)gMXdZddlmZmZmZmZmZmZddlmZ ddl Tddl Tddl m Z ddlTddlZGdded ZGd d ed ZGdded ZGdded ZGddedeeeegZGdded ZGdded ZGdded ZGd!d"ed#eeegZGd$d%ed&eegZGd'd(ed)egZGd*d+ed,egZGd-d.ed/ ZGd0d1ed2 ZGd3d4ed5egZ Gd6d7ed8e gZ!Gd9d:ed;egZ"Gd<d=ed>e"gZ#Gd?d@edAegZ$GdBdCedDeeeegZ%GdEdFedG Z&GdHdIedJeegZ'GdKdLedMeegZ(GdNdOedP Z)GdQdRedS Z*GdTdUedV Z+GdWdXedY Z,GdZd[ed\eegZ-Gd]d^ed_ Z.Gd`dae/ee gbZ0Gdcdde/eeee#gbZ1Gdedfe/e.e$e%e&e'e(e)e*e+e,g bZ2Gdgdhe/ee-e!gbZ3Gdidje4Z5dkdldmdndodpdqdrdsdtdudvdwdxdydzd{iZ6Gd|d}e7Z8dS)~zW Support for the Secure Element Access Control, specifically the ARA-M inside an UICC. ) GreedyBytes GreedyStringStructEnumInt8ubInt16ub)Optional)*)HexstrNc$eZdZeeZdS)AidRefDON__name__ __module__ __qualname__ HexAdapterr _construct9/home/jenkins/workspace/simtester-sanitize/pySim/ara_m.pyr r (K((JJJrr O)tagceZdZdS) AidRefEmptyDONrrrrrrrr-Drrc$eZdZeeZdS) DevAppIdRefDONrrrrr r 2rrr c<eZdZededz ZdS)PkgRefDOpackage_name_stringasciiN)rrrrrrrrrr#r#7s--ll7.C.CCDDJJJrr#ceZdZdS)RefDONrrrrr(r(<rrr()rnestedc eZdZdefdZdZdS)ApduArDOdoc *t|dkrG|ddkrddi|_|jS|ddkrddi|_|jStdSt|dzrtdt|zSd gi|_d}|t|krd|jd xxt|||d zt||d z|dzd gz cc<|dz }|t|kd|jS) Nrgeneric_access_ruleneveralways'Invalid 1-byte generic APDU access rulez.Invalid non-modulo-8 length of APDU filter: %d apdu_filterheadermask)lendecoded ValueErrorb2h)selfr-offsets r _from_byteszApduArDO._from_bytesCsA r77a<<!u}} 5w? |#!u}} 5x@ |#GHH H2ww{ ^!"RUXY[U\U\"\]]])2.DLF3r77"" ]+++3r&PQ/?R;S;S8;Bvaxq?Pfiltersresfheader_bmask_bs r _to_byteszApduArDO._to_bytesWs DL 0 0|12g==w|12h>>wGHH H DL00!"6777l=1GC ) )1}}FaKK%&PQQQQQq{++QvYx==A%%V)9)9%&XYYYYYx&((JrN)rrrbytesr@rJrrrr,r,As> e    (rr,cBeZdZedeeddz ZdS)NfcArDOnfc_event_access_rulerr/)r1r2N)rrrrrrrrrrrNrNns;/V1Q777899JJJrrNcNeZdZedeedz ZdS)PermArDO permissionsr4NrrrrrBytesrrrrrRrRts6 jjq&:&::;;JJJrrRceZdZdS)ArDONrrrrrXrXzrrrXceZdZdS)RefArDONrrrrr[r[rrr[ceZdZdS)ResponseAllRefArDONrrrrr^r^rrr^i@ceZdZdS) ResponseArDONrrrrr`r`rrr`iPcNeZdZedeedz ZdS)ResponseRefreshTagDO refresh_tagr4NrTrrrrbrbs4 jjq&:&::;;JJJrrbi c:eZdZedez dez dez ZdS)DeviceInterfaceVersionDOmajorminorpatchN)rrrrrrrrrreres-GGJJJrreceZdZdS)DeviceConfigDONrrrrrkrkrrrkceZdZdS)ResponseDeviceConfigDONrrrrrnrnrrrniceZdZdS) AramConfigDONrrrrrprprrrpceZdZdS)ResponseAramConfigDONrrrrrsrsrrrsi!ceZdZdS)CommandStoreRefArDONrrrrrururrruceZdZdS) CommandDeleteNrrrrrxrxrrrxceZdZdS)CommandUpdateRefreshTagDONrrrrr{r{rrr{ceZdZdS)CommandRegisterClientAidsDONrrrrr~r~rrr~ceZdZdS) CommandGetNrrrrrrrrrceZdZdS) CommandGetAllNrrrrrrrrrceZdZdS)CommandGetClientAidsDONrrrrrrrrrceZdZdS)CommandGetNextNrrrrrrrrrceZdZdS)CommandGetDeviceConfigDONrrrrrrrrrceZdZdS)ResponseAracAidDONrrrrrrrrripc2eZdZedez dez ZdS)BlockDOr?lengthN)rrrrrrrrrrrrs(((6/::JJJrrceZdZdS)GetCommandDoCollectionNrrrrrrsDrr)r*ceZdZdS)GetResponseDoCollectionNrrrrrrrrrceZdZdS)StoreCommandDoCollectionNrrrrrrs  DrrceZdZdS)StoreResponseDoCollectionNrrrrrrrrrceZdZ dfd ZdZeddefd Zed efd Z ed Z eddZ e dGdde ZxZS)ADF_ARAMa00000015141434c00 ADF.ARA-MNARA-M Applicationct||||||xj|gz c_g}||dS)N)aidfidsfidnamedesc)super__init__shell_commandsAddlShellCommands add_files)r>rrrrrfiles __class__s rrzADF_ARAM.__init__sf Sc4dKKK  6 6 8 899 urc@tj|S)N)pySimglobal_platformdecode_select_response)r>data_hexs rrzADF_ARAM.decode_select_responses$;;HEEEr9000hdrcN|r9|}t|}|dkrtdSnd}d}|d|zzt|z}|||\}} |r2|r.|} | t || S|SdS)z~Transceive an APDU with the card, transparently encoding the command data from TLV and decoding the response data tlv.z DO > 255 bytes not supported yetrrz%02xN)to_ier:r<r=send_apdu_checkswfrom_tlvrD) sccrcmd_doresp_clsexp_sw cmd_do_enc cmd_do_lenc_apdudata_swresp_dos rxceive_apdu_tlvzADF_ARAM.xceive_apdu_tlvs  JZJC!"DEEE JJ+,s:>++FF;; s   "(**  T+++K4rreturncFt|d|tS)z&Build the Command APDU for STORE DATA.80e29000)rrr)rr-s r store_datazADF_ARAM.store_datas''Z=VWWWrcFt|ddtS)N80caff40)rrr)rs rget_allzADF_ARAM.get_all$s''Z?VWWWrrr/ct}|d|||digt|d|tS)Ndevice_interface_version_do)rfrgrh80cadf21)rk from_val_dictrrrs)rv_majorv_minorv_patchrs r get_configzADF_ARAM.get_config(se!!<(/'G?U?UVW X X X''ZAUVVVrzApplication-Specific CommandsceZdZdZdZeZeddde Z e dd e d d d edd e Z e dd d e dd d e dd e Z e dd d e dd d edd e edZdZdS)ADF_ARAM.AddlShellCommandsct|jjj}|r.|j|dSdS)z"GET DATA [All] on the ARA-M AppletN)rr_cmdlchanr poutput_jsonto_dictr>_optsres_dos rdo_aram_get_allz*ADF_ARAM.AddlShellCommands.do_aram_get_all1sT%%dio&9::F 9 &&v~~'7'788888 9 9rct|jjj}|r.|j|dSdS)z\Perform GET DATA [Config] on the ARA-M Applet: Tell it our version and retrieve its version.N)rrrrrrrrs rdo_aram_get_configz-ADF_ARAM.AddlShellCommands.do_aram_get_config7sT(()<==F 9 &&v~~'7'788888 9 9rz--device-app-idTzIdentifies the specific device application that the rule appplies to. Hash of Certificate of Application Provider, or UUID. (20/32 hex bytes))requiredhelpz--aidzIdentifies the specific SE application for which rules are to be stored. Can be a partial AID, containing for example only the RID. (5-16 or 0 hex bytes))rz --aid-empty store_truezUNo specific SE application, applies to implicitly selected application (all channels))actionrz --pkg-refz6Full Android Java package name (up to 127 chars ASCII)z --apdu-neverzAPDU access is not allowedz --apdu-alwayszAPDU access is allowedz --apdu-filterzZAPDU filter: multiple groups of 8 hex bytes (4 byte CLA/INS/P1/P2 followed by 4 byte mask)z --nfc-alwayszNFC event access is allowedz --nfc-neverzNFC event access is not allowedz--android-permissionsz8Android UICC Carrier Privilege Permissions (8 hex bytes)cg}|j|d|jigz }n|jr|ddigz }|d|jigz }|jr|dd|jiigz }g}|jr |ddd iigz }n|jr |ddd iigz }n|jrt|jd zr$td ttzSd }g}|t|jkrI||j||dz|j|dz|d zdgz }|d z }|t|jkI|dd|iigz }|j r |ddd iigz }n|j r |ddd iigz }|j r|dd|j iigz }dd|id|igig}t}||t|jjj|}|r.|j|dSdS)zJPerform STORE DATA [Command-Store-REF-AR-DO] to store a (new) access rule.N aid_ref_doaid_ref_empty_dodev_app_id_ref_do pkg_ref_dor$ apdu_ar_dor0r1r2z/Invalid non-modulo-16 length of APDU filter: %drr4r7r5 nfc_ar_dorO perm_ar_dorS ref_ar_doref_doar_do)r aid_empty device_app_idpkg_ref apdu_never apdu_alwaysr5r:r<r- nfc_always nfc_neverandroid_permissionsrurrrrrrrr) r>optsref_do_content ar_do_contentr?r5dcsradors rdo_aram_store_ref_ar_doz2ADF_ARAM.AddlShellCommands.do_aram_store_ref_ar_doXs Nx#L$(#;"<< ?$6#=">>  3T5GHI IN| ZL3H$,2W#X"YYM P<2G1Q"R!SS ! P<2G1R"S!TT ! Pt'((2-c%&WZ]^`ZaZa&abbb s4#34444t/?vax/P-1-=fQhvby>P-Q%S%S$TTKbLFs4#34444<-1M"N!OO  U;1H(0S"T!UU  U;1H'0R"S!TT ' ]<-AY1Z"[!\\ > :Wmrdeldors rdo_aram_delete_allz-ADF_ARAM.AddlShellCommands.do_aram_delete_alls_!OOE(()RV)FFF&\,XuXXX\XXX\XWWW\W :;;V9V9V9V9V9JV9V9<;V9V9V9V9V9rrARA-Mz:Rule successfully stored but an access rule already existszNRule successfully stored bu contained at least one unknown (discarded) BER-TLVzMemory ProblemzWrong Length in Lcz&DO is not supported by the ARA-M/ARA-CzSecurity status not satisfiedzHRules have been updated and must be read again / logical channels in usezConditions not satisfiedz$Incorrect values in the command dataz.Rules have been updated and must be read againzIncorrect P1 P2zReferenced data not foundzrs rrzCardApplicationARAM.__init__s, hjjW=====rc\|dS|D]$}||vr||}|dS|cS%dS)N)get)keydictlistrobjs r__export_get_from_dictlistz.CardApplicationARAM.__export_get_from_dictlistsW  4  AaxxeeCjj;22  trcd}td|d}td|d}|ru|rrtd|}td|}td|}td|}td |}td |} td |} |d z }|t|d kr |d|zz }n||dz }||dz }|r|d|zz }|rd|vr|d|dzz }n,|r*d|vr&|dz }|dD]} || dz }|| dz }| rd| vr|d| dzz }| r|d| dzz }|r|d|dzz }|dz }|S)Nr)rrrrrrrrrraram_store_ref_ar_dorz --aid %sz --aid ""z --aid-emptyz --device-app-id %sr0z --apdu-%sr5z --apdu-filter r8r9rOz --nfc-%sz --android-permissions %srSz --pkg-ref %sr$ )r#._CardApplicationARAM__export_get_from_dictlistr*r:) ref_ar_do_list export_str ref_do_list ar_do_listrrrrrrrr5s r__export_ref_ar_do_listz+CardApplicationARAM.__export_ref_ar_do_lists\ )DDX~OaOabmOnOnoo (CCG^M_M_`kMlMlmm # :# ,GG VabbJ2MMN`bmnn  3 N NObdo p p ,GG VabbJ-GG V`aaJ+FF{T^__I,GG V`aaJ 0 0J%#j//A*=*={Z78 'm+ +n,   J47HHI  63zAA|j9N.OOP  6  ; ;01 #-m#<66K+h"77J+f"55JJ Q4 AA{Y7N-OOP  X:Z =VVW  T>++ Z ZK??#;UCC "-.F"G Z Z1II.YYY  Z!!!r) rrrrr r2r=boolr?rrs@rr#r#s>>>>>  \ ))\)V""""\"""""rr#)9__doc__ constructrrrrrrr COptionalosmocom.construct osmocom.tlv osmocom.utilsr pySim.filesystempySim.global_platformr BER_TLV_IEr rr r#r(r,rNrRrXr[r^r`rbrerkrnrprsrurxr{r~rrrrrrrTLV_IE_CollectionrrrrCardADFrr'CardApplicationr#rrrrMsM,ONNNNNNNNNNNNNNN++++++  )))))zt))))      JD    )))))JD)))) EEEEEztEEEE      JD(M=RZ)[    *****zt****Z99999jd9999 <<<<