removed the currently unused getenc and setenc
These functions intended to do encryption and decryption respecting file acls. This however was never implemented. Better use object properties with appropriately setters and getters to realize this functionality.
This commit is contained in:
@@ -250,11 +250,11 @@ class File(object):
|
|||||||
if simpletlv_data:
|
if simpletlv_data:
|
||||||
if not isinstance(simpletlv_data, list):
|
if not isinstance(simpletlv_data, list):
|
||||||
raise TypeError("must be a list of (tag, length, value)-tuples")
|
raise TypeError("must be a list of (tag, length, value)-tuples")
|
||||||
self.setdec('simpletlv_data', simpletlv_data)
|
self.simpletlv_data = simpletlv_data
|
||||||
if bertlv_data:
|
if bertlv_data:
|
||||||
if not isinstance(bertlv_data, list):
|
if not isinstance(bertlv_data, list):
|
||||||
raise TypeError("must be a list of (tag, length, value)-tuples")
|
raise TypeError("must be a list of (tag, length, value)-tuples")
|
||||||
self.setdec('bertlv_data', bertlv_data)
|
self.bertlv_data = bertlv_data
|
||||||
|
|
||||||
def decrypt(self, path, data):
|
def decrypt(self, path, data):
|
||||||
if self.SAM == None: #WARNING: Fails silent
|
if self.SAM == None: #WARNING: Fails silent
|
||||||
@@ -280,14 +280,6 @@ class File(object):
|
|||||||
else:
|
else:
|
||||||
return self.parent.getpath() + inttostring(self.fid, 2)
|
return self.parent.getpath() + inttostring(self.fid, 2)
|
||||||
|
|
||||||
def getenc(self, attribute):
|
|
||||||
"""Returns the decrypted data of an 'attribute' from the file."""
|
|
||||||
return loads(self.decrypt(self.getpath(), getattr(self, attribute)))
|
|
||||||
|
|
||||||
def setdec(self, attribute, data):
|
|
||||||
"""Encrypts 'data' and sets the file's 'attribute' to the chiffre."""
|
|
||||||
setattr(self, attribute, dumps(self.encrypt(self.getpath(), data)))
|
|
||||||
|
|
||||||
def getdata(self, isSimpleTlv, requestedTL):
|
def getdata(self, isSimpleTlv, requestedTL):
|
||||||
"""
|
"""
|
||||||
Returns a string of either the file's BER-TLV or the file's SIMPLE-TLV
|
Returns a string of either the file's BER-TLV or the file's SIMPLE-TLV
|
||||||
@@ -303,7 +295,7 @@ class File(object):
|
|||||||
if not hasattr(self, attribute):
|
if not hasattr(self, attribute):
|
||||||
raise SwError(SW["ERR_NOTSUPPORTED"])
|
raise SwError(SW["ERR_NOTSUPPORTED"])
|
||||||
|
|
||||||
tlv_data = self.getenc(attribute)
|
tlv_data = getattr(self, attribute)
|
||||||
if requestedTL == []:
|
if requestedTL == []:
|
||||||
result = tlv_data
|
result = tlv_data
|
||||||
else:
|
else:
|
||||||
@@ -339,7 +331,7 @@ class File(object):
|
|||||||
if not hasattr(self, attribute):
|
if not hasattr(self, attribute):
|
||||||
raise SwError(SW["ERR_NOTSUPPORTED"])
|
raise SwError(SW["ERR_NOTSUPPORTED"])
|
||||||
|
|
||||||
tlv_data = self.getenc(attribute)
|
tlv_data = getattr(self, attribute)
|
||||||
for tag, newlength, newvalue in newtlvlist:
|
for tag, newlength, newvalue in newtlvlist:
|
||||||
tagfound = False
|
tagfound = False
|
||||||
for i in range(0, len(tlv_data)):
|
for i in range(0, len(tlv_data)):
|
||||||
@@ -352,7 +344,7 @@ class File(object):
|
|||||||
tagfound = True
|
tagfound = True
|
||||||
if not tagfound:
|
if not tagfound:
|
||||||
tlv_data.append(tag, newlength, newvalue)
|
tlv_data.append(tag, newlength, newvalue)
|
||||||
self.setdec(attribute, tlv_data)
|
setattr(self, attribute, tlv_data)
|
||||||
|
|
||||||
def readbinary(self, *argz, **args):
|
def readbinary(self, *argz, **args):
|
||||||
"""Only a template, will raise an error."""
|
"""Only a template, will raise an error."""
|
||||||
@@ -412,7 +404,7 @@ class DF(File):
|
|||||||
self.content = []
|
self.content = []
|
||||||
# TODO: opensc sends the length of data, but what does it limit
|
# TODO: opensc sends the length of data, but what does it limit
|
||||||
# (bertlv-data/simpletlv-data/number of files in DF, ...)?
|
# (bertlv-data/simpletlv-data/number of files in DF, ...)?
|
||||||
self.setdec('data', data)
|
self.data = data
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
"""
|
"""
|
||||||
@@ -582,7 +574,7 @@ class MF(DF):
|
|||||||
fdm.append("%c\x00" % TAG["SHORTFID"])
|
fdm.append("%c\x00" % TAG["SHORTFID"])
|
||||||
|
|
||||||
if isinstance(file, TransparentStructureEF):
|
if isinstance(file, TransparentStructureEF):
|
||||||
l = inttostring(len(file.getenc('data')))
|
l = inttostring(len(file.data))
|
||||||
fdm.append("%c%c%s" % (TAG["BYTES_EXCLUDINGSTRUCTURE"],
|
fdm.append("%c%c%s" % (TAG["BYTES_EXCLUDINGSTRUCTURE"],
|
||||||
chr(len(l)), l))
|
chr(len(l)), l))
|
||||||
fdm.append("%c%c%s" % (TAG["BYTES_INCLUDINGSTRUCTURE"],
|
fdm.append("%c%c%s" % (TAG["BYTES_INCLUDINGSTRUCTURE"],
|
||||||
@@ -592,7 +584,7 @@ class MF(DF):
|
|||||||
|
|
||||||
elif isinstance(file, RecordStructureEF):
|
elif isinstance(file, RecordStructureEF):
|
||||||
l = 0
|
l = 0
|
||||||
records = file.getenc('records')
|
records = file.records
|
||||||
for r in records:
|
for r in records:
|
||||||
if file.hasSimpleTlv():
|
if file.hasSimpleTlv():
|
||||||
l += simpletlv_unpack(r.data)[0][1]
|
l += simpletlv_unpack(r.data)[0][1]
|
||||||
@@ -1378,11 +1370,11 @@ class TransparentStructureEF(EF):
|
|||||||
filedescriptor, lifecycle,
|
filedescriptor, lifecycle,
|
||||||
simpletlv_data, bertlv_data,
|
simpletlv_data, bertlv_data,
|
||||||
datacoding, shortfid)
|
datacoding, shortfid)
|
||||||
self.setdec('data', data)
|
self.data = data
|
||||||
|
|
||||||
def readbinary(self, offset):
|
def readbinary(self, offset):
|
||||||
"""Returns the string of decrypted data beginning at 'offset'."""
|
"""Returns the string of decrypted data beginning at 'offset'."""
|
||||||
data = self.getenc('data')
|
data = self.data
|
||||||
|
|
||||||
if offset + 1 > len(data):
|
if offset + 1 > len(data):
|
||||||
raise SwError(SW["ERR_OFFSETOUTOFFILE"])
|
raise SwError(SW["ERR_OFFSETOUTOFFILE"])
|
||||||
@@ -1398,12 +1390,12 @@ class TransparentStructureEF(EF):
|
|||||||
:param datalist: list of strings. Data pieces.
|
:param datalist: list of strings. Data pieces.
|
||||||
:param 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.data
|
||||||
if datacoding:
|
if datacoding:
|
||||||
data = write(data, datalist, offsets, datacoding)
|
data = write(data, datalist, offsets, datacoding)
|
||||||
else:
|
else:
|
||||||
data = write(data, datalist, offsets, self.datacoding)
|
data = write(data, datalist, offsets, self.datacoding)
|
||||||
self.setdec('data', data)
|
self.data = data
|
||||||
|
|
||||||
def updatebinary(self, offsets, datalist):
|
def updatebinary(self, offsets, datalist):
|
||||||
"""
|
"""
|
||||||
@@ -1416,7 +1408,7 @@ class TransparentStructureEF(EF):
|
|||||||
Sets (part of) the content of an EF to its logical erased state,
|
Sets (part of) the content of an EF to its logical erased state,
|
||||||
sequentially starting from 'erasefrom' ending at 'eraseto'.
|
sequentially starting from 'erasefrom' ending at 'eraseto'.
|
||||||
"""
|
"""
|
||||||
data = self.getenc('data')
|
data = self.data
|
||||||
if erasefrom == None:
|
if erasefrom == None:
|
||||||
erasefrom = 0
|
erasefrom = 0
|
||||||
if eraseto == None:
|
if eraseto == None:
|
||||||
@@ -1428,7 +1420,7 @@ class TransparentStructureEF(EF):
|
|||||||
raise SwError(SW["ERR_INCORRECTPARAMETERS"])
|
raise SwError(SW["ERR_INCORRECTPARAMETERS"])
|
||||||
|
|
||||||
data = data[0:erasefrom] + data[eraseto:len(data)]
|
data = data[0:erasefrom] + data[eraseto:len(data)]
|
||||||
self.setdec('data', data)
|
self.data = data
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1482,7 +1474,7 @@ class RecordStructureEF(EF):
|
|||||||
if len(r.data) > maxrecordsize or (self.hasFixedRecordSize() and
|
if len(r.data) > maxrecordsize or (self.hasFixedRecordSize() and
|
||||||
len(r.data) < maxrecordsize):
|
len(r.data) < maxrecordsize):
|
||||||
raise SwError(SW["ERR_INCOMPATIBLEWITHFILE"])
|
raise SwError(SW["ERR_INCOMPATIBLEWITHFILE"])
|
||||||
self.setdec('records', records)
|
self.records = records
|
||||||
self.resetRecordPointer()
|
self.resetRecordPointer()
|
||||||
self.maxrecordsize = maxrecordsize
|
self.maxrecordsize = maxrecordsize
|
||||||
|
|
||||||
@@ -1538,7 +1530,7 @@ class RecordStructureEF(EF):
|
|||||||
bits of 'p1' of a record handling command)
|
bits of 'p1' of a record handling command)
|
||||||
"""
|
"""
|
||||||
result = []
|
result = []
|
||||||
records = self.getenc('records')
|
records = self.records
|
||||||
|
|
||||||
if number == 0:
|
if number == 0:
|
||||||
# refer to the current record
|
# refer to the current record
|
||||||
@@ -1572,7 +1564,7 @@ class RecordStructureEF(EF):
|
|||||||
bits of 'p1' of a record handling command)
|
bits of 'p1' of a record handling command)
|
||||||
"""
|
"""
|
||||||
result = []
|
result = []
|
||||||
records = self.getenc('records')
|
records = self.records
|
||||||
|
|
||||||
indexes = get_indexes(records, reference, self.recordpointer)
|
indexes = get_indexes(records, reference, self.recordpointer)
|
||||||
for i in indexes:
|
for i in indexes:
|
||||||
@@ -1651,14 +1643,14 @@ class RecordStructureEF(EF):
|
|||||||
if self.hasFixedRecordSize():
|
if self.hasFixedRecordSize():
|
||||||
data = chr(0)*(self.maxrecordsize) + data
|
data = chr(0)*(self.maxrecordsize) + data
|
||||||
|
|
||||||
records = self.getenc('records')
|
records = self.records
|
||||||
if self.isCyclic():
|
if self.isCyclic():
|
||||||
records.insert(0, Record(recordidentifier, data))
|
records.insert(0, Record(recordidentifier, data))
|
||||||
self.recordpointer = 0
|
self.recordpointer = 0
|
||||||
else:
|
else:
|
||||||
records.append(Record(recordidentifier, data))
|
records.append(Record(recordidentifier, data))
|
||||||
self.recordpointer = len(records)-1
|
self.recordpointer = len(records)-1
|
||||||
self.setdec('records', records)
|
self.records = records
|
||||||
|
|
||||||
def eraserecord(self, num_id, reference):
|
def eraserecord(self, num_id, reference):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -506,10 +506,10 @@ class NPAOS(Iso7816OS):
|
|||||||
self.atr = '\x3B\x8A\x80\x01\x80\x31\xF8\x73\xF7\x41\xE0\x82\x90\x00\x75'
|
self.atr = '\x3B\x8A\x80\x01\x80\x31\xF8\x73\xF7\x41\xE0\x82\x90\x00\x75'
|
||||||
if ef_cardsecurity:
|
if ef_cardsecurity:
|
||||||
ef = self.mf.select('fid', 0x011d)
|
ef = self.mf.select('fid', 0x011d)
|
||||||
ef.setdec('data', ef_cardsecurity)
|
ef.data = ef_cardsecurity
|
||||||
if ef_cardaccess:
|
if ef_cardaccess:
|
||||||
ef = self.mf.select('fid', 0x011c)
|
ef = self.mf.select('fid', 0x011c)
|
||||||
ef.setdec('data', ef_cardaccess)
|
ef.data = ef_cardaccess
|
||||||
if ca:
|
if ca:
|
||||||
self.SAM.current_SE.ca = ca
|
self.SAM.current_SE.ca = ca
|
||||||
if ca_key:
|
if ca_key:
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ class nPA_SE(Security_Environment):
|
|||||||
raise SwError(SW["ERR_INCORRECTPARAMETERS"])
|
raise SwError(SW["ERR_INCORRECTPARAMETERS"])
|
||||||
|
|
||||||
ef_card_access = self.mf.select('fid', 0x011c)
|
ef_card_access = self.mf.select('fid', 0x011c)
|
||||||
ef_card_access_data = ef_card_access.getenc('data')
|
ef_card_access_data = ef_card_access.data
|
||||||
pace.EAC_CTX_init_ef_cardaccess(ef_card_access_data, self.eac_ctx)
|
pace.EAC_CTX_init_ef_cardaccess(ef_card_access_data, self.eac_ctx)
|
||||||
pace.EAC_CTX_init_ca(self.eac_ctx, pace.id_CA_ECDH_AES_CBC_CMAC_128, 13, self.ca_key, self.ca_pubkey)
|
pace.EAC_CTX_init_ca(self.eac_ctx, pace.id_CA_ECDH_AES_CBC_CMAC_128, 13, self.ca_key, self.ca_pubkey)
|
||||||
|
|
||||||
@@ -213,9 +213,9 @@ class nPA_SE(Security_Environment):
|
|||||||
|
|
||||||
# save public key in EF.CardSecurity (and invalidate the signature)
|
# save public key in EF.CardSecurity (and invalidate the signature)
|
||||||
ef_card_security = self.mf.select('fid', 0x011d)
|
ef_card_security = self.mf.select('fid', 0x011d)
|
||||||
ef_card_security_data = ef_card_security.getenc('data')
|
ef_card_security_data = ef_card_security.data
|
||||||
ef_card_security_data = ef_card_security_data[:61+4+239+2+1] + pubkey + ef_card_security_data[61+4+239+2+1+len(pubkey):]
|
ef_card_security_data = ef_card_security_data[:61+4+239+2+1] + pubkey + ef_card_security_data[61+4+239+2+1+len(pubkey):]
|
||||||
ef_card_security.setdec('data', ef_card_security_data)
|
ef_card_security.data = ef_card_security_data
|
||||||
|
|
||||||
nonce = pace.PACE_STEP1_enc_nonce(self.eac_ctx, self.sec)
|
nonce = pace.PACE_STEP1_enc_nonce(self.eac_ctx, self.sec)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user