def main(): """ main """ card_connection = readers()[0].createConnection() card_connection.connect(mode=SCARD_SHARE_DIRECT, disposition=SCARD_LEAVE_CARD) feature_list = getFeatureRequest(card_connection) get_tlv_properties = hasFeature(feature_list, FEATURE_GET_TLV_PROPERTIES) if get_tlv_properties: tlv = getTlvProperties(card_connection) print "Reader: ", readers()[0] print "IdVendor: 0x%04X" % tlv['PCSCv2_PART10_PROPERTY_wIdVendor'] print "IdProduct: 0x%04X" % tlv['PCSCv2_PART10_PROPERTY_wIdProduct'] ccid_esc_command = hasFeature(feature_list, FEATURE_CCID_ESC_COMMAND) if ccid_esc_command is None: raise Exception("FEATURE_CCID_ESC_COMMAND is not supported or allowed") # Proprietary command for Gemalto readers # This is implemented by the Gemalto Pinpad v2 and C200 readers firmware_features = [0x6A] try: res = card_connection.control(ccid_esc_command, firmware_features) except SmartcardException, ex: print "Failed:", ex return
def main(): """ main """ card_connection = readers()[0].createConnection() card_connection.connect(mode=SCARD_SHARE_DIRECT, disposition=SCARD_LEAVE_CARD) feature_list = getFeatureRequest(card_connection) get_tlv_properties = hasFeature(feature_list, FEATURE_GET_TLV_PROPERTIES) if get_tlv_properties: tlv = getTlvProperties(card_connection) print "Reader: ", readers()[0] print "IdVendor: 0x%04X" % tlv['PCSCv2_PART10_PROPERTY_wIdVendor'] print "IdProduct: 0x%04X" % tlv['PCSCv2_PART10_PROPERTY_wIdProduct'] ccid_esc_command = hasFeature(feature_list, FEATURE_CCID_ESC_COMMAND) if ccid_esc_command is None: raise Exception("FEATURE_CCID_ESC_COMMAND is not supported or allowed") # Proprietary command for Gemalto readers # This is implemented by the Gemalto Pinpad v2 and C200 readers firmware_features = [0x6A] try: res = card_connection.control(ccid_esc_command, firmware_features) except SmartcardException, ex: print "Failed:", ex return
from smartcard.pcsc.PCSCPart10 import (getFeatureRequest, hasFeature, getTlvProperties, FEATURE_CCID_ESC_COMMAND, SCARD_SHARE_DIRECT) # use the first reader card_connection = readers()[0].createConnection() card_connection.connect(mode=SCARD_SHARE_DIRECT) # get CCID Escape control code feature_list = getFeatureRequest(card_connection) ccid_esc_command = hasFeature(feature_list, FEATURE_CCID_ESC_COMMAND) if ccid_esc_command is None: raise Exception("The reader does not support FEATURE_CCID_ESC_COMMAND") # get the TLV PROPERTIES tlv = getTlvProperties(card_connection) # check we are using a Xiring Leo v1 or v2 reader if tlv['PCSCv2_PART10_PROPERTY_wIdVendor'] == 0x0F14 \ and (tlv['PCSCv2_PART10_PROPERTY_wIdProduct'] in [0x0037, 0x0038]): # proprietary escape command for Xiring Leo readers version = [ord(c) for c in "VERSION"] res = card_connection.control(ccid_esc_command, version) print(res) print("VERSION:", ''.join([chr(x) for x in res])) serial = [ord(c) for c in "GET_SN"] res = card_connection.control(ccid_esc_command, serial) print(res) print("GET_SN:", ''.join([chr(x) for x in res]))
# You should have received a copy of the GNU General Public License along # with this program; if not, see <http://www.gnu.org/licenses/>. from smartcard.System import readers from smartcard.pcsc.PCSCPart10 import (SCARD_SHARE_DIRECT, SCARD_LEAVE_CARD, SCARD_CTL_CODE, getTlvProperties) for reader in readers(): cardConnection = reader.createConnection() cardConnection.connect(mode=SCARD_SHARE_DIRECT, disposition=SCARD_LEAVE_CARD) print "Reader:", reader # properties returned by IOCTL_FEATURE_GET_TLV_PROPERTIES properties = getTlvProperties(cardConnection) # Gemalto devices supports a control code to get firmware key = 'PCSCv2_PART10_PROPERTY_wIdVendor' if key in properties: if properties[key] == 0x08E6: get_firmware = [0x02] IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE = SCARD_CTL_CODE(1) res = cardConnection.control(IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE, get_firmware) print " Firmware:", "".join([chr(x) for x in res]) else: print " Not a Gemalto reader" key = 'PCSCv2_PART10_PROPERTY_sFirmwareID' if key in properties: firmware = properties[key]
# # 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, see <http://www.gnu.org/licenses/>. # You have to enable the use of Escape commands with the # DRIVER_OPTION_CCID_EXCHANGE_AUTHORIZED bit in the ifdDriverOptions # option of the CCID driver Info.plist file from smartcard.System import readers from smartcard.pcsc.PCSCPart10 import (getFeatureRequest, hasFeature, getTlvProperties, FEATURE_CCID_ESC_COMMAND, SCARD_SHARE_DIRECT) # use the first reader card_connection = readers()[0].createConnection() card_connection.connect(mode=SCARD_SHARE_DIRECT) # get the TLV PROPERTIES tlv = getTlvProperties(card_connection) for key in sorted(tlv): if key in ["PCSCv2_PART10_PROPERTY_wIdProduct", "PCSCv2_PART10_PROPERTY_wIdVendor"]: print "%s: 0x%04X" % (key, tlv[key]) else: print "%s: %s" % (key, tlv[key])
# You should have received a copy of the GNU General Public License along # with this program; if not, see <http://www.gnu.org/licenses/>. from smartcard.System import readers from smartcard.pcsc.PCSCPart10 import (SCARD_SHARE_DIRECT, SCARD_LEAVE_CARD, SCARD_CTL_CODE, getTlvProperties) for reader in readers(): cardConnection = reader.createConnection() cardConnection.connect(mode=SCARD_SHARE_DIRECT, disposition=SCARD_LEAVE_CARD) print("Reader:", reader) # properties returned by IOCTL_FEATURE_GET_TLV_PROPERTIES properties = getTlvProperties(cardConnection) # Gemalto devices supports a control code to get firmware key = 'PCSCv2_PART10_PROPERTY_wIdVendor' if key in properties: if properties[key] == 0x08E6: get_firmware = [0x02] IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE = SCARD_CTL_CODE(1) res = cardConnection.control(IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE, get_firmware) print(" Firmware:", "".join([chr(x) for x in res])) else: print(" Not a Gemalto reader") key = 'PCSCv2_PART10_PROPERTY_sFirmwareID' if key in properties: firmware = properties[key]
def main(): """ main """ card_connection = readers()[0].createConnection() card_connection.connect(mode=SCARD_SHARE_DIRECT, disposition=SCARD_LEAVE_CARD) feature_list = getFeatureRequest(card_connection) get_tlv_properties = hasFeature(feature_list, FEATURE_GET_TLV_PROPERTIES) if get_tlv_properties: tlv = getTlvProperties(card_connection) print("Reader: ", readers()[0]) print("IdVendor: 0x%04X" % tlv['PCSCv2_PART10_PROPERTY_wIdVendor']) print("IdProduct: 0x%04X" % tlv['PCSCv2_PART10_PROPERTY_wIdProduct']) ccid_esc_command = hasFeature(feature_list, FEATURE_CCID_ESC_COMMAND) if ccid_esc_command is None: raise Exception("FEATURE_CCID_ESC_COMMAND is not supported or allowed") # Proprietary command for Gemalto readers # This is implemented by the Gemalto Pinpad v2 and C200 readers firmware_features = [0x6A] try: res = card_connection.control(ccid_esc_command, firmware_features) except SmartcardException as ex: print("Failed:", ex) return print(res) print("LogicalLCDLineNumber (Logical number of LCD lines):", res[0]) print("LogicalLCDRowNumber (Logical number of characters per LCD line):", res[1]) print("LcdInfo:", res[2]) print(" b0 indicates if scrolling available:", test_bit(res[2], 0)) print("EntryValidationCondition:", res[3]) print("PC/SCv2 features:") print(" VerifyPinStart:", test_bit(res[4], 0)) print(" VerifyPinFinish:", test_bit(res[4], 1)) print(" ModifyPinStart:", test_bit(res[4], 2)) print(" ModifyPinFinish:", test_bit(res[4], 3)) print(" GetKeyPressed:", test_bit(res[4], 4)) print(" VerifyPinDirect:", test_bit(res[4], 5)) print(" ModifyPinDirect:", test_bit(res[4], 6)) print(" Abort:", test_bit(res[4], 7)) print(" GetKey:", test_bit(res[5], 0)) print(" WriteDisplay:", test_bit(res[5], 1)) print(" SetSpeMessage:", test_bit(res[5], 2)) # bits 3-7 are RFU # bytes 6 and 7 are RFU print(" bTimeOut2:", test_bit(res[8], 0)) bListSupportedLanguages = test_bit(res[8], 1) print(" bListSupportedLanguages:", bListSupportedLanguages) if bListSupportedLanguages: try: # Reader is able to indicate the list of supported languages # through CCID-ESC 0x6B languages = card_connection.control(ccid_esc_command, [0x6B]) except SmartcardException as ex: print("Failed:", ex) print(" ", languages) languages = iter(languages) for low, high in izip(languages, languages): lang_x = high * 256 + low try: lang_t = USBLangID[lang_x] except KeyError: lang_t = "unkonwn" print(" 0x%04X: %s" % (lang_x, lang_t)) print(" bNumberMessageFix:", test_bit(res[8], 2)) print(" bPPDUSupportOverXferBlock:", test_bit(res[8], 3)) print(" bPPDUSupportOverEscape:", test_bit(res[8], 4)) # bits 5-7 are RFU # bytes 9, 10 and 11 and RFU print("VersionNumber:", res[12]) print("MinimumPINSize:", res[13]) print("MaximumPINSize:", res[14]) Firewall = test_bit(res[15], 0) print("Firewall:", Firewall) # bits 1-7 are RFU if Firewall: print("FirewalledCommand_SW1: 0x%02X" % res[16]) print("FirewalledCommand_SW2: 0x%02X" % res[17])