ZjPTdZddlmZmZmZmZmZddlmZddl Tddl Tddl m Z ddl TddlZGdded ZGd d ed ZGdded ZGdded ZGddedeeeegZGdded ZGdded ZGdded ZGd!d"ed#eeegZGd$d%ed&eegZGd'd(ed)egZGd*d+ed,egZGd-d.ed/ ZGd0d1ed2 ZGd3d4ed5egZGd6d7ed8egZ 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.eegbZ/Gdcdde.eeee"gbZ0Gdedfe.e-e#e$e%e&e'e(e)e*e+g bZ1Gdgdhe.ee,e gbZ2Gdidje3Z4dkdldmdndodpdqdrdsdtdudvdwdxdydzd{iZ5Gd|d}e6Z7dS)~zW Support for the Secure Element Access Control, specifically the ARA-M inside an UICC. ) GreedyStringStructEnumInt8ubInt16ub)Optional)*)HexstrNc$eZdZeeZdS)AidRefDON__name__ __module__ __qualname__ HexAdapter GreedyBytes _constructA/home/jenkins/jenkins/workspace/simtester-sanitize/pySim/ara_m.pyr r (K((JJJrr O)tagceZdZdS) AidRefEmptyDONrrrrrrrr-Drrc$eZdZeeZdS) DevAppIdRefDONr rrrr 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|_|jStdt|dzrtdt|zd 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@ |#FGG G2ww{ ] !QTWXZT[T[![\\\)2.DLF3r77"" ]+++3r&PQ/?R;S;S8;Bvaxq?Pfiltersresfheader_bmask_bs r _to_byteszApduArDO._to_bytesWs DL 0 0|12g==w|12h>>wFGG G DL00 !5666l=1GC ) )1}}FaKK$%OPPPq{++QvYx==A%%V)9)9$%WXXXx&((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)StoreResponseDoCollectionNrrrrrrrrrc&eZdZ dfd ZdZed defd Zed efd Z ed Z ed!dZ edede dede dede de de de defdZedZedGddeZxZS)"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|SN)pySimglobal_platformdecode_select_response)r>data_hexs rrzADF_ARAM.decode_select_responses$;;HEEEr9000hdrcN|r9|}t|}|dkrtdnd}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 !CDDD 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''ZAUVVVrr aid_empty device_app_idpkg_refr5 apdu_never apdu_always nfc_always nfc_neverandroid_permissionsc g} | | d|igz } n |r| ddigz } | d|igz } |r | dd|iigz } g} |r | dddiigz } n|r | ddd iigz } n|rt|d zrtd t|d } g}| t|kr:||| | d z|| d z| d zdgz }| d z } | t|k:| dd|iigz } | r | dddiigz } n |r | ddd iigz } | r | dd| iigz } dd| id| igig}t}||t||S)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: rr4r7r5 nfc_ar_dorO perm_ar_dorS ref_ar_doref_doar_do)r:r<rurrr)rrrrrr5rrrrrref_do_content ar_do_contentr?apdu_filter_listdcsrados rstore_ref_ar_dozADF_ARAM.store_ref_ar_do/sJ  ?  c23 3NN  ;  2D9: :N/?@@  Q  /Dg.NOP PN  Q |.CW-MNO OMM  Q |.CX-NOP PMM  Q;"$ e !cQTU`QaQa!c!cdddF! 3{++++ F6!8O0L.9&(6"9:L.M&O&O%PP " 3{++++ |m=M-NOP PM  R {-Dg,NOP PMM  R {-Dh,OPQ QM  T |m=P-QRS SMX~6-8PQ R S$&&Q""3///rcTt}t||Sr)rxrr)rdeldos raram_delete_allzADF_ARAM.aram_delete_allWs!""3...rzApplication-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 edZdZdZdS) 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_all^sT%%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_configdsT(()<==F 9 &&v~~'7'788888 9 9rz--device-app-idTzIdentifies the specific device application that the rule applies 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-neverzNFC event access is not allowedz --nfc-alwayszNFC event access is allowedz--android-permissionsz8Android UICC Carrier Privilege Permissions (8 hex bytes)c 0t|jjj|j|j|j|j|j |j |j |j |j |j }|r.|j|dSdS)zJPerform STORE DATA [Command-Store-REF-AR-DO] to store a (new) access rule.N)rrrrrrrrrr5rrrrrrr)r>optsrs rdo_aram_store_ref_ar_doz2ADF_ARAM.AddlShellCommands.do_aram_store_ref_ar_dos--dio.A48T^]a]o.2lDrs r do_aram_lockz'ADF_ARAM.AddlShellCommands.do_aram_locks' IO  1 1.& I I I I IrN)rrrrrargparseArgumentParserstore_ref_ar_do_parse add_argumentadd_mutually_exclusive_groupaid_grpapdu_grpnfc_grpcmd2with_argparserrrr rrrrr\sT 9 9 9  9 9 9 !) 7 7 9 9** 4B + C C C'DDFF v  w w w]<"y  { { {** V + X X X)EEGG <6R  T T T L7O  Q Q Q "~  @ @ @'DDFF]<"C  E E E^L"?  A A A** #*d + f f f   2 3 3 9 9 4 3 9 9 9 9  J J J J Jrr)rrNNr)r)rrr/)rrrrr staticmethodr rrKrrrboolstrrrwith_default_category CommandSetr __classcell__rs@rrrsRV)FFF&\,XuXXX\XXX\XWWW\W %0%04%0v%0WZ%0$*%07;%0IM%0#'%037%0MS%0%0%0\%0N//\/:;;:J:J:J:J:JJ:J:J<;:J:J:J:J:JrrARA-Mz:Rule successfully stored but an access rule already existszORule successfully stored but 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)Nr4rrrrrrrrrraram_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_dictlistr5r:) 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  Ts rexportzCardApplicationARAM.exports  ^%&\]] ] )) !!%),, &##%% %!>>++ Z ZK??#;UCC "-.F"G Z Z1II.YYY  Z!!!r) rrrrrr=rHrrJrrs@rr.r.s>>>>>  \ ))\)V""""\"""""rr.)8__doc__ constructrrrrrr COptionalosmocom.construct osmocom.tlv osmocom.utilsr pySim.filesystempySim.global_platformr BER_TLV_IEr rr r#r(r,rNrRrXr[r^r`rbrerkrnrprsrurxr{r~rrrrrrrTLV_IE_CollectionrrrrCardADFrr2CardApplicationr.rrrrWsO,BAAAAAAAAAAAAA++++++  )))))zt))))      JD    )))))JD)))) EEEEEztEEEE      JD(M=RZ)[    *****zt****Z99999jd9999 <<<<