本文整理汇总了Python中smartcard.System.readers函数的典型用法代码示例。如果您正苦于以下问题:Python readers函数的具体用法?Python readers怎么用?Python readers使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了readers函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: checklocalconfig
def checklocalconfig():
try:
f = open('local_config.py', 'r')
except IOError:
print 'local_config.py not found; generating local_config.py...'
# generate local configuration
f = open('local_config.py', 'w+')
f.write('from smartcard.util import toHexString\n')
f.write('expectedReaders = ')
f.write(str(readers()) + '\n')
expectedATRs = []
for reader in readers():
try:
expectedATRs.append(getATR(reader))
except NoCardException:
expectedATRs.append([])
f.write('expectedATRs = ')
#for atr in expectedATRs: print `toHexString(atr)`
f.write(`expectedATRs` + '\n')
f.write('expectedATRinReader = {}\n')
f.write('for i in xrange(len(expectedReaders)):\n')
f.write(' expectedATRinReader[expectedReaders[i]] = expectedATRs[i]\n')
f.write('expectedReaderForATR = {}\n')
f.write('for i in xrange(len(expectedReaders)):\n')
f.write(' expectedReaderForATR[toHexString(expectedATRs[i])] = expectedReaders[i]\n')
f.write('expectedReaderGroups = [\'SCard$DefaultReaders\']\n')
f.close()
示例2: main
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
示例3: testcase_CardRequestNewCardInReaderNotPresentInfiniteTimeOut
def testcase_CardRequestNewCardInReaderNotPresentInfiniteTimeOut(self):
"""Test smartcard.CardRequest for any new card in a specific
reader not present without time-out."""
print 'please remove a smart card reader'
_readerz = readers()
while True:
readerz = readers()
if len(_readerz) > len(readerz):
break
time.sleep(.1)
for reader in readerz:
_readerz.remove(reader)
cardtype = AnyCardType()
cardrequest = CardRequest(
timeout=None,
readers=[_readerz[0]],
cardType=cardtype,
newcardonly=True)
print 'Re-insert reader ', _readerz[0], 'with a card inside'
cardservice = cardrequest.waitforcard()
cardservice.connection.connect()
print toHexString(
cardservice.connection.getATR()), \
'in', cardservice.connection.getReader()
cardservice.connection.disconnect()
示例4: __init__
def __init__(self, readerName=None, cardServiceClass=None):
"""Session constructor. Initializes a smart card session and
connect to the card.
@param readerName: reader to connect to; default is first PCSC reader
@param cardServiceClass: card service to bind the session to; default
is None
"""
# if reader name not given, select first reader
if readerName is None:
if len(readers()) > 0:
self.reader = readers()[0]
self.readerName = repr(self.reader)
else:
raise NoReadersException()
# otherwise select reader from name
else:
self.readerName = readerName
for reader in readers():
if readerName == str(reader):
self.reader = reader
self.readerName = repr(self.reader)
try:
self.reader
except AttributeError:
raise InvalidReaderException(self.readerName)
# open card connection and bind PassThruCardService
cc = self.reader.createConnection()
self.cs = PassThruCardService(cc)
self.cs.connection.connect()
示例5: testcase_Card_Eq_NotEq
def testcase_Card_Eq_NotEq(self):
"""Test == and != for Cards."""
for reader in readers():
card = Card(str(reader), expectedATRinReader[str(reader)])
cardcopy = Card(str(reader), expectedATRinReader[str(reader)])
self.assertEqual(True, card == cardcopy)
self.assertEqual(True, not card != cardcopy)
for reader in readers():
card = Card(str(reader), expectedATRinReader[str(reader)])
cardcopy = Card(str(reader), [0, 0])
self.assertEqual(True, card != cardcopy)
self.assertEqual(True, not card == cardcopy)
示例6: testcase_readers_in_readergroup_nonexistent
def testcase_readers_in_readergroup_nonexistent(self):
foundreaders = {}
for reader in readers(['dummy$group']):
foundreaders[reader] = 1
for reader in expectedReaders:
self.assert_(not reader in foundreaders)
self.assertEquals(0, len(foundreaders))
示例7: main
def main():
""" Ask the first reader/driver to return its Vendor Name if any """
card_connection = readers()[0].createConnection()
card_connection.connect(mode=SCARD_SHARE_DIRECT,
disposition=SCARD_LEAVE_CARD)
try:
# Vendor name
name = card_connection.getAttrib(SCARD_ATTR_VENDOR_NAME)
print(''.join([chr(char) for char in name]))
# Vendor-supplied interface device version (DWORD in the form
# 0xMMmmbbbb where MM = major version, mm = minor version, and
# bbbb = build number).
version = card_connection.getAttrib(SCARD_ATTR_VENDOR_IFD_VERSION)
print("Version: %d.%d.%d" % (version[3], version[2],
version[0]))
# Vendor-supplied interface device serial number.
# only for readers with a USB serial number
serial = card_connection.getAttrib(SCARD_ATTR_VENDOR_IFD_SERIAL_NO)
print(serial)
# Reader's display name
# only with pcsc-lite version >= 1.6.0
name = card_connection.getAttrib(SCARD_ATTR_DEVICE_FRIENDLY_NAME)
print(''.join([chr(char) for char in name]))
except smartcard.Exceptions.SmartcardException, message:
print("Exception:", message)
示例8: setUp
def setUp(self):
r = readers()
self.max = maxim.MaximAPI(r[0])
self.max.Connect()
self.CardInterfaces = [1,2]
self.UnknownInterfaces = [3, 7]
self.timeout = 0b10000111
示例9: open_key_multiple_readers
def open_key_multiple_readers(name=None):
"""
Opens a smartcard reader matching the given name and connects to the
ykneo-oath applet through it.
Returns a reference to the YkneoYubiOath object.
"""
for reader in readers():
print "list of readers"
print readers
try:
conn = reader.createConnection()
conn.connect()
data, status = _cmd2(conn, 0, 0xa4, 0x04, 0x00, 'a0000005272101'.decode('hex'))
if (status) != 0x9000:
print "unable to select the applet on reader %s" % reader
else:
print "using reader"
print reader
return YkneoYubiOath(conn)
except Exception, e:
print "WARNING: %s" % e
print "i am in the except of multiple readers"
示例10: switch_interface
def switch_interface(interface):
"""
switch from contact to contactless (or reverse) on a GemProx DU reader
"""
for reader in readers():
cardConnection = reader.createConnection()
cardConnection.connect(mode=SCARD_SHARE_DIRECT, disposition=SCARD_LEAVE_CARD)
switch_interface_cmd = [0x52, 0xF8, 0x04, 0x01, 0x00, interface]
print("Reader:", reader, "=>", end=' ')
try:
res = cardConnection.control(IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE,
switch_interface_cmd)
except:
print("FAILED")
else:
if res != [0, 0, 0, 0]:
print("Failed: ", end='')
err = res[0] * 256 + res[1]
if err == 0xFF83:
print("Wrong data parameters")
elif err == 0xFF84:
print("Wrong command bytes")
else:
print("Unknown error:", [hex(x) for x in res])
else:
print("Success")
示例11: setup
def setup(readernumber):
"""Open up a connection to the specified reader via PCSC
"""
r = readers()
connection = r[readernumber].createConnection()
connection.connect()
return connection
示例12: print_welcome
def print_welcome():
print "Welcome to sandwich-manager beta release."
r = readers()
if len(r) < 1:
print "Warning: no reader available"
else:
print "Reader: " + str(r[0])
print "Type 'help' or 'h' for help."
示例13: __init__
def __init__(self, dbus_server):
self.dbus_server = dbus_server
r = readers()
self.ttag = r[r.index('ACS ACR 38U-CCID 00 00')].createConnection()
self.ttag.connect()
#set retry time to 1
RTO = get_set_retry_time_to_one()
data, sw1, sw2 = self.ttag.transmit( RTO )
示例14: testcase_CardDictionary
def testcase_CardDictionary(self):
"""Create a dictionnary with Card keys"""
mydict = {}
for reader in readers():
card = Card(reader, expectedATRinReader[str(reader)])
mydict[card] = reader
for card in list(mydict.keys()):
self.assertTrue(str(card.reader) in expectedReaders)
示例15: getAttribute
def getAttribute():
r=readers()
connection = r[0].createConnection()
connection.connect()
GETATTR = [0x80, 0x2B, 0x00, 0x00]
data, sw1, sw2 = connection.transmit( GETATTR )
return (data, sw1, sw2)