def switch_interface(interface): for reader in readers(): cardConnection = reader.createConnection() cardConnection.connect(mode=SCARD_SHARE_DIRECT) switch_interface = [ 0x52, 0xF8, 0x04, 0x01, 0x00, interface ] IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE = SCARD_CTL_CODE(1) print "Reader:", reader, try: res = cardConnection.control(IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE, switch_interface) except: print "FAILED" else: print res
def switch_interface(interface): for reader in readers(): cardConnection = reader.createConnection() cardConnection.connect(mode=SCARD_SHARE_DIRECT) switch_interface = [0x52, 0xF8, 0x04, 0x01, 0x00, interface] IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE = SCARD_CTL_CODE(1) print "Reader:", reader, try: res = cardConnection.control(IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE, switch_interface) except: print "FAILED" else: print res
data = data[1] * 256 + data[0] elif 4 == len: # 32 bits value data = ((data[3] * 256 + data[2]) * 256 + data[1]) * 256 + data[0] # store the value in the dictionnary d[Properties[tag]] = data del tmp[0:2 + len] return d if __name__ == '__main__': """Small sample illustrating the use of PCSCPart10.""" from smartcard.pcsc.PCSCReader import readers cc = readers()[0].createConnection() cc.connect(mode=SCARD_SHARE_DIRECT) #print cc.control( CM_IOCTL_GET_FEATURE_REQUEST ) features = getFeatureRequest(cc) print features print hasFeature(features, FEATURE_VERIFY_PIN_START) print hasFeature(features, FEATURE_VERIFY_PIN_DIRECT) properties = getPinProperties(cc) print "\nPinProperties:" for k in properties.keys(): print " %s: %s" % (k, properties[k]) print "\nTlvProperties:"
# Copyright (C) 2009 Ludovic Rousseau # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. from smartcard.pcsc.PCSCReader import readers from smartcard.pcsc.PCSCPart10 import * from smartcard.util import toHexString for reader in readers(): cardConnection = reader.createConnection() cardConnection.connect(mode=SCARD_SHARE_DIRECT) get_firmware = [0x02] IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE = SCARD_CTL_CODE(1) res = cardConnection.control(IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE, get_firmware) print "Reader:", reader print "Firmware:", "".join(map(chr, res))
print "SW:", toHexString(sw) def parse_select(bytes): """ parse the SECODER SELECT APPLICATION answer """ print "parse the SECODER SELECT APPLICATION answer:", toHexString(bytes) print "Activation ID:", toHexString(bytes[0:4]) print "Interface Version: '%s'" % ''.join(map(chr, bytes[5:11])) print "Language Code:", toHexString(bytes[11:15]) print "CSI:", toHexString(bytes[15:18]) print "Application Identifier:", toHexString(bytes[18:23]) print "SW:", toHexString(bytes[23:25]) cardConnection = readers()[0].createConnection() cardConnection.connect(mode=SCARD_SHARE_DIRECT) featureList = getFeatureRequest(cardConnection) #print getPinProperties(cardConnection) mct_readerDirect = hasFeature(featureList, FEATURE_MCT_READERDIRECT) if mct_readerDirect is None: raise Exception("The reader does not support MCT_READERDIRECT") secoder_info = [ 0x20, 0x70, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 ] res = cardConnection.control(mct_readerDirect, secoder_info) parse_info(res) secoder_select = [ 0x20, 0x71, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x80, 0x05, 0x31, 0x2E, 0x31, 0x2E, 0x30, 0x84, 0x02, 0x64, 0x65,
# control_get_firmware.py: get firmware version of Gemalto readers # Copyright (C) 2009 Ludovic Rousseau # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. from smartcard.pcsc.PCSCReader import readers from smartcard.pcsc.PCSCPart10 import * from smartcard.util import toHexString for reader in readers(): cardConnection = reader.createConnection() cardConnection.connect(mode=SCARD_SHARE_DIRECT) get_firmware = [0x02] IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE = SCARD_CTL_CODE(1) res = cardConnection.control(IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE, get_firmware) print "Reader:", reader print "Firmware:", "".join(map(chr, res))