Converting docstrings to sphinx syntax
git-svn-id: https://vsmartcard.svn.sourceforge.net/svnroot/vsmartcard@607 96b47cad-a561-4643-ad3b-153ac7d7599c
This commit is contained in:
@@ -121,15 +121,19 @@ def strip_padding(cipherspec, data, padding_class=0x01):
|
|||||||
def crypto_checksum(algo, key, data, iv=None, ssc=None):
|
def crypto_checksum(algo, key, data, iv=None, ssc=None):
|
||||||
"""
|
"""
|
||||||
Compute various types of cryptographic checksums.
|
Compute various types of cryptographic checksums.
|
||||||
@param algo: A string specifying the algorithm to use. Currently supported
|
|
||||||
algorithms are \"MAX\" \"HMAC\" and \"CC\" (Meaning a
|
:param algo: A string specifying the algorithm to use. Currently supported \
|
||||||
cryptographic checksum as used by the ICAO passports)
|
algorithms are \"MAX\" \"HMAC\" and \"CC\" (Meaning a cryptographic checksum \
|
||||||
@param key: They key used to computed the cryptographic checksum
|
as used by the ICAO passports)
|
||||||
@param data: The data for which to calculate the checksum
|
:param key: They key used to computed the cryptographic checksum
|
||||||
@param iv: Optional. An initialization vector. Only used by the \"MAC\" algorithm
|
:param data: The data for which to calculate the checksum
|
||||||
@param ssc: Optional. A send sequence counter to be prepended to the data. Only
|
:param iv: Optional. An initialization vector. Only used by the \"MAC\" \
|
||||||
used by the \"CC\" algorithm
|
algorithm
|
||||||
|
:param ssc: Optional. A send sequence counter to be prepended to the data. \
|
||||||
|
Only used by the \"CC\" algorithm
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if algo not in ("HMAC", "MAC", "CC"):
|
if algo not in ("HMAC", "MAC", "CC"):
|
||||||
raise ValueError, "Unknown Algorithm %s" % algo
|
raise ValueError, "Unknown Algorithm %s" % algo
|
||||||
|
|
||||||
@@ -254,7 +258,7 @@ def read_protected_string(string, password, cipherspec=None):
|
|||||||
## * Cyberflex specific methods *
|
## * Cyberflex specific methods *
|
||||||
## *******************************************************************
|
## *******************************************************************
|
||||||
def calculate_MAC(session_key, message, iv=CYBERFLEX_IV):
|
def calculate_MAC(session_key, message, iv=CYBERFLEX_IV):
|
||||||
""""
|
"""
|
||||||
Cyberflex MAC is the last Block of the input encrypted with DES3-CBC
|
Cyberflex MAC is the last Block of the input encrypted with DES3-CBC
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
@@ -36,10 +36,11 @@ class ControlReferenceTemplate:
|
|||||||
def __init__(self, tag, config=""):
|
def __init__(self, tag, config=""):
|
||||||
"""
|
"""
|
||||||
Generates a new CRT
|
Generates a new CRT
|
||||||
@param tag: Indicates the type of the CRT (HT, AT, KT, CCT, DST, CT-sym,
|
|
||||||
CT-asym)
|
:param tag: Indicates the type of the CRT (HT, AT, KT, CCT, DST, CT-sym, \
|
||||||
@param config: A string containing TLV encoded Security Environment
|
CT-asym)
|
||||||
parameters
|
:param config: A string containing TLV encoded Security Environment \
|
||||||
|
parameters
|
||||||
"""
|
"""
|
||||||
if tag not in (CRT_TEMPLATE["AT"], CRT_TEMPLATE["HT"],
|
if tag not in (CRT_TEMPLATE["AT"], CRT_TEMPLATE["HT"],
|
||||||
CRT_TEMPLATE["KAT"], CRT_TEMPLATE["CCT"],
|
CRT_TEMPLATE["KAT"], CRT_TEMPLATE["CCT"],
|
||||||
@@ -63,7 +64,8 @@ class ControlReferenceTemplate:
|
|||||||
def parse_SE_config(self, config):
|
def parse_SE_config(self, config):
|
||||||
"""
|
"""
|
||||||
Parse a control reference template as given e.g. in an MSE APDU.
|
Parse a control reference template as given e.g. in an MSE APDU.
|
||||||
@param config : a TLV string containing the configuration for the CRT.
|
|
||||||
|
:param config : a TLV string containing the configuration for the CRT.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
structure = unpack(config)
|
structure = unpack(config)
|
||||||
@@ -87,7 +89,8 @@ class ControlReferenceTemplate:
|
|||||||
Set the algorithm to be used by this CRT. The algorithms are specified
|
Set the algorithm to be used by this CRT. The algorithms are specified
|
||||||
in a global dictionary. New cards may add or modify this table in order
|
in a global dictionary. New cards may add or modify this table in order
|
||||||
to support new or different algorithms.
|
to support new or different algorithms.
|
||||||
@param data: reference to an algorithm
|
|
||||||
|
:param data: reference to an algorithm
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not ALGO_MAPPING.has_key(data):
|
if not ALGO_MAPPING.has_key(data):
|
||||||
@@ -254,11 +257,13 @@ class Security_Environment(object):
|
|||||||
This methods parses a data field including Secure Messaging objects.
|
This methods parses a data field including Secure Messaging objects.
|
||||||
SM_header indicates whether or not the header of the message shall be
|
SM_header indicates whether or not the header of the message shall be
|
||||||
authenticated. It returns an unprotected command APDU
|
authenticated. It returns an unprotected command APDU
|
||||||
@param CAPDU: The protected CAPDU to be parsed
|
|
||||||
@param authenticate_header: Wether or not the header should be
|
:param CAPDU: The protected CAPDU to be parsed
|
||||||
included in authentication mechanisms
|
:param authenticate_header: Whether or not the header should be
|
||||||
@return: Unprotected command APDU
|
included in authentication mechanisms
|
||||||
"""
|
:returns: Unprotected command APDU
|
||||||
|
"""
|
||||||
|
|
||||||
structure = unpack(CAPDU.data)
|
structure = unpack(CAPDU.data)
|
||||||
return_data = ["",]
|
return_data = ["",]
|
||||||
expected = self.sm_objects
|
expected = self.sm_objects
|
||||||
@@ -399,7 +404,8 @@ class Security_Environment(object):
|
|||||||
def protect_response(self, sw, result):
|
def protect_response(self, sw, result):
|
||||||
"""
|
"""
|
||||||
This method protects a response APDU using secure messaging mechanisms
|
This method protects a response APDU using secure messaging mechanisms
|
||||||
It returns the protected data and the SW bytes
|
|
||||||
|
:returns: the protected data and the SW bytes
|
||||||
"""
|
"""
|
||||||
expected = self.sm_objects
|
expected = self.sm_objects
|
||||||
for pos in range(len(expected)):
|
for pos in range(len(expected)):
|
||||||
@@ -495,9 +501,10 @@ class Security_Environment(object):
|
|||||||
"""
|
"""
|
||||||
Compute a digital signature for the given data.
|
Compute a digital signature for the given data.
|
||||||
Algorithm and key are specified in the current SE
|
Algorithm and key are specified in the current SE
|
||||||
@param p1: Must be 0x9E = Secure Messaging class for digital signatures
|
|
||||||
@param p2: Must be one of 0x9A, 0xAC, 0xBC. Indicates what kind of data
|
:param p1: Must be 0x9E = Secure Messaging class for digital signatures
|
||||||
is included in the data field.
|
:param p2: Must be one of 0x9A, 0xAC, 0xBC. Indicates what kind of data
|
||||||
|
is included in the data field.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if p1 != 0x9E or not p2 in (0x9A, 0xAC, 0xBC):
|
if p1 != 0x9E or not p2 in (0x9A, 0xAC, 0xBC):
|
||||||
@@ -522,9 +529,10 @@ class Security_Environment(object):
|
|||||||
|
|
||||||
def hash(self, p1, p2, data):
|
def hash(self, p1, p2, data):
|
||||||
"""
|
"""
|
||||||
Hash the given data using the algorithm specified by the
|
Hash the given data using the algorithm specified by the current
|
||||||
current Security environment.
|
Security environment.
|
||||||
Return raw data (no TLV coding).
|
|
||||||
|
:return: raw data (no TLV coding).
|
||||||
"""
|
"""
|
||||||
if p1 != 0x90 or not p2 in (0x80, 0xA0):
|
if p1 != 0x90 or not p2 in (0x80, 0xA0):
|
||||||
raise SwError(SW["ERR_INCORRECTP1P2"])
|
raise SwError(SW["ERR_INCORRECTP1P2"])
|
||||||
@@ -616,7 +624,8 @@ class Security_Environment(object):
|
|||||||
"""
|
"""
|
||||||
Encipher data using key, algorithm, IV and Padding specified
|
Encipher data using key, algorithm, IV and Padding specified
|
||||||
by the current Security environment.
|
by the current Security environment.
|
||||||
Return raw data (no TLV coding).
|
|
||||||
|
:returns: raw data (no TLV coding).
|
||||||
"""
|
"""
|
||||||
algo = self.ct.algorithm
|
algo = self.ct.algorithm
|
||||||
key = self.ct.key
|
key = self.ct.key
|
||||||
@@ -631,7 +640,8 @@ class Security_Environment(object):
|
|||||||
"""
|
"""
|
||||||
Decipher data using key, algorithm, IV and Padding specified
|
Decipher data using key, algorithm, IV and Padding specified
|
||||||
by the current Security environment.
|
by the current Security environment.
|
||||||
Return raw data (no TLV coding). Padding is not removed!!!
|
|
||||||
|
:returns: raw data (no TLV coding). Padding is not removed!!!
|
||||||
"""
|
"""
|
||||||
algo = self.ct.algorithm
|
algo = self.ct.algorithm
|
||||||
key = self.ct.key
|
key = self.ct.key
|
||||||
@@ -642,16 +652,16 @@ class Security_Environment(object):
|
|||||||
return SW["NORMAL"], plain
|
return SW["NORMAL"], plain
|
||||||
|
|
||||||
def generate_public_key_pair(self, p1, p2, data):
|
def generate_public_key_pair(self, p1, p2, data):
|
||||||
"""The GENERATE PUBLIC-KEY PAIR command either initiates the generation
|
"""
|
||||||
|
The GENERATE PUBLIC-KEY PAIR command either initiates the generation
|
||||||
and storing of a key pair, i.e., a public key and a private key, in the
|
and storing of a key pair, i.e., a public key and a private key, in the
|
||||||
card, or accesses a key pair previously generated in the card.
|
card, or accesses a key pair previously generated in the card.
|
||||||
|
|
||||||
@param p1:
|
:param p1: should be 0x00 (generate new key)
|
||||||
@param p2:'00' (no information provided) or reference of the key to be
|
:param p2:'00' (no information provided) or reference of the key to be \
|
||||||
generated
|
generated
|
||||||
@param data: One or more CRTs associated to the key generation if P1-P2
|
:param data: One or more CRTs associated to the key generation if P1-P2 \
|
||||||
different from '0000'
|
different from '0000'
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from Crypto.PublicKey import RSA, DSA
|
from Crypto.PublicKey import RSA, DSA
|
||||||
|
|||||||
@@ -103,13 +103,12 @@ def write(old, newlist, offsets, datacoding, maxsize=None):
|
|||||||
"""Returns the status bytes and the result of a write operation according to
|
"""Returns the status bytes and the result of a write operation according to
|
||||||
the given data coding.
|
the given data coding.
|
||||||
|
|
||||||
@param old: string of old data
|
:param old: string of old data
|
||||||
@param newlist: a list of new data string
|
:param newlist: a list of new data string
|
||||||
@param offsets: a list of offsets, each for one new data strings
|
:param offsets: a list of offsets, each for one new data strings
|
||||||
@param datacoding: DCB["ONETIMEWRITE"] (replace) or DCB["WRITEOR"] (logical or)
|
:param datacoding: DCB["ONETIMEWRITE"] (replace) or DCB["WRITEOR"] (logical or)
|
||||||
or DCB["WRITEAND"] (logical and) or DCB["PROPRIETARY"]
|
or DCB["WRITEAND"] (logical and) or DCB["PROPRIETARY"] (logical xor)
|
||||||
(logical xor)
|
:param maxsize: the maximum number of bytes in the result
|
||||||
@param maxsize: the maximum number of bytes in the result
|
|
||||||
"""
|
"""
|
||||||
result = old
|
result = old
|
||||||
listindex = 0
|
listindex = 0
|
||||||
@@ -686,8 +685,10 @@ class MF(DF):
|
|||||||
def selectFile(self, p1, p2, data):
|
def selectFile(self, p1, p2, data):
|
||||||
"""
|
"""
|
||||||
Function for instruction 0xa4. Takes the parameter bytes 'p1', 'p2' as
|
Function for instruction 0xa4. Takes the parameter bytes 'p1', 'p2' as
|
||||||
integers and 'data' as binary string. Returns the status bytes as two
|
integers and 'data' as binary string.
|
||||||
byte long integer and the response data as binary string.
|
|
||||||
|
:returns: the status bytes as two byte long integer and the response
|
||||||
|
data as binary string.
|
||||||
"""
|
"""
|
||||||
P2_FCI = 0
|
P2_FCI = 0
|
||||||
P2_FCP = 1 << 2
|
P2_FCP = 1 << 2
|
||||||
@@ -716,8 +717,9 @@ class MF(DF):
|
|||||||
"""
|
"""
|
||||||
Decodes 'p1', 'p2' and 'data' from a data unit command (i. e.
|
Decodes 'p1', 'p2' and 'data' from a data unit command (i. e.
|
||||||
read/write/update/search/erase binary) with *odd* instruction code.
|
read/write/update/search/erase binary) with *odd* instruction code.
|
||||||
Returns the specified TransparentStructureEF, a list of offsets and a
|
|
||||||
list of data strings.
|
:returns: the specified TransparentStructureEF, a list of offsets and a
|
||||||
|
list of data strings.
|
||||||
"""
|
"""
|
||||||
if p1 >> 7:
|
if p1 >> 7:
|
||||||
# If bit 1 of INS is set to 0 and bit 8 of P1 to 1, then bits 7
|
# If bit 1 of INS is set to 0 and bit 8 of P1 to 1, then bits 7
|
||||||
@@ -741,8 +743,9 @@ class MF(DF):
|
|||||||
"""
|
"""
|
||||||
Decodes 'p1', 'p2' and 'data' from a data unit command (i. e.
|
Decodes 'p1', 'p2' and 'data' from a data unit command (i. e.
|
||||||
read/write/update/search/erase binary) with *even* instruction code.
|
read/write/update/search/erase binary) with *even* instruction code.
|
||||||
Returns the specified TransparentStructureEF, a list of offsets and a
|
|
||||||
list of data strings.
|
:returns the specified TransparentStructureEF, a list of offsets and a
|
||||||
|
list of data strings.
|
||||||
"""
|
"""
|
||||||
# If bit 1 of INS is set to 1, then P1-P2 shall identify an EF. If
|
# If bit 1 of INS is set to 1, then P1-P2 shall identify an EF. If
|
||||||
# the first eleven bits of P1-P2 are set to 0 and if bits 5 to 1 of
|
# the first eleven bits of P1-P2 are set to 0 and if bits 5 to 1 of
|
||||||
@@ -769,8 +772,10 @@ class MF(DF):
|
|||||||
def readBinaryPlain(self, p1, p2, data):
|
def readBinaryPlain(self, p1, p2, data):
|
||||||
"""
|
"""
|
||||||
Function for instruction 0xb0. Takes the parameter bytes 'p1', 'p2' as
|
Function for instruction 0xb0. Takes the parameter bytes 'p1', 'p2' as
|
||||||
integers and 'data' as binary string. Returns the status bytes as two
|
integers and 'data' as binary string.
|
||||||
byte long integer and the response data as binary string.
|
|
||||||
|
:returns: the status bytes as two byte long integer and the response
|
||||||
|
data as binary string.
|
||||||
"""
|
"""
|
||||||
ef, offsets, datalist = self.dataUnitsDecodePlain(p1, p2, data)
|
ef, offsets, datalist = self.dataUnitsDecodePlain(p1, p2, data)
|
||||||
result = ef.readbinary(offsets[0])
|
result = ef.readbinary(offsets[0])
|
||||||
@@ -780,8 +785,10 @@ class MF(DF):
|
|||||||
def readBinaryEncapsulated(self, p1, p2, data):
|
def readBinaryEncapsulated(self, p1, p2, data):
|
||||||
"""
|
"""
|
||||||
Function for instruction 0xb1. Takes the parameter bytes 'p1', 'p2' as
|
Function for instruction 0xb1. Takes the parameter bytes 'p1', 'p2' as
|
||||||
integers and 'data' as binary string. Returns the status bytes as two
|
integers and 'data' as binary string.
|
||||||
byte long integer and the response data as binary string.
|
|
||||||
|
:returns: the status bytes as two byte long integer and the response
|
||||||
|
data as binary string.
|
||||||
"""
|
"""
|
||||||
ef, offsets, datalist = self.dataUnitsDecodeEncapsulated(p1, p2, data)
|
ef, offsets, datalist = self.dataUnitsDecodeEncapsulated(p1, p2, data)
|
||||||
result = ef.readbinary(offsets[0])
|
result = ef.readbinary(offsets[0])
|
||||||
@@ -793,8 +800,10 @@ class MF(DF):
|
|||||||
def writeBinaryPlain(self, p1, p2, data):
|
def writeBinaryPlain(self, p1, p2, data):
|
||||||
"""
|
"""
|
||||||
Function for instruction 0xd0. Takes the parameter bytes 'p1', 'p2' as
|
Function for instruction 0xd0. Takes the parameter bytes 'p1', 'p2' as
|
||||||
integers and 'data' as binary string. Returns the status bytes as two
|
integers and 'data' as binary string.
|
||||||
byte long integer and the response data as binary string.
|
|
||||||
|
:returns: the status bytes as two byte long integer and the response
|
||||||
|
data as binary string.
|
||||||
"""
|
"""
|
||||||
ef, offsets, datalist = self.dataUnitsDecodePlain(p1, p2, data)
|
ef, offsets, datalist = self.dataUnitsDecodePlain(p1, p2, data)
|
||||||
ef.writebinary(offsets, datalist)
|
ef.writebinary(offsets, datalist)
|
||||||
@@ -815,8 +824,10 @@ class MF(DF):
|
|||||||
def updateBinaryPlain(self, p1, p2, data):
|
def updateBinaryPlain(self, p1, p2, data):
|
||||||
"""
|
"""
|
||||||
Function for instruction 0xd6. Takes the parameter bytes 'p1', 'p2' as
|
Function for instruction 0xd6. Takes the parameter bytes 'p1', 'p2' as
|
||||||
integers and 'data' as binary string. Returns the status bytes as two
|
integers and 'data' as binary string.
|
||||||
byte long integer and the response data as binary string.
|
|
||||||
|
:returns: the status bytes as two byte long integer and the response
|
||||||
|
data as binary string.
|
||||||
"""
|
"""
|
||||||
ef, offsets, datalist = self.dataUnitsDecodePlain(p1, p2, data)
|
ef, offsets, datalist = self.dataUnitsDecodePlain(p1, p2, data)
|
||||||
ef.updatebinary(offsets, datalist)
|
ef.updatebinary(offsets, datalist)
|
||||||
@@ -826,8 +837,10 @@ class MF(DF):
|
|||||||
def updateBinaryEncapsulated(self, p1, p2, data):
|
def updateBinaryEncapsulated(self, p1, p2, data):
|
||||||
"""
|
"""
|
||||||
Function for instruction 0xd7. Takes the parameter bytes 'p1', 'p2' as
|
Function for instruction 0xd7. Takes the parameter bytes 'p1', 'p2' as
|
||||||
integers and 'data' as binary string. Returns the status bytes as two
|
integers and 'data' as binary string.
|
||||||
byte long integer and the response data as binary string.
|
|
||||||
|
:returns: the status bytes as two byte long integer and the response
|
||||||
|
data as binary string.
|
||||||
"""
|
"""
|
||||||
ef, offsets, datalist = self.dataUnitsDecodeEncapsulated(p1, p2, data)
|
ef, offsets, datalist = self.dataUnitsDecodeEncapsulated(p1, p2, data)
|
||||||
ef.updatebinary(offsets, datalist)
|
ef.updatebinary(offsets, datalist)
|
||||||
@@ -859,8 +872,10 @@ class MF(DF):
|
|||||||
def eraseBinaryPlain(self, p1, p2, data):
|
def eraseBinaryPlain(self, p1, p2, data):
|
||||||
"""
|
"""
|
||||||
Function for instruction 0x0e. Takes the parameter bytes 'p1', 'p2' as
|
Function for instruction 0x0e. Takes the parameter bytes 'p1', 'p2' as
|
||||||
integers and 'data' as binary string. Returns the status bytes as two
|
integers and 'data' as binary string.
|
||||||
byte long integer and the response data as binary string.
|
|
||||||
|
:returns: the status bytes as two byte long integer and the response
|
||||||
|
data as binary string.
|
||||||
"""
|
"""
|
||||||
ef, offsets, datalist = self.dataUnitsDecodePlain(p1, p2, data)
|
ef, offsets, datalist = self.dataUnitsDecodePlain(p1, p2, data)
|
||||||
# If INS = '0E', then, if present, the command data field encodes
|
# If INS = '0E', then, if present, the command data field encodes
|
||||||
@@ -881,8 +896,10 @@ class MF(DF):
|
|||||||
def eraseBinaryEncapsulated(self, p1, p2, data):
|
def eraseBinaryEncapsulated(self, p1, p2, data):
|
||||||
"""
|
"""
|
||||||
Function for instruction 0x0f. Takes the parameter bytes 'p1', 'p2' as
|
Function for instruction 0x0f. Takes the parameter bytes 'p1', 'p2' as
|
||||||
integers and 'data' as binary string. Returns the status bytes as two
|
integers and 'data' as binary string.
|
||||||
byte long integer and the response data as binary string.
|
|
||||||
|
:returns: the status bytes as two byte long integer and the response
|
||||||
|
data as binary string.
|
||||||
"""
|
"""
|
||||||
ef, offsets, datalist = self.dataUnitsDecodeEncapsulated(p1, p2, data)
|
ef, offsets, datalist = self.dataUnitsDecodeEncapsulated(p1, p2, data)
|
||||||
# If INS = '0F', then, if present, the command data field shall
|
# If INS = '0F', then, if present, the command data field shall
|
||||||
@@ -909,10 +926,11 @@ class MF(DF):
|
|||||||
def recordHandlingDecode(self, p1, p2):
|
def recordHandlingDecode(self, p1, p2):
|
||||||
"""
|
"""
|
||||||
Decodes 'p1' and 'p2' from a record handling command (i. e.
|
Decodes 'p1' and 'p2' from a record handling command (i. e.
|
||||||
read/write/update/append/search/erase record). Returns the specified
|
read/write/update/append/search/erase record).
|
||||||
RecordStructureEF, the number or identifier of the record and a
|
|
||||||
reference, that specifies which record to select (i. e. the last 3 bits
|
:returns: the specified RecordStructureEF, the number or identifier of
|
||||||
of 'p1').
|
the record and a reference, that specifies which record to select
|
||||||
|
(i. e. the last 3 bits of 'p1').
|
||||||
"""
|
"""
|
||||||
if p1 == 0xff:
|
if p1 == 0xff:
|
||||||
# RFU
|
# RFU
|
||||||
@@ -938,8 +956,10 @@ class MF(DF):
|
|||||||
def readRecordPlain(self, p1, p2, data):
|
def readRecordPlain(self, p1, p2, data):
|
||||||
"""
|
"""
|
||||||
Function for instruction 0xb2. Takes the parameter bytes 'p1', 'p2' as
|
Function for instruction 0xb2. Takes the parameter bytes 'p1', 'p2' as
|
||||||
integers and 'data' as binary string. Returns the status bytes as two
|
integers and 'data' as binary string.
|
||||||
byte long integer and the response data as binary string.
|
|
||||||
|
:returns: the status bytes as two byte long integer and the response
|
||||||
|
data as binary string.
|
||||||
"""
|
"""
|
||||||
ef, num_id, reference = self.recordHandlingDecode(p1, p2)
|
ef, num_id, reference = self.recordHandlingDecode(p1, p2)
|
||||||
result = ef.readrecord(0, num_id, reference)
|
result = ef.readrecord(0, num_id, reference)
|
||||||
@@ -953,8 +973,10 @@ class MF(DF):
|
|||||||
def readRecordEncapsulated(self, p1, p2, data):
|
def readRecordEncapsulated(self, p1, p2, data):
|
||||||
"""
|
"""
|
||||||
Function for instruction 0xb3. Takes the parameter bytes 'p1', 'p2' as
|
Function for instruction 0xb3. Takes the parameter bytes 'p1', 'p2' as
|
||||||
integers and 'data' as binary string. Returns the status bytes as two
|
integers and 'data' as binary string.
|
||||||
byte long integer and the response data as binary string.
|
|
||||||
|
:returns: the status bytes as two byte long integer and the response
|
||||||
|
data as binary string.
|
||||||
"""
|
"""
|
||||||
ef, num_id, reference = self.recordHandlingDecode(p1, p2)
|
ef, num_id, reference = self.recordHandlingDecode(p1, p2)
|
||||||
result = ef.readrecord(0, num_id, reference)
|
result = ef.readrecord(0, num_id, reference)
|
||||||
@@ -964,8 +986,10 @@ class MF(DF):
|
|||||||
def writeRecord(self, p1, p2, data):
|
def writeRecord(self, p1, p2, data):
|
||||||
"""
|
"""
|
||||||
Function for instruction 0xd2. Takes the parameter bytes 'p1', 'p2' as
|
Function for instruction 0xd2. Takes the parameter bytes 'p1', 'p2' as
|
||||||
integers and 'data' as binary string. Returns the status bytes as two
|
integers and 'data' as binary string.
|
||||||
byte long integer and the response data as binary string.
|
|
||||||
|
:returns: the status bytes as two byte long integer and the response
|
||||||
|
data as binary string.
|
||||||
"""
|
"""
|
||||||
ef, num_id, reference = self.recordHandlingDecode(p1, p2)
|
ef, num_id, reference = self.recordHandlingDecode(p1, p2)
|
||||||
if reference not in [ REF["IDENTIFIER_FIRST"], REF["IDENTIFIER_LAST"],
|
if reference not in [ REF["IDENTIFIER_FIRST"], REF["IDENTIFIER_LAST"],
|
||||||
@@ -980,8 +1004,10 @@ class MF(DF):
|
|||||||
def updateRecordPlain(self, p1, p2, data):
|
def updateRecordPlain(self, p1, p2, data):
|
||||||
"""
|
"""
|
||||||
Function for instruction 0xdc. Takes the parameter bytes 'p1', 'p2' as
|
Function for instruction 0xdc. Takes the parameter bytes 'p1', 'p2' as
|
||||||
integers and 'data' as binary string. Returns the status bytes as two
|
integers and 'data' as binary string.
|
||||||
byte long integer and the response data as binary string.
|
|
||||||
|
:returns: the status bytes as two byte long integer and the response
|
||||||
|
data as binary string.
|
||||||
"""
|
"""
|
||||||
ef, num_id, reference = self.recordHandlingDecode(p1, p2)
|
ef, num_id, reference = self.recordHandlingDecode(p1, p2)
|
||||||
if reference not in [ REF["IDENTIFIER_FIRST"], REF["IDENTIFIER_LAST"],
|
if reference not in [ REF["IDENTIFIER_FIRST"], REF["IDENTIFIER_LAST"],
|
||||||
@@ -996,8 +1022,10 @@ class MF(DF):
|
|||||||
def updateRecordEncapsulated(self, p1, p2, data):
|
def updateRecordEncapsulated(self, p1, p2, data):
|
||||||
"""
|
"""
|
||||||
Function for instruction 0xdd. Takes the parameter bytes 'p1', 'p2' as
|
Function for instruction 0xdd. Takes the parameter bytes 'p1', 'p2' as
|
||||||
integers and 'data' as binary string. Returns the status bytes as two
|
integers and 'data' as binary string.
|
||||||
byte long integer and the response data as binary string.
|
|
||||||
|
:returns: the status bytes as two byte long integer and the response
|
||||||
|
data as binary string.
|
||||||
"""
|
"""
|
||||||
ef, num_id, reference = self.recordHandlingDecode(p1, p2)
|
ef, num_id, reference = self.recordHandlingDecode(p1, p2)
|
||||||
|
|
||||||
@@ -1033,8 +1061,10 @@ class MF(DF):
|
|||||||
def appendRecord(self, p1, p2, data):
|
def appendRecord(self, p1, p2, data):
|
||||||
"""
|
"""
|
||||||
Function for instruction 0xe2. Takes the parameter bytes 'p1', 'p2' as
|
Function for instruction 0xe2. Takes the parameter bytes 'p1', 'p2' as
|
||||||
integers and 'data' as binary string. Returns the status bytes as two
|
integers and 'data' as binary string.
|
||||||
byte long integer and the response data as binary string.
|
|
||||||
|
:returns: the status bytes as two byte long integer and the response
|
||||||
|
data as binary string.
|
||||||
"""
|
"""
|
||||||
if p1 != 0 or (p2 & REF["REFERENCE_CONTROL"]) != 0:
|
if p1 != 0 or (p2 & REF["REFERENCE_CONTROL"]) != 0:
|
||||||
raise SwError(SW["ERR_INCORRECTP1P2"])
|
raise SwError(SW["ERR_INCORRECTP1P2"])
|
||||||
@@ -1046,8 +1076,10 @@ class MF(DF):
|
|||||||
def eraseRecord(self, p1, p2, data):
|
def eraseRecord(self, p1, p2, data):
|
||||||
"""
|
"""
|
||||||
Function for instruction 0x0c. Takes the parameter bytes 'p1', 'p2' as
|
Function for instruction 0x0c. Takes the parameter bytes 'p1', 'p2' as
|
||||||
integers and 'data' as binary string. Returns the status bytes as two
|
integers and 'data' as binary string.
|
||||||
byte long integer and the response data as binary string.
|
|
||||||
|
:returns: the status bytes as two byte long integer and the response
|
||||||
|
data as binary string.
|
||||||
"""
|
"""
|
||||||
ef, num_id, reference = self.recordHandlingDecode(p1, p2)
|
ef, num_id, reference = self.recordHandlingDecode(p1, p2)
|
||||||
if reference not in [
|
if reference not in [
|
||||||
@@ -1062,9 +1094,11 @@ class MF(DF):
|
|||||||
def dataObjectHandlingDecodePlain(self, p1, p2, data):
|
def dataObjectHandlingDecodePlain(self, p1, p2, data):
|
||||||
"""
|
"""
|
||||||
Decodes 'p1', 'p2' and 'data' from a data object handling command (i.
|
Decodes 'p1', 'p2' and 'data' from a data object handling command (i.
|
||||||
e. get/put data) with *even* instruction code. Returns the specified
|
e. get/put data) with *even* instruction code.
|
||||||
file, True if the following list regards SIMPLE-TLV data objects False
|
|
||||||
otherwise and a list of (tag, length, value)-tuples.
|
:returns: the specified file, True if the following list regards
|
||||||
|
SIMPLE-TLV data objects False otherwise and a list of
|
||||||
|
(tag, length, value)-tuples.
|
||||||
"""
|
"""
|
||||||
if self.current == None:
|
if self.current == None:
|
||||||
raise SwError(SW["ERR_NOCURRENTEF"])
|
raise SwError(SW["ERR_NOCURRENTEF"])
|
||||||
@@ -1109,9 +1143,11 @@ class MF(DF):
|
|||||||
def dataObjectHandlingDecodeEncapsulated(self, p1, p2, data):
|
def dataObjectHandlingDecodeEncapsulated(self, p1, p2, data):
|
||||||
"""
|
"""
|
||||||
Decodes 'p1', 'p2' and 'data' from a data object handling command (i.
|
Decodes 'p1', 'p2' and 'data' from a data object handling command (i.
|
||||||
e. get/put data) with *odd* instruction code. Returns the specified
|
e. get/put data) with *odd* instruction code.
|
||||||
file, True if the following list regards SIMPLE-TLV data objects False
|
|
||||||
otherwise and a list of (tag, length, value)-tuples.
|
:returns: the specified file, True if the following list regards
|
||||||
|
SIMPLE-TLV data objects False otherwise and a list of
|
||||||
|
(tag, length, value)-tuples.
|
||||||
"""
|
"""
|
||||||
# If bit 1 of INS is set to 1, then P1-P2 shall identify a file.
|
# If bit 1 of INS is set to 1, then P1-P2 shall identify a file.
|
||||||
tlv_data = bertlv_unpack(data)
|
tlv_data = bertlv_unpack(data)
|
||||||
@@ -1147,8 +1183,10 @@ class MF(DF):
|
|||||||
def getDataPlain(self, p1, p2, data):
|
def getDataPlain(self, p1, p2, data):
|
||||||
"""
|
"""
|
||||||
Function for instruction 0xca. Takes the parameter bytes 'p1', 'p2' as
|
Function for instruction 0xca. Takes the parameter bytes 'p1', 'p2' as
|
||||||
integers and 'data' as binary string. Returns the status bytes as two
|
integers and 'data' as binary string.
|
||||||
byte long integer and the response data as binary string.
|
|
||||||
|
:returns: the status bytes as two byte long integer and the response
|
||||||
|
data as binary string.
|
||||||
"""
|
"""
|
||||||
file, isSimpleTlv, tlvlist = self.dataObjectHandlingDecodePlain(p1, p2, data)
|
file, isSimpleTlv, tlvlist = self.dataObjectHandlingDecodePlain(p1, p2, data)
|
||||||
# TODO oversized answers
|
# TODO oversized answers
|
||||||
@@ -1160,8 +1198,10 @@ class MF(DF):
|
|||||||
def getDataEncapsulated(self, p1, p2, data):
|
def getDataEncapsulated(self, p1, p2, data):
|
||||||
"""
|
"""
|
||||||
Function for instruction 0xcb. Takes the parameter bytes 'p1', 'p2' as
|
Function for instruction 0xcb. Takes the parameter bytes 'p1', 'p2' as
|
||||||
integers and 'data' as binary string. Returns the status bytes as two
|
integers and 'data' as binary string.
|
||||||
byte long integer and the response data as binary string.
|
|
||||||
|
:returns: the status bytes as two byte long integer and the response
|
||||||
|
data as binary string.
|
||||||
"""
|
"""
|
||||||
file, tlv_data = self.dataObjectHandlingDecodeEncapsulated(p1, p2, data)
|
file, tlv_data = self.dataObjectHandlingDecodeEncapsulated(p1, p2, data)
|
||||||
# TODO oversized answers
|
# TODO oversized answers
|
||||||
@@ -1176,8 +1216,10 @@ class MF(DF):
|
|||||||
def putDataPlain(self, p1, p2, data):
|
def putDataPlain(self, p1, p2, data):
|
||||||
"""
|
"""
|
||||||
Function for instruction 0xda. Takes the parameter bytes 'p1', 'p2' as
|
Function for instruction 0xda. Takes the parameter bytes 'p1', 'p2' as
|
||||||
integers and 'data' as binary string. Returns the status bytes as two
|
integers and 'data' as binary string.
|
||||||
byte long integer and the response data as binary string.
|
|
||||||
|
:returns: the status bytes as two byte long integer and the response
|
||||||
|
data as binary string.
|
||||||
"""
|
"""
|
||||||
file, isSimpleTlv, tlvlist = self.dataObjectHandlingDecodePlain(p1, p2, data)
|
file, isSimpleTlv, tlvlist = self.dataObjectHandlingDecodePlain(p1, p2, data)
|
||||||
file.putdata(isSimpleTlv, tlvlist)
|
file.putdata(isSimpleTlv, tlvlist)
|
||||||
@@ -1187,8 +1229,10 @@ class MF(DF):
|
|||||||
def putDataEncapsulated(self, p1, p2, data):
|
def putDataEncapsulated(self, p1, p2, data):
|
||||||
"""
|
"""
|
||||||
Function for instruction 0xdb. Takes the parameter bytes 'p1', 'p2' as
|
Function for instruction 0xdb. Takes the parameter bytes 'p1', 'p2' as
|
||||||
integers and 'data' as binary string. Returns the status bytes as two
|
integers and 'data' as binary string.
|
||||||
byte long integer and the response data as binary string.
|
|
||||||
|
:returns: the status bytes as two byte long integer and the response
|
||||||
|
data as binary string.
|
||||||
"""
|
"""
|
||||||
file, tlvlist = self.dataObjectHandlingDecodeEncapsulated(p1, p2, data)
|
file, tlvlist = self.dataObjectHandlingDecodeEncapsulated(p1, p2, data)
|
||||||
file.putdata(False, tlvlist)
|
file.putdata(False, tlvlist)
|
||||||
@@ -1270,8 +1314,10 @@ class MF(DF):
|
|||||||
def createFile(self, p1, p2, data):
|
def createFile(self, p1, p2, data):
|
||||||
"""
|
"""
|
||||||
Function for instruction 0xe0. Takes the parameter bytes 'p1', 'p2' as
|
Function for instruction 0xe0. Takes the parameter bytes 'p1', 'p2' as
|
||||||
integers and 'data' as binary string. Returns the status bytes as two
|
integers and 'data' as binary string.
|
||||||
byte long integer and the response data as binary string.
|
|
||||||
|
:returns: the status bytes as two byte long integer and the response
|
||||||
|
data as binary string.
|
||||||
"""
|
"""
|
||||||
df = self.currentDF()
|
df = self.currentDF()
|
||||||
if df == None:
|
if df == None:
|
||||||
@@ -1287,8 +1333,10 @@ class MF(DF):
|
|||||||
def deleteFile(self, p1, p2, data):
|
def deleteFile(self, p1, p2, data):
|
||||||
"""
|
"""
|
||||||
Function for instruction 0xe4. Takes the parameter bytes 'p1', 'p2' as
|
Function for instruction 0xe4. Takes the parameter bytes 'p1', 'p2' as
|
||||||
integers and 'data' as binary string. Returns the status bytes as two
|
integers and 'data' as binary string.
|
||||||
byte long integer and the response data as binary string.
|
|
||||||
|
:returns: the status bytes as two byte long integer and the response
|
||||||
|
data as binary string.
|
||||||
"""
|
"""
|
||||||
file = self._selectFile(p1, p2, data)
|
file = self._selectFile(p1, p2, data)
|
||||||
file.parent.content.remove(file)
|
file.parent.content.remove(file)
|
||||||
@@ -1356,9 +1404,9 @@ class TransparentStructureEF(EF):
|
|||||||
Writes pieces of data to the specified offsets honoring the given
|
Writes pieces of data to the specified offsets honoring the given
|
||||||
coding byte.
|
coding byte.
|
||||||
|
|
||||||
offsets -- list of integers. Offsets.
|
:param offsets: list of integers. Offsets.
|
||||||
datalist -- list of strings. Data pieces.
|
:param datalist: list of strings. Data pieces.
|
||||||
datacoding -- the data coding byte to use for writing
|
:param datacoding: the data coding byte to use for writing
|
||||||
"""
|
"""
|
||||||
data = self.getenc('data')
|
data = self.getenc('data')
|
||||||
if datacoding:
|
if datacoding:
|
||||||
@@ -1430,8 +1478,8 @@ class RecordStructureEF(EF):
|
|||||||
which kind of record structured file you want to create (i. e.
|
which kind of record structured file you want to create (i. e.
|
||||||
linear/cyclic or variable/fixed EF). The record pointer is reset.
|
linear/cyclic or variable/fixed EF). The record pointer is reset.
|
||||||
|
|
||||||
records -- list of Records
|
:param records: list of Records
|
||||||
maxrecordsize -- integer. maximum length of a record's data.
|
:para, maxrecordsize: integer. maximum length of a record's data.
|
||||||
|
|
||||||
See EF for more.
|
See EF for more.
|
||||||
"""
|
"""
|
||||||
@@ -1495,8 +1543,9 @@ class RecordStructureEF(EF):
|
|||||||
"""
|
"""
|
||||||
Returns a list of records. Is to be involved by __getRecords.
|
Returns a list of records. Is to be involved by __getRecords.
|
||||||
|
|
||||||
number -- The requested record's number
|
:param number: The requested record's number
|
||||||
reference -- Specifies which record to select (usually the last 3 bits of 'p1' of a record handling command)
|
:param reference: Specifies which record to select (usually the last 3
|
||||||
|
bits of 'p1' of a record handling command)
|
||||||
"""
|
"""
|
||||||
result = []
|
result = []
|
||||||
records = self.getenc('records')
|
records = self.getenc('records')
|
||||||
@@ -1528,8 +1577,9 @@ class RecordStructureEF(EF):
|
|||||||
Returns a list of records and sets the recordpointer to the first
|
Returns a list of records and sets the recordpointer to the first
|
||||||
record, that matched. Is to be involved by __getRecords.
|
record, that matched. Is to be involved by __getRecords.
|
||||||
|
|
||||||
id -- The requested record's identifier
|
:param id: The requested record's identifier
|
||||||
reference -- Specifies which record to select (usually the last 3 bits of 'p1' of a record handling command)
|
:param reference: Specifies which record to select (usually the last 3
|
||||||
|
bits of 'p1' of a record handling command)
|
||||||
"""
|
"""
|
||||||
result = []
|
result = []
|
||||||
records = self.getenc('records')
|
records = self.getenc('records')
|
||||||
|
|||||||
@@ -147,8 +147,8 @@ class SAM(object):
|
|||||||
|
|
||||||
def set_asym_algorithm(self, cipher, keytype):
|
def set_asym_algorithm(self, cipher, keytype):
|
||||||
"""
|
"""
|
||||||
@param cipher: Public/private key object from used for encryption
|
:param cipher: Public/private key object from used for encryption
|
||||||
@param keytype: Type of the public key (e.g. RSA, DSA)
|
:param keytype: Type of the public key (e.g. RSA, DSA)
|
||||||
"""
|
"""
|
||||||
if not keytype in range(0x07, 0x08):
|
if not keytype in range(0x07, 0x08):
|
||||||
raise SwError(SW["ERR_INCORRECTP1P2"])
|
raise SwError(SW["ERR_INCORRECTP1P2"])
|
||||||
@@ -289,8 +289,9 @@ class SAM(object):
|
|||||||
"""
|
"""
|
||||||
This method returns the key specified by the p2 parameter. The key may be
|
This method returns the key specified by the p2 parameter. The key may be
|
||||||
stored on the cards filesystem.
|
stored on the cards filesystem.
|
||||||
@param p1: Specifies the algorithm to use. Needed to know the keylength.
|
|
||||||
@param p2: Specifies a reference to the key to be used for encryption
|
:param p1: Specifies the algorithm to use. Needed to know the keylength.
|
||||||
|
:param p2: Specifies a reference to the key to be used for encryption
|
||||||
|
|
||||||
Meaning of p2:
|
Meaning of p2:
|
||||||
b8 b7 b6 b5 b4 b3 b2 b1 | Meaning
|
b8 b7 b6 b5 b4 b3 b2 b1 | Meaning
|
||||||
|
|||||||
@@ -37,10 +37,10 @@ class CryptoflexSE(Security_Environment):
|
|||||||
"""
|
"""
|
||||||
In the Cryptoflex card this command only supports RSA keys.
|
In the Cryptoflex card this command only supports RSA keys.
|
||||||
|
|
||||||
@param data: Contains the public exponent used for key generation
|
:param data: Contains the public exponent used for key generation
|
||||||
@param p1: The keynumber. Can be used later to refer to the generated key
|
:param p1: The key number. Can be used later to refer to the generated key \
|
||||||
@param p2: Used to specify the keylength.
|
:param p2: Used to specify the key length. The mapping is: 0x40 => 256 \
|
||||||
The mapping is: 0x40 => 256 Bit, 0x60 => 512 Bit, 0x80 => 1024
|
Bit, 0x60 => 512 Bit, 0x80 => 1024
|
||||||
"""
|
"""
|
||||||
from Crypto.PublicKey import RSA
|
from Crypto.PublicKey import RSA
|
||||||
from Crypto.Util.randpool import RandomPool
|
from Crypto.Util.randpool import RandomPool
|
||||||
@@ -107,9 +107,11 @@ class CryptoflexSAM(SAM):
|
|||||||
In the cryptoflex card, this is the verify key command. A key is send
|
In the cryptoflex card, this is the verify key command. A key is send
|
||||||
to the card in plain text and compared to a key stored in the card.
|
to the card in plain text and compared to a key stored in the card.
|
||||||
This is used for authentication
|
This is used for authentication
|
||||||
@param data: Contains the key to be verified
|
|
||||||
@return: SW[NORMAL] in case of success otherwise SW[WARN_NOINFO63]
|
:param data: Contains the key to be verified
|
||||||
|
:returns: SW[NORMAL] in case of success otherwise SW[WARN_NOINFO63]
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return SW["NORMAL"], ""
|
return SW["NORMAL"], ""
|
||||||
#FIXME
|
#FIXME
|
||||||
#key = self._get_referenced_key(p1,p2)
|
#key = self._get_referenced_key(p1,p2)
|
||||||
|
|||||||
Reference in New Issue
Block a user