*gl*dZddlZddlmZmZmZmZddlmZmZm Z ddl m Z ddl Tddl TddlmZddlm Z mZmZdd lmZdd lmZddlZGd d ed ZejjjedefdZ de!fdZ"Gdde#Z$e$ede%Z&dZ'dZ(dZ)dZ*GddedZ+Gddede+gZ,Gd d!ed"ejj-e,gzZ.Gd#d$ed%Z/Gd&d'ed(Z0Gd)d*ed+e/e0gZ1Gd,d-ed%Z2Gd.d/ed0e/e2gZ3Gd1d2ed%Z4Gd3d4ed5e4gZ5Gd6d7edZ6Gd8d9ed:Z7Gd;dd?ed@e7gZ9GdAdBedCe6e8e9gZ:GdDdEed(Z;GdFdGedHZ<GdIdJedKZ=GdLdMedNZ>GdOdPedQZ?GdRdSedTZ@GdUdVedWZAGdXdYedZZBGd[d\ed:ZCGd]d^ed_ZDGd`daedbZEGdcdded%ZFGdedfedgeFgZGGdhdiedjeGgZHGdkdledme;e6ee?e@eAe8e9eBeCeDeEeHgZIGdndoed(ZJGdpdqedreJgZKGdsdted%ZLGdudved_ZMGdwdxed ZNGdydzed{eLeJeMeNgZOGd|d}edgeOgZPGd~ded(ZQGddedrePeQgZRGdded%ZSGddedeLgZTGddedeSgZUGddedgZVGddedZWGddedeWgZXGddedZYGddedZZGddedbZ[GddedZ\GddedZ]GddedZ^GddedjZ_GddedZ`GddedeNeYeZe[e\e]e^e_e`g ZaGddedgeagZbGdded(ZcGddedebecgZdGdded(ZeGdded%ZfGddedgeYeNgZgGddedegeegZhGddedefgZiGdded%ZjGddedegeegZkGddedejgZlGdÄded%ZmGdńdedeYeNgZnGdȄdedemgZoGdʄded ZpGd̄dedeWepgZqGdτdedѬZrGd҄dedeNergZsGdՄded%ZtGdׄdedetgZuGdلded۬ZvGd܄dedެZwGd߄dedZxGdded(ZyGddedewexeygZzGdded%Z{Gdded(Z|GddedZ}GddedHZ~GddedKZGddedTZGdded%e{e|e}e~eegZGddedgegZGddedegZGddejjZGddejjZGddeZGddeZGddeZdS(z Various definitions related to GSMA consumer + IoT eSIM / eUICC Does *not* implement anything related to M2M eUICC Related Specs: GSMA SGP.21, SGP.22, SGP.31, SGP32 N)ArrayStruct FlagsEnum GreedyRange)cmd2 CommandSetwith_default_category)Hexstr)*) SwMatchError)r SwHexstr SwMatchstr)SimCardCommands)CardProfileUICCc$eZdZeeZdS)Sgp02EidN__name__ __module__ __qualname__ BcdAdapter GreedyBytes _construct9/home/jenkins/workspace/simtester-sanitize/pySim/euicc.pyrr)K((JJJrrZ)tagreturnc^t|trYt|dkr|dz }n0t|dkr|dddz}ntdt |}n$t|tr|}|dzr||dzz}d|d zz }||z }t|S) zYCompute and add/replace check digits of an EID value according to GSMA SGP.29 Section 10.00 Nzand EID must be 30 or 32 digitsdba) isinstancestrlen ValueErrorint)eideid_intcsums rcompute_eid_checksumr1/s#s% s88r>> 4KCC XX^^crc(T/CC>?? ?c(( C  % S= % w} $G 2 D tOG w<<rc.t|dzdkS)zLVerify the check digits of an EID value according to GSMA SGP.29 Section 10.r(r-)r.s rverify_eid_checksumr5Gs s88b=A rceZdZdZdZdZdS)VersionAdapterzCconvert an EUICC Version (3-int array) to a textual representation.c6d|d|d|dfzS)Nz%u.%u.%urr3rselfobjcontextpaths r_decodezVersionAdapter._decodePs SVSVSV444rc@d|dDS)Nc,g|]}t|Srr4).0xs r z*VersionAdapter._encode..Ts///1A///r.)splitr:s r_encodezVersionAdapter._encodeSs // #////rN)rrr__doc__r?rGrrrr7r7Ms8MM55500000rr7 A0000005591010FFFFFFFF8900000100 A0000005591010FFFFFFFF8900000200 A0000005591010FFFFFFFF8900000D00 A0000005591010FFFFFFFF8900000E00ceZdZeZdS)SupportedVersionNumberNrrrrrrrrrOrO^JJJrrOceZdZdS)"IsdrProprietaryApplicationTemplateNrrrrrrrTrTaDrrT)rnestedceZdZdS) FciTemplateNrUrrrrZrZfrVrrZoc$eZdZeeZdS)DefaultDpAddressNrrr Utf8Adapterrrrrrr]r]l[))JJJrr]c$eZdZeeZdS) RootDsAddressNr^rrrrcrcnr`rrcceZdZdS)EuiccConfiguredAddressesNrUrrrrfrfpDrrfi<c*eZdZeeddZdS)SetDefaultDpAddrResr)okundefinedErrorNrrrEnumInt8ubrrrrririts$f3777JJJrriceZdZdS)SetDefaultDpAddressNrUrrrrqrqvrgrrqi?c6eZdZeedZdS)EuiccChallengeN)rrr HexAdapterBytesrrrrrsrszs%EE"II&&JJJrrsceZdZdS)GetEuiccChallengeNrUrrrrxrx|rgrrxi.ceZdZeZdS)SVNNrrr VersionTyperrrrrzrzrQrrzc$eZdZeeZdS)SubjectKeyIdentifierNrrrrurrrrrr~r~rrr~ceZdZdS)EuiccCiPkiListForVerificationNrUrrrrrrgrrceZdZdS)EuiccCiPkiListForSigningNrUrrrrrrgrrceZdZdS) EuiccInfo1NrUrrrrrrgrri ceZdZeZdS)ProfileVersionNr{rrrrrrQrrceZdZeZdS)EuiccFirmwareVerNr{rrrrrrQrrc$eZdZeeZdS)ExtCardResourceNrrrrrrrrrc$eZdZeeZdS)UiccCapabilityNrrrrrrrrrceZdZeZdS)TS102241VersionNr{rrrrrrQrrceZdZeZdS)GlobalPlatformVersionNr{rrrrrrQrrc$eZdZeeZdS) RspCapabilityNrrrrrrrrrc.eZdZeeddddZdS) EuiccCategoryrr3r9rI)other basicEuicc mediumEuicccontactlessEuiccNrmrrrrrs)fA!UVWWWJJJrrceZdZeZdS) PpVersionNr{rrrrrrQrrc$eZdZeeZdS)SsAcreditationNumberNr^rrrrrr`rr c*eZdZeeddZdS)IpaModerr3)ipadipeaNrmrrrrrs$f11---JJJrrceZdZeZdS) IotVersionNr{rrrrrrQrrceZdZdS) IotVersionSeqNrUrrrrrrgrrceZdZdS)IotSpecificInfoNrUrrrrrrgrrceZdZdS) EuiccInfo2NrUrrrrrs  Drri"c HeZdZeedeeddddz ZdS)ProfileMgmtOperationpmora@r$rt)installenabledisabledeleteN)rrrrByterrrrrrrs;eIIdDW[dh$i$i$iijjJJJrrceZdZdS)ListNotificationReqNrUrrrrrrgrri(c"eZdZeZdS) SeqNumberNrrrAsn1DerIntegerrrrrrr!!JJJrrc$eZdZeeZdS)NotificationAddressNr^rrrrrr`rrc$eZdZeeZdS)IccidNrrrrrrrrrceZdZdS)NotificationMetadataNrUrrrrrrVrri/ceZdZdS)NotificationMetadataListNrUrrrrrrgrrc(eZdZeedZdS)ListNotificationsResultErrorrj)rlNrmrrrrrs"fS111JJJrrceZdZdS)ListNotificationRespNrUrrrrrrVrrc,eZdZeedddZdS)DeleteNotificationStatusrr3rj)rknothingToDeleterlNrmrrrrrs&fAcJJJJJJrrceZdZdS)NotificationSentReqNrUrrrrrrgrri0ceZdZdS)NotificationSentRespNrUrrrrrrgrrceZdZdS)LoadCRLNrUrrrrrrgrri5c$eZdZeeZdS)TagListN)rrrrrorrrrrrsV$$JJJrr\ceZdZdS)ProfileInfoListReqNrUrrrrrrgrri-c$eZdZeeZdS)IsdpAidNrrrrrrrrrOc*eZdZeeddZdS) ProfileStaterr3)disabledenabledNrmrrrrrs$fq!444JJJrripc$eZdZeeZdS)ProfileNicknameNr^rrrrrr`rrc$eZdZeeZdS)ServiceProviderNameNr^rrrrrr`rrc$eZdZeeZdS) ProfileNameNr^rrrrrr`rrc*eZdZeeddZdS)IconTyperr3)jpgpngNrmrrrrrs$f!+++JJJrrceZdZeZdS)IconNrPrrrrrrQrrc,eZdZeedddZdS) ProfileClassrr3r9)test provisioning operationalNrmrrrrrs&f11!DDDJJJrrceZdZdS) ProfileInfoNrUrrrrrs DrrceZdZdS)ProfileInfoSeqNrUrrrrrrgrrc*eZdZeeddZdS)ProfileInfoListErrorr3r9)incorrectInputValuesrlNrmrrrrrs$f1QGGGJJJrrceZdZdS)ProfileInfoListRespNrUrrrrrrgrrceZdZeZdS) RefreshFlagN)rrrrorrrrr r sJJJrr c 4eZdZeedddddddZd S) EnableResultrr3r9rIrrj)rkiccidOrAidNotFoundprofileNotInDisabledStatedisallowedByPolicywrongProfileReenablingcatBusyrlNrmrrrr r s:fqTU)*1a`ceeeJJJrr ceZdZdS)ProfileIdentifierNrUrrrrrrgrrceZdZdS)EnableProfileReqNrUrrrrrrgrri1ceZdZdS)EnableProfileRespNrUrrrrrrgrrc 2eZdZeeddddddZdS) DisableResultrr3r9rIr rj)rkr profileNotInEnabledStaterrrlNrmrrrrrs7fqST)*AcKKKJJJrrceZdZdS)DisableProfileReqNrUrrrrrrgrri2ceZdZdS)DisableProfileRespNrUrrrrrrgrrc0eZdZeedddddZdS) DeleteResultrr3r9rIrj)rkr rrrlNrmrrrr r s5fqTU)*3@@@JJJrr ceZdZdS)DeleteProfileReqNrUrrrr"r" rgrr"i3ceZdZdS)DeleteProfileRespNrUrrrr$r$ rgrr$c$eZdZeeZdS)EidValueNrrrrr&r&rrr&ceZdZdS) GetEuiccDataNrUrrrr(r(rgrr(i>c$eZdZeeZdS)SnrProfileNicknameNr^rrrr*r*r`rr*ceZdZdS)SetNicknameReqNrUrrrr-r-rgrr-i)c,eZdZeedddZdS)SetNicknameResultrr3rj)rk iccidNotFoundrlNrmrrrr/r/s&f!CHHHJJJrr/ceZdZdS)SetNicknameRespNrUrrrr2r2rgrr2ceZdZdS) GetCertsReqNrUrrrr4r4 rgrr4iVceZdZeZdS)EumCertificateNrPrrrr6r6"rQrr6ceZdZeZdS)EuiccCertificateNrPrrrr9r9$rQrr9c*eZdZeeddZdS) GetCertsErrorr3rj) invalidCiPKIdrlNrmrrrr<r<&s$fAcBBBJJJrr<ceZdZdS) GetCertsRespNrUrrrr?r?(rgrr?c$eZdZeeZdS)EimIdNr^rrrrArA,r`rrAc$eZdZeeZdS)EimFqdnNr^rrrrCrC.r`rrCc,eZdZeedddZdS) EimIdTyper3r9rI) eimIdTypeOid eimIdTypeFqdneimIdTypeProprietaryNrmrrrrErE0s'f1ATUVVVJJJrrEc"eZdZeZdS) CounterValueNrrrrrJrJ2rrrJc"eZdZeZdS)AssociationTokenNrrrrrLrL4rrrLc0eZdZeedddddZdS)EimSupportedProtocolrr3r9rIr)eimRetrieveHttpseimRetrieveCoapseimInjectHttpseimInjectCoapseimProprietaryNrmrrrrNrN6s3fq1UVgh%&(((JJJrrNceZdZdS)EimConfigurationDataNrUrrrrUrU:rVrrUceZdZdS)EimConfigurationDataSeqNrUrrrrWrW=rgrrWceZdZdS)GetEimConfigurationDataNrUrrrrYrY?rgrrYiUc eZdZfdZeddedededeee ffdZ eddedefdZ edede fd Z d edefd Zed Gd deZxZS)CardApplicationISDRctdtd|j|j_|jxj|gz c_d|j_dS)Nz ADF.ISD-Rz/ISD-R (Issuer Security Domain Root) ApplicationnameaiddescEID)super__init__ AID_ISD_Rdecode_select_responseadfshell_commandsAddlShellCommandsscp_key_identityr; __class__s rrczCardApplicationISDR.__init__Csp kyO  Q Q Q*.*E' D$:$:$<$<#==$)!!!r9000scctx_doexp_swr c\dt|dz|fz}|||S)zzPerform STORE DATA according to Table 47+48 in Section 5.7.2 of SGP.22. Only single-block store supported for now.z80E29100%02x%s00r9)r+send_apdu_checksw)rmrnrocapdus r store_datazCardApplicationISDR.store_dataKs3#c%jj!mU%;;$$UF333rcB|r9|}t|}|dkrtdSnd}t|t ||\}}|r2|r.|}|t||S|SdS)zTransceive STORE DATA APDU with the card, transparently encoding the command data from TLV and decoding the response data tlv.z DO > 255 bytes not supported yetr)roN)to_tlvr+r,r[rsb2hfrom_tlvh2b) rmcmd_doresp_clsro cmd_do_enc cmd_do_lendata_swresp_dos rstore_data_tlvz"CardApplicationISDR.store_data_tlvRs  JZJC!"DEEE J)44S#j//RX4YY s   "(**  T+++ 4rcttdgg}t||t}|}t |ddS)Nrdecodedchildrenget_euicc_data eid_value)r(rr[rto_dictflatten_dict_lists)rmged_cmdgedds rget_eidzCardApplicationISDR.get_eidhs_$)@)@)@(ABBB!00g|LL KKMM!!$4"566{CCrdata_hexct}|t||}t |dSN fci_templaterZrxryrrr;rtrs rrez*CardApplicationISDR.decode_select_responseoC MM 3x==!!! IIKK!!N"3444rApplication-Specific CommandscHeZdZejZeddejedZ dZ ejZ e ddeje dZ d Z d Zd Zd ZejZed edejedZdZejZeZeddeddedddejedZejZeZeddeddedddejedZejZeZeddeddejedZdZejZ e dde d d!eje d"Z!d#Z"d$Z#d%S)&%CardApplicationISDR.AddlShellCommandsTX_DOz)Hexstring of encoded to-be-transmitted DO)helpcjt|jjj|j\}}dS)zJPerform a raw STORE DATA command as defined for the ES10x eUICC interface.N)r[rs_cmdlchanrmr)r;opts_datars rdo_es10x_store_dataz9CardApplicationISDR.AddlShellCommands.do_es10x_store_data{s*/99$)/:MtzZZLUCCCrct|jjjt t }|}|jt|ddS)z6Perform an ES10a GetEuiccConfiguredAddresses function.euicc_configured_addressesN) r[rrrrmrfr poutput_jsonr)r;_optsecars r!do_get_euicc_configured_addresseszGCardApplicationISDR.AddlShellCommands.do_get_euicc_configured_addressess`%44TY_5HJbJdJdf~C A I " "#5a8T6U#V#V W W W W Wr DP_ADDRESSz&Default SM-DP+ address as UTF-8 stringc0tt|jg}t|jjj|t}|}|j t|ddS)z.Perform an ES10a SetDefaultDpAddress function.rrset_default_dp_addressN) rqr]rr[rrrrmrrr)r;rsdda_cmdsddars rdo_set_default_dp_addressz?CardApplicationISDR.AddlShellCommands.do_set_default_dp_addresss|+5Edo5^5^5^4_```H&55dio6I8UhiiD A I " "#5a8P6Q#R#R S S S S Srct|jjjt t }|}|jt|ddS)z,Perform an ES10b GetEUICCChallenge function.get_euicc_challengeN) r[rrrrmrxrrrr;rgecrs rdo_get_euicc_challengezsk E99999///d///[/////rr!cBeZdZdZfdZededdfdZxZS)CardProfileEuiccSGP02cLtddS)NzM2M eUICC (SGP.02)rrrjs rrczCardProfileEuiccSGP02.__init__Orrrmr Ncrd|_|t|ddS)Nr#r)rrr get_datars rrz%CardProfileEuiccSGP02._try_match_cardRs3  y!!! Trrrs@rr&r&Lsk E44444/d[rr&)rHr constructrrrrrrr osmocom.utilsr osmocom.tlvosmocom.constructpySim.exceptionsr pySim.utilsr rpySim.commandsrpySim.ts_102_221rpySim.global_platformpySim BER_TLV_IErglobal_platformDataCollectionpossible_nestedappendr*r1boolr5Adapterr7ror|rdr AID_ISD_P_FILEAID_ISD_P_MODULErOrTFciTemplateNestedListrZr]rcrfrirqrsrxrzr~rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr r rrrrrrr r"r$r&r(r*r-r/r2r4r6r9r<r?rArCrErJrLrNrUrWrYCardApplicationSDr[r rr!r&rrrr@sO.;;;;;;;;;;;;8888888888 ))))))4444444444******,,,,,,)))))zt))))$4;;HEEE0 00000W000nUU1f--.. 9 8 88ZT     G]F^         *$u/D/Z0R/S0T    *****zt*********JD****     zv?OQ^>_    88888*$8888     *&:JL_9`    '''''ZT''''     7G    *$))))):4))))     JDBVAW         zt=Q@]1I=Zc1EwP_ 1a    kkkkk:4kkkk     *&:N9O    """"" """"******$****)))))JD))))     :69FZ;NPU;W         zt=Q         ZT;-    HHHHH:4HHHH     *&.J^9_    *$eeeee:4eeee     gu5E         zv7H+6V          ~    KKKKKJDKKKK     8I;7W             @@@@@:4@@@@     zvw6F          ~    )))))zt))))     :67H2E    *********     ZVUCSUb2c    *****JD*********jd****WWWWW WWWW""""":4"""""""""zt""""(((((:4((((     :4T`9IK_9a         jdU=V    ZXZXZXZXZX%/AZXZXZXx     50B   & M M M M MO M M M / / / / /O / / /     O     r