diff options
author | hploetz <hploetz@f711b948-2313-0410-aaa9-d29f33439f0b> | 2006-11-22 06:26:28 +0000 |
---|---|---|
committer | hploetz <hploetz@f711b948-2313-0410-aaa9-d29f33439f0b> | 2006-11-22 06:26:28 +0000 |
commit | 09560911b658a1fefa4e6b95273812b1494337d7 (patch) | |
tree | 13912c0c76656a30be86a2f29cee360365f26753 /cards | |
parent | 7cba0484e847a10a0c4ab704db4c50bd4dab8dcb (diff) |
separate SE configs for mac and encrytion
git-svn-id: svn+ssh://localhost/home/henryk/svn/cyberflex-shell/trunk@138 f711b948-2313-0410-aaa9-d29f33439f0b
Diffstat (limited to 'cards')
-rw-r--r-- | cards/tcos_card.py | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/cards/tcos_card.py b/cards/tcos_card.py index 634c916..da812ef 100644 --- a/cards/tcos_card.py +++ b/cards/tcos_card.py @@ -7,9 +7,12 @@ MODE_CBC = 1 ALGO_IDEA = 0x1 ALGO_DES = 0x2 ALGO_DES3 = 0x3 +SE_APDU = 1 +SE_RAPDU = 2 +SE_PSO = 3 class SE_Config: - def __init__(self, config = None, operation = "\xB4"): + def __init__(self, config = None): self.algorithm = None self.mode = MODE_ECB self.keyref = 0 @@ -45,9 +48,15 @@ class TCOS_Security_Environment(object): self.card = card self.last_c_apdu = None self.last_r_apdu = None - self.mso = SE_Config() - self.se_apdu = SE_Config() - self.se_rapdu = SE_Config() + self.config = {} + + def get_config(self, context, operation): + if not self.config.has_key( (context, operation) ): + self.set_config( context, operation, SE_Config() ) + return self.config[ context, operation ] + + def set_config(self, context, operation, config): + self.config[ context, operation ] = config def before_send(self, apdu): self.last_c_apdu = apdu @@ -62,15 +71,15 @@ class TCOS_Security_Environment(object): return result def parse_mse(self, apdu): - if apdu.p1 & 1 != 1: - return + assert apdu.p1 & 0x0f == 1 + operation = apdu.p2 if apdu.p1 & 0x10 == 0x10: - self.se_apdu = SE_Config(apdu.data, apdu.p2) + self.set_config( SE_APDU, operation, SE_Config(apdu.data) ) if apdu.p1 & 0x20 == 0x20: - self.se_rapdu = SE_Config(apdu.data, apdu.p2) + self.set_config( SE_RAPDU, operation, SE_Config(apdu.data) ) if apdu.p1 & 0xc0 == 0xc0: - self.se_pso = SE_Config(apdu.data, apdu.p2) + self.set_config( SE_PSO, operation, SE_Config(apdu.data) ) def set_key(self, keyref, keyvalue): self.keys[keyref] = keyvalue |