Honor generic_card.DEBUG

git-svn-id: svn+ssh://localhost/home/henryk/svn/cyberflex-shell/trunk@219 f711b948-2313-0410-aaa9-d29f33439f0b
This commit is contained in:
hploetz 2007-06-07 22:28:43 +00:00
parent bda175ccb2
commit 84e812ebf7
1 changed files with 46 additions and 33 deletions

View File

@ -1,6 +1,6 @@
import utils, TLV_utils, crypto_utils, traceback
from iso_7816_4_card import *
import building_blocks
import building_blocks, generic_card
MODE_ECB = 0
MODE_CBC = 1
@ -180,6 +180,7 @@ class TCOS_Security_Environment(object):
t = tag & ~(0x01)
if t == 0x84:
value_ = self.pad(value)
if generic_card.DEBUG:
print "| Tag 0x%02x, length 0x%02x, encrypting (with ISO padding): " % (tag, length)
print "|| " + "\n|| ".join( utils.hexdump( value_ ).splitlines() )
@ -189,12 +190,14 @@ class TCOS_Security_Environment(object):
value_,
self.get_iv(config) )
if generic_card.DEBUG:
print "| Encrypted result of length 0x%02x:" % len(value)
print "|| " + "\n|| ".join( utils.hexdump(value).splitlines() )
print
elif t == 0x86:
pi = value[0]
value_ = self.pad(value[1:], ord(pi))
if generic_card.DEBUG:
print "| Tag 0x%02x, length 0x%02x, encrypting (with padding type %x): " % (tag, length, ord(pi))
print "|| " + "\n|| ".join( utils.hexdump( value_ ).splitlines() )
@ -204,6 +207,7 @@ class TCOS_Security_Environment(object):
value_,
self.get_iv(config) )
if generic_card.DEBUG:
print "| Encrypted result of length 0x%02x:" % len(value)
print "|| " + "\n|| ".join( utils.hexdump(value).splitlines() )
print
@ -227,6 +231,7 @@ class TCOS_Security_Environment(object):
marks = len(data) > 3 and data[3] or ()
t = tag & ~(0x01)
if t == 0x84:
if generic_card.DEBUG:
print
print "| Tag 0x%02x, length 0x%02x, encrypted (with ISO padding): " % (tag, length)
print "|| " + "\n|| ".join( utils.hexdump( value ).splitlines() )
@ -237,6 +242,7 @@ class TCOS_Security_Environment(object):
value,
self.get_iv(config) )
if generic_card.DEBUG:
print "| Decrypted result of length 0x%02x:" % len(value_)
print "|| " + "\n|| ".join( utils.hexdump(value_).splitlines() )
@ -248,6 +254,7 @@ class TCOS_Security_Environment(object):
marks = marks + (self.MARK_ENCRYPT,)
elif t == 0x86:
pi = value[0]
if generic_card.DEBUG:
print
print "| Tag 0x%02x, length 0x%02x, decrypting (with padding type %x): " % (tag, length, ord(pi))
print "|| " + "\n|| ".join( utils.hexdump( value[1:] ).splitlines() )
@ -258,6 +265,7 @@ class TCOS_Security_Environment(object):
value[1:],
self.get_iv(config) )
if generic_card.DEBUG:
print "| Decrypted result of length 0x%02x:" % len(value_)
print "|| " + "\n|| ".join( utils.hexdump(value_).splitlines() )
@ -335,7 +343,8 @@ class TCOS_Security_Environment(object):
startblock = ""
if apdu.cla & 0x0c == 0x0c:
startblock = apdu.render()[:4]
cct = self.calculate_cct(config, tlv_data, startblock)
cct = self.calculate_cct(config, tlv_data, startblock, print_buffer=generic_card.DEBUG)
if generic_card.DEBUG:
print
data = tuple( (0x8e, len(cct), cct) + data[3:] )
@ -349,6 +358,7 @@ class TCOS_Security_Environment(object):
if config.algorithm is None: ## FIXME: Find out the correct way to determine this
return tlv_data
if generic_card.DEBUG:
print
cct_claimed = None
result = []
@ -360,16 +370,19 @@ class TCOS_Security_Environment(object):
result.append( data )
if cct_claimed is None:
if generic_card.DEBUG:
print "| CRYPTOGRAPHIC CHECKSUM VERIFICATION ERROR"
print "| No cryptographic checksum was included in the response"
return tlv_data
else:
cct = self.calculate_cct(config, tlv_data)
cct = self.calculate_cct(config, tlv_data, print_buffer=generic_card.DEBUG)
if len(cct_claimed) >= 4 and cct.startswith(cct_claimed):
if generic_card.DEBUG:
print "| Cryptographic checksum verifies OK"
return result
else:
if generic_card.DEBUG:
print "| CRYPTOGRAPHIC CHECKSUM VERIFICATION ERROR"
print "| Is:"
print "|| " + "\n|| ".join( utils.hexdump( cct_claimed ).splitlines() )