def checkAndVerifyCHV1(self, checktype=CHV_UPDATE, data=None):
if not self.chv1_enabled:
# No PIN set on this card
return 1
if self.chv1:
# Must have verified successfully already
return 1
# Issue the status command if we don't already have the data
if not data:
data, sw = self.sendAPDUmatchSW("A0C000000F", SW_OK)
# Check if CHV1 is needed for this function (read / write)
# 000007DF3F000100 00 444401071302
if checktype == CHV_ALWAYS:
val = 1
elif checktype & CHV_UPDATE:
val = int(data[17], 16)
else: # Must be checking for read access
val = int(data[16], 16)
if val == 0: # means we don't need chv1, always access is set
return 1
elif val == 1: # means chv1 is needed, try and verify it
# Have not verified yet, try now, ask for the PIN number
dlg = wxskinTextEntryDialog(self, 'Enter your PIN (4 to 8 digits) :', 'PIN verification', '', style=wx.TE_PASSWORD|wx.OK|wx.CANCEL)
ret = dlg.ShowModal()
self.chv1 = dlg.GetValue()
dlg.Destroy()
if ret == wx.ID_OK:
ok = True
for i in self.chv1:
if i not in "0123456789":
ok = False
if len(self.chv1) < 4 or len(self.chv1) > 8:
ok = False
if not ok:
pySIMmessage(self, "Invalid PIN! Must be 4 to 8 digits long\n\nDigits are these characters: 0123456789", "SIM card error")
return 0
try:
self.sendAPDUmatchSW("A020000108%s" % ASCIIToPIN(self.chv1), SW_OK)
return 1
except:
self.chv1 = ''
pySIMmessage(self, "Incorrect PIN!", "SIM card error")
print_exc()
# Must need CHV2 or ADM access, foo-ey!
return 0
评论列表
文章目录