verify pin command

git-svn-id: svn+ssh://localhost/home/henryk/svn/cyberflex-shell/trunk@21 f711b948-2313-0410-aaa9-d29f33439f0b
This commit is contained in:
henryk 2005-09-29 21:37:28 +00:00
parent 9fb1f2863b
commit bd6140e6ff
2 changed files with 27 additions and 2 deletions

View File

@ -5,10 +5,10 @@ DEBUG = True
class Card:
APDU_GET_RESPONSE = "\x00\xC0\x00\x00"
APDU_VERIFY_PIN = "\x00\x20\x00\x00"
SW_OK = '\x90\x00'
ATRS = []
DRIVER_NAME = "Generic"
COMMANDS = {}
STATUS_WORDS = {
SW_OK: "Normal execution"
}
@ -24,6 +24,24 @@ class Card:
self.last_sw = None
self.sw_changed = False
def verify_pin(self, pin_number, pin_value):
apdu = self.APDU_VERIFY_PIN[:3] + chr(pin_number) + \
chr(len(pin_value)) + pin_value
result = self.send_apdu(apdu)
return result == self.SW_OK
def cmd_verify(self, *args):
if len(args) != 2:
raise TypeError, "Must give exactly two arguments: pin number and pin"
pin_number = int(args[0], 0)
pin_value = binascii.a2b_hex("".join(args[1].split()))
self.verify_pin(pin_number, pin_value)
COMMANDS = {
"verify": (cmd_verify, "verify pin_number pin_value",
"""Verify a PIN.""")
}
def _check_apdu(apdu):
if len(apdu) < 4 or ((len(apdu) > 5) and len(apdu) != (ord(apdu[4])+5)):
print "Cowardly refusing to send invalid APDU:\n ", utils.hexdump(apdu, indent=2)

View File

@ -1,7 +1,8 @@
#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
import pycsc, utils, cards, os, re, binascii, sys, exceptions
import pycsc, utils, cards, os, re, binascii, sys, exceptions, traceback
print_backtrace = False
try:
import readline
@ -130,6 +131,8 @@ if __name__ == "__main__":
if exctype == exceptions.SystemExit:
raise exctype, value
print "%s: %s" % (exctype, value)
if print_backtrace:
traceback.print_tb(sys.exc_info()[2])
elif COMMANDS.has_key(cmd.lower()):
cmdspec = COMMANDS[cmd.lower()]
@ -140,6 +143,8 @@ if __name__ == "__main__":
if exctype == exceptions.SystemExit:
raise exctype, value
print "%s: %s" % (exctype, value)
if print_backtrace:
traceback.print_tb(sys.exc_info()[2])
elif apduregex.match(line):
## Might be an APDU
@ -150,6 +155,8 @@ if __name__ == "__main__":
except Exception:
exctype, value = sys.exc_info()[:2]
print "%s: %s" % (exctype, value)
if print_backtrace:
traceback.print_tb(sys.exc_info()[2])
else:
print "Unknown command"