[vpicc] Python 3 linting
Some additional code linting - remove unused imports - remove unecessary parenthesis from if statements - created TLVutils TAG dictionary in creation time
This commit is contained in:
@@ -239,11 +239,11 @@ class Security_Environment(object):
|
||||
if se & 0x08:
|
||||
self.external_auth = True
|
||||
return self._set_SE(p2, data)
|
||||
elif(cmd == 0x02):
|
||||
elif cmd == 0x02:
|
||||
return self.sam.store_SE(p2)
|
||||
elif(cmd == 0x03):
|
||||
elif cmd == 0x03:
|
||||
return self.sam.restore_SE(p2)
|
||||
elif(cmd == 0x04):
|
||||
elif cmd == 0x04:
|
||||
return self.sam.erase_SE(p2)
|
||||
else:
|
||||
raise SwError(SW["ERR_INCORRECTP1P2"])
|
||||
@@ -684,7 +684,6 @@ class Security_Environment(object):
|
||||
"""
|
||||
|
||||
from Crypto.PublicKey import RSA, DSA
|
||||
from Crypto.Random import get_random_bytes
|
||||
|
||||
cipher = self.ct.algorithm
|
||||
|
||||
|
||||
@@ -229,7 +229,7 @@ class SAM(object):
|
||||
blocklen = vsCrypto.get_cipher_blocklen(cipher)
|
||||
reference = vsCrypto.append_padding(blocklen, self.last_challenge)
|
||||
reference = vsCrypto.encrypt(cipher, key, reference)
|
||||
if(reference == data):
|
||||
if reference == data:
|
||||
# Invalidate last challenge
|
||||
self.last_challenge is None
|
||||
return SW["NORMAL"], ""
|
||||
@@ -249,14 +249,14 @@ class SAM(object):
|
||||
key = self._get_referenced_key(p1, p2)
|
||||
card_number = self.get_card_number()
|
||||
|
||||
if (key is None):
|
||||
if key is None:
|
||||
raise SwError(SW["ERR_INCORRECTP1P2"])
|
||||
if p1 == 0x00: # No information given
|
||||
cipher = get_referenced_cipher(self.cipher)
|
||||
else:
|
||||
cipher = get_referenced_cipher(p1)
|
||||
|
||||
if (cipher is None):
|
||||
if cipher is None:
|
||||
raise SwError(SW["ERR_INCORRECTP1P2"])
|
||||
|
||||
plain = vsCrypto.decrypt(cipher, key, mutual_challenge)
|
||||
@@ -277,7 +277,7 @@ class SAM(object):
|
||||
"""
|
||||
Generate a random number of maximum 8 Byte and return it.
|
||||
"""
|
||||
if (p1 != 0x00 or p2 != 0x00): # RFU
|
||||
if p1 != 0x00 or p2 != 0x00: # RFU
|
||||
raise SwError(SW["ERR_INCORRECTP1P2"])
|
||||
|
||||
length = 8 # Length of the challenge in Byte
|
||||
@@ -315,7 +315,7 @@ class SAM(object):
|
||||
algo = get_referenced_cipher(p1)
|
||||
keylength = vsCrypto.get_cipher_keylen(algo)
|
||||
|
||||
if (p2 == 0x00): # No information given, use the global card key
|
||||
if p2 == 0x00: # No information given, use the global card key
|
||||
key = self.cardSecret
|
||||
# We treat global and specific reference data alike
|
||||
else:
|
||||
|
||||
@@ -19,35 +19,36 @@
|
||||
|
||||
from virtualsmartcard.utils import stringtoint, inttostring
|
||||
|
||||
TAG = {}
|
||||
TAG["FILECONTROLPARAMETERS"] = 0x62
|
||||
TAG["FILEMANAGEMENTDATA"] = 0x64
|
||||
TAG["FILECONTROLINFORMATION"] = 0x6F
|
||||
TAG["BYTES_EXCLUDINGSTRUCTURE"] = 0x80
|
||||
TAG["BYTES_INCLUDINGSTRUCTURE"] = 0x81
|
||||
TAG["FILEDISCRIPTORBYTE"] = 0x82
|
||||
TAG["FILEIDENTIFIER"] = 0x83
|
||||
TAG["DFNAME"] = 0x84
|
||||
TAG["PROPRIETARY_NOTBERTLV"] = 0x85
|
||||
TAG["PROPRIETARY_SECURITY"] = 0x86
|
||||
TAG["FIDEF_CONTAININGFCI"] = 0x87
|
||||
TAG["SHORTFID"] = 0x88
|
||||
TAG["LIFECYCLESTATUS"] = 0x8A
|
||||
TAG["SA_EXPANDEDFORMAT"] = 0x8B
|
||||
TAG["SA_COMPACTFORMAT"] = 0x8C
|
||||
TAG["FIDEF_CONTAININGSET"] = 0x8D
|
||||
TAG["CHANNELSECURITY"] = 0x8E
|
||||
TAG["SA_DATAOBJECTS"] = 0xA0
|
||||
TAG["PROPRIETARY_SECURITYTEMP"] = 0xA1
|
||||
TAG["PROPRIETARY_BERTLV"] = 0xA5
|
||||
TAG["SA_EXPANDEDFORMAT_TEMP"] = 0xAB
|
||||
TAG["CRYPTIDENTIFIER_TEMP"] = 0xAC
|
||||
TAG["DISCRETIONARY_DATA"] = 0x53
|
||||
TAG["DISCRETIONARY_TEMPLATE"] = 0x73
|
||||
TAG["OFFSET_DATA"] = 0x54
|
||||
TAG["TAG_LIST"] = 0x5C
|
||||
TAG["HEADER_LIST"] = 0x5D
|
||||
TAG["EXTENDED_HEADER_LIST"] = 0x4D
|
||||
TAG = {
|
||||
"FILECONTROLPARAMETERS": 0x62,
|
||||
"FILEMANAGEMENTDATA": 0x64,
|
||||
"FILECONTROLINFORMATION": 0x6F,
|
||||
"BYTES_EXCLUDINGSTRUCTURE": 0x80,
|
||||
"BYTES_INCLUDINGSTRUCTURE": 0x81,
|
||||
"FILEDISCRIPTORBYTE": 0x82,
|
||||
"FILEIDENTIFIER": 0x83,
|
||||
"DFNAME": 0x84,
|
||||
"PROPRIETARY_NOTBERTLV": 0x85,
|
||||
"PROPRIETARY_SECURITY": 0x86,
|
||||
"FIDEF_CONTAININGFCI": 0x87,
|
||||
"SHORTFID": 0x88,
|
||||
"LIFECYCLESTATUS": 0x8A,
|
||||
"SA_EXPANDEDFORMAT": 0x8B,
|
||||
"SA_COMPACTFORMAT": 0x8C,
|
||||
"FIDEF_CONTAININGSET": 0x8D,
|
||||
"CHANNELSECURITY": 0x8E,
|
||||
"SA_DATAOBJECTS": 0xA0,
|
||||
"PROPRIETARY_SECURITYTEMP": 0xA1,
|
||||
"PROPRIETARY_BERTLV": 0xA5,
|
||||
"SA_EXPANDEDFORMAT_TEMP": 0xAB,
|
||||
"CRYPTIDENTIFIER_TEMP": 0xAC,
|
||||
"DISCRETIONARY_DATA": 0x53,
|
||||
"DISCRETIONARY_TEMPLATE": 0x73,
|
||||
"OFFSET_DATA": 0x54,
|
||||
"TAG_LIST": 0x5C,
|
||||
"HEADER_LIST": 0x5D,
|
||||
"EXTENDED_HEADER_LIST": 0x4D
|
||||
}
|
||||
|
||||
|
||||
def tlv_unpack(data):
|
||||
|
||||
Reference in New Issue
Block a user