34
34
35
35
# various BER-TLV encoded Data Objects (DOs)
36
36
37
+
37
38
class AidRefDO (BER_TLV_IE , tag = 0x4f ):
38
39
# SEID v1.1 Table 6-3
39
40
_construct = HexAdapter (GreedyBytes )
40
41
42
+
41
43
class AidRefEmptyDO (BER_TLV_IE , tag = 0xc0 ):
42
44
# SEID v1.1 Table 6-3
43
45
pass
44
46
47
+
45
48
class DevAppIdRefDO (BER_TLV_IE , tag = 0xc1 ):
46
49
# SEID v1.1 Table 6-4
47
50
_construct = HexAdapter (GreedyBytes )
48
51
52
+
49
53
class PkgRefDO (BER_TLV_IE , tag = 0xca ):
50
54
# Android UICC Carrier Privileges specific extension, see https://source.android.com/devices/tech/config/uicc
51
55
_construct = Struct ('package_name_string' / GreedyString ("ascii" ))
52
56
53
- class RefDO (BER_TLV_IE , tag = 0xe1 , nested = [AidRefDO ,AidRefEmptyDO ,DevAppIdRefDO ,PkgRefDO ]):
57
+
58
+ class RefDO (BER_TLV_IE , tag = 0xe1 , nested = [AidRefDO , AidRefEmptyDO , DevAppIdRefDO , PkgRefDO ]):
54
59
# SEID v1.1 Table 6-5
55
60
pass
56
61
62
+
57
63
class ApduArDO (BER_TLV_IE , tag = 0xd0 ):
58
64
# SEID v1.1 Table 6-8
59
- def _from_bytes (self , do :bytes ):
65
+ def _from_bytes (self , do : bytes ):
60
66
if len (do ) == 1 :
61
67
if do [0 ] == 0x00 :
62
68
self .decoded = {'generic_access_rule' : 'never' }
@@ -76,6 +82,7 @@ def _from_bytes(self, do:bytes):
76
82
'mask' : b2h (do [offset + 4 :offset + 8 ])}
77
83
self .decoded = res
78
84
return res
85
+
79
86
def _to_bytes (self ):
80
87
if 'generic_access_rule' in self .decoded :
81
88
if self .decoded ['generic_access_rule' ] == 'never' :
@@ -99,94 +106,118 @@ def _to_bytes(self):
99
106
res += header_b + mask_b
100
107
return res
101
108
109
+
102
110
class NfcArDO (BER_TLV_IE , tag = 0xd1 ):
103
111
# SEID v1.1 Table 6-9
104
- _construct = Struct ('nfc_event_access_rule' / Enum (Int8ub , never = 0 , always = 1 ))
112
+ _construct = Struct ('nfc_event_access_rule' /
113
+ Enum (Int8ub , never = 0 , always = 1 ))
114
+
105
115
106
116
class PermArDO (BER_TLV_IE , tag = 0xdb ):
107
117
# Android UICC Carrier Privileges specific extension, see https://source.android.com/devices/tech/config/uicc
108
118
_construct = Struct ('permissions' / HexAdapter (Bytes (8 )))
109
119
120
+
110
121
class ArDO (BER_TLV_IE , tag = 0xe3 , nested = [ApduArDO , NfcArDO , PermArDO ]):
111
122
# SEID v1.1 Table 6-7
112
123
pass
113
124
125
+
114
126
class RefArDO (BER_TLV_IE , tag = 0xe2 , nested = [RefDO , ArDO ]):
115
127
# SEID v1.1 Table 6-6
116
128
pass
117
129
130
+
118
131
class ResponseAllRefArDO (BER_TLV_IE , tag = 0xff40 , nested = [RefArDO ]):
119
132
# SEID v1.1 Table 4-2
120
133
pass
121
134
135
+
122
136
class ResponseArDO (BER_TLV_IE , tag = 0xff50 , nested = [ArDO ]):
123
137
# SEID v1.1 Table 4-3
124
138
pass
125
139
140
+
126
141
class ResponseRefreshTagDO (BER_TLV_IE , tag = 0xdf20 ):
127
142
# SEID v1.1 Table 4-4
128
143
_construct = Struct ('refresh_tag' / HexAdapter (Bytes (8 )))
129
144
145
+
130
146
class DeviceInterfaceVersionDO (BER_TLV_IE , tag = 0xe6 ):
131
147
# SEID v1.1 Table 6-12
132
148
_construct = Struct ('major' / Int8ub , 'minor' / Int8ub , 'patch' / Int8ub )
133
149
150
+
134
151
class DeviceConfigDO (BER_TLV_IE , tag = 0xe4 , nested = [DeviceInterfaceVersionDO ]):
135
152
# SEID v1.1 Table 6-10
136
153
pass
137
154
155
+
138
156
class ResponseDeviceConfigDO (BER_TLV_IE , tag = 0xff7f , nested = [DeviceConfigDO ]):
139
157
# SEID v1.1 Table 5-14
140
158
pass
141
159
160
+
142
161
class AramConfigDO (BER_TLV_IE , tag = 0xe5 , nested = [DeviceInterfaceVersionDO ]):
143
162
# SEID v1.1 Table 6-11
144
163
pass
145
164
165
+
146
166
class ResponseAramConfigDO (BER_TLV_IE , tag = 0xdf21 , nested = [AramConfigDO ]):
147
167
# SEID v1.1 Table 4-5
148
168
pass
149
169
170
+
150
171
class CommandStoreRefArDO (BER_TLV_IE , tag = 0xf0 , nested = [RefArDO ]):
151
172
# SEID v1.1 Table 5-2
152
173
pass
153
174
175
+
154
176
class CommandDelete (BER_TLV_IE , tag = 0xf1 , nested = [AidRefDO , AidRefEmptyDO , RefDO , RefArDO ]):
155
177
# SEID v1.1 Table 5-4
156
178
pass
157
179
180
+
158
181
class CommandUpdateRefreshTagDO (BER_TLV_IE , tag = 0xf2 ):
159
182
# SEID V1.1 Table 5-6
160
183
pass
161
184
185
+
162
186
class CommandRegisterClientAidsDO (BER_TLV_IE , tag = 0xf7 , nested = [AidRefDO , AidRefEmptyDO ]):
163
187
# SEID v1.1 Table 5-7
164
188
pass
165
189
190
+
166
191
class CommandGet (BER_TLV_IE , tag = 0xf3 , nested = [AidRefDO , AidRefEmptyDO ]):
167
192
# SEID v1.1 Table 5-8
168
193
pass
169
194
195
+
170
196
class CommandGetAll (BER_TLV_IE , tag = 0xf4 ):
171
197
# SEID v1.1 Table 5-9
172
198
pass
173
199
200
+
174
201
class CommandGetClientAidsDO (BER_TLV_IE , tag = 0xf6 ):
175
202
# SEID v1.1 Table 5-10
176
203
pass
177
204
205
+
178
206
class CommandGetNext (BER_TLV_IE , tag = 0xf5 ):
179
207
# SEID v1.1 Table 5-11
180
208
pass
181
209
210
+
182
211
class CommandGetDeviceConfigDO (BER_TLV_IE , tag = 0xf8 ):
183
212
# SEID v1.1 Table 5-12
184
213
pass
185
214
215
+
186
216
class ResponseAracAidDO (BER_TLV_IE , tag = 0xff70 , nested = [AidRefDO , AidRefEmptyDO ]):
187
217
# SEID v1.1 Table 5-13
188
218
pass
189
219
220
+
190
221
class BlockDO (BER_TLV_IE , tag = 0xe7 ):
191
222
# SEID v1.1 Table 6-13
192
223
_construct = Struct ('offset' / Int16ub , 'length' / Int8ub )
@@ -197,11 +228,15 @@ class GetCommandDoCollection(TLV_IE_Collection, nested=[RefDO, DeviceConfigDO]):
197
228
pass
198
229
199
230
# SEID v1.1 Table 4-2
231
+
232
+
200
233
class GetResponseDoCollection (TLV_IE_Collection , nested = [ResponseAllRefArDO , ResponseArDO ,
201
234
ResponseRefreshTagDO , ResponseAramConfigDO ]):
202
235
pass
203
236
204
237
# SEID v1.1 Table 5-1
238
+
239
+
205
240
class StoreCommandDoCollection (TLV_IE_Collection ,
206
241
nested = [BlockDO , CommandStoreRefArDO , CommandDelete ,
207
242
CommandUpdateRefreshTagDO , CommandRegisterClientAidsDO ,
@@ -215,6 +250,7 @@ class StoreResponseDoCollection(TLV_IE_Collection,
215
250
nested = [ResponseAllRefArDO , ResponseAracAidDO , ResponseDeviceConfigDO ]):
216
251
pass
217
252
253
+
218
254
class ADF_ARAM (CardADF ):
219
255
def __init__ (self , aid = 'a00000015141434c00' , name = 'ADF.ARA-M' , fid = None , sfid = None ,
220
256
desc = 'ARA-M Application' ):
@@ -224,7 +260,7 @@ def __init__(self, aid='a00000015141434c00', name='ADF.ARA-M', fid=None, sfid=No
224
260
self .add_files (files )
225
261
226
262
@staticmethod
227
- def xceive_apdu_tlv (tp , hdr :Hexstr , cmd_do , resp_cls , exp_sw = '9000' ):
263
+ def xceive_apdu_tlv (tp , hdr : Hexstr , cmd_do , resp_cls , exp_sw = '9000' ):
228
264
"""Transceive an APDU with the card, transparently encoding the command data from TLV
229
265
and decoding the response data tlv."""
230
266
if cmd_do :
@@ -259,7 +295,8 @@ def get_all(tp):
259
295
@staticmethod
260
296
def get_config (tp , v_major = 0 , v_minor = 0 , v_patch = 1 ):
261
297
cmd_do = DeviceConfigDO ()
262
- cmd_do .from_dict ([{'DeviceInterfaceVersionDO' : {'major' : v_major , 'minor' : v_minor , 'patch' : v_patch }}])
298
+ cmd_do .from_dict ([{'DeviceInterfaceVersionDO' : {
299
+ 'major' : v_major , 'minor' : v_minor , 'patch' : v_patch }}])
263
300
return ADF_ARAM .xceive_apdu_tlv (tp , '80cadf21' , cmd_do , ResponseAramConfigDO )
264
301
265
302
@with_default_category ('Application-Specific Commands' )
@@ -281,20 +318,30 @@ def do_aram_get_config(self, opts):
281
318
282
319
store_ref_ar_do_parse = argparse .ArgumentParser ()
283
320
# REF-DO
284
- store_ref_ar_do_parse .add_argument ('--device-app-id' , required = True , help = 'Identifies the specific device application that the rule appplies to. Hash of Certificate of Application Provider, or UUID. (20/32 hex bytes)' )
321
+ store_ref_ar_do_parse .add_argument (
322
+ '--device-app-id' , required = True , help = 'Identifies the specific device application that the rule appplies to. Hash of Certificate of Application Provider, or UUID. (20/32 hex bytes)' )
285
323
aid_grp = store_ref_ar_do_parse .add_mutually_exclusive_group ()
286
- aid_grp .add_argument ('--aid' , help = 'Identifies the specific SE application for which rules are to be stored. Can be a partial AID, containing for example only the RID. (5-16 hex bytes)' )
287
- aid_grp .add_argument ('--aid-empty' , action = 'store_true' , help = 'No specific SE application, applies to all applications' )
288
- store_ref_ar_do_parse .add_argument ('--pkg-ref' , help = 'Full Android Java package name (up to 127 chars ASCII)' )
324
+ aid_grp .add_argument (
325
+ '--aid' , help = 'Identifies the specific SE application for which rules are to be stored. Can be a partial AID, containing for example only the RID. (5-16 hex bytes)' )
326
+ aid_grp .add_argument ('--aid-empty' , action = 'store_true' ,
327
+ help = 'No specific SE application, applies to all applications' )
328
+ store_ref_ar_do_parse .add_argument (
329
+ '--pkg-ref' , help = 'Full Android Java package name (up to 127 chars ASCII)' )
289
330
# AR-DO
290
331
apdu_grp = store_ref_ar_do_parse .add_mutually_exclusive_group ()
291
- apdu_grp .add_argument ('--apdu-never' , action = 'store_true' , help = 'APDU access is not allowed' )
292
- apdu_grp .add_argument ('--apdu-always' , action = 'store_true' , help = 'APDU access is allowed' )
293
- apdu_grp .add_argument ('--apdu-filter' , help = 'APDU filter: 4 byte CLA/INS/P1/P2 followed by 4 byte mask (8 hex bytes)' )
332
+ apdu_grp .add_argument (
333
+ '--apdu-never' , action = 'store_true' , help = 'APDU access is not allowed' )
334
+ apdu_grp .add_argument (
335
+ '--apdu-always' , action = 'store_true' , help = 'APDU access is allowed' )
336
+ apdu_grp .add_argument (
337
+ '--apdu-filter' , help = 'APDU filter: 4 byte CLA/INS/P1/P2 followed by 4 byte mask (8 hex bytes)' )
294
338
nfc_grp = store_ref_ar_do_parse .add_mutually_exclusive_group ()
295
- nfc_grp .add_argument ('--nfc-always' , action = 'store_true' , help = 'NFC event access is allowed' )
296
- nfc_grp .add_argument ('--nfc-never' , action = 'store_true' , help = 'NFC event access is not allowed' )
297
- store_ref_ar_do_parse .add_argument ('--android-permissions' , help = 'Android UICC Carrier Privilege Permissions (8 hex bytes)' )
339
+ nfc_grp .add_argument ('--nfc-always' , action = 'store_true' ,
340
+ help = 'NFC event access is allowed' )
341
+ nfc_grp .add_argument ('--nfc-never' , action = 'store_true' ,
342
+ help = 'NFC event access is not allowed' )
343
+ store_ref_ar_do_parse .add_argument (
344
+ '--android-permissions' , help = 'Android UICC Carrier Privilege Permissions (8 hex bytes)' )
298
345
299
346
@cmd2 .with_argparser (store_ref_ar_do_parse )
300
347
def do_aram_store_ref_ar_do (self , opts ):
@@ -323,7 +370,7 @@ def do_aram_store_ref_ar_do(self, opts):
323
370
ar_do_content += [{'NfcArDO' : {'nfc_event_access_rule' : 'never' }}]
324
371
if opts .android_permissions :
325
372
ar_do_content += [{'PermArDO' : {'permissions' : opts .android_permissions }}]
326
- d = [{'RefArDO' : [{ 'RefDO' : ref_do_content }, {'ArDO' : ar_do_content }]}]
373
+ d = [{'RefArDO' : [{'RefDO' : ref_do_content }, {'ArDO' : ar_do_content }]}]
327
374
csrado = CommandStoreRefArDO ()
328
375
csrado .from_dict (d )
329
376
res_do = ADF_ARAM .store_data (self ._cmd .card ._scc ._tp , csrado )
@@ -359,6 +406,7 @@ def do_aram_delete_all(self, opts):
359
406
}
360
407
}
361
408
409
+
362
410
class CardApplicationARAM (CardApplication ):
363
411
def __init__ (self ):
364
- super ().__init__ ('ARA-M' , adf = ADF_ARAM (), sw = sw_aram )
412
+ super ().__init__ ('ARA-M' , adf = ADF_ARAM (), sw = sw_aram )
0 commit comments