Hello,
Sorry for posting this question here, I've asked this GPPro Martin as well. Not sure if I should've included him as well.. Just there is a few people to ask help for this level of details.
I've figured out that my problem was in LOAD commands, now reading GP code, I've written this loader: https://gist.github.com/Novitoll/f0dbyour070f06d8a268adf571d5c8eb3947 https://gist.github.com/Novitoll/f0db070f06d8a268adf571d5c8eb3947
Every component in CAP file is in separate APDU with LOAD instruction. First 5 is loaded successfully with DATA=00, SW=9000, however on Method it fails. As you can see from my script, I've fixed Descriptor size to 0000 in Directory field. And in Header C482xxyy, where xxyy is calculated properly, which is a sum of all size fields in Directory, e.g.
016a = 0011+001f+000c+001e+0042+0018+006d+0032+0017+0000+0000
*Question*: Can't figure out why Method LOAD fails? By checking GP 2.1 spec, it doesnt help me understand the problem. Concatenated components to < 255 block size also fails, only separate components work for LOAD.
[+] Install for load
80e602001207d07002ca449001000006ef04c60201850000c0000000
<< 009000 [+] LOAD - Header
80e8000018c482*016a*010011decaffed010204000107d07002ca44900100c0000000
<< 009000 [+] LOAD - Directory
80e800012202001f*0011001f000c001e00420018006d0032001700000000*
00040002002202010000c0000000 << 009000 [+] LOAD - Import
80e800022104001e02000107a0000000620101060210a0000000090003ffffffff891071000200c0000000 << 009000 [+] LOAD - Applet
80e800030f03000c0108d07002ca44900101002000c0000000
<< 009000 [+] LOAD - Class
80e800041b06001843800301ff0007020000002f00398002008101010881000000c0000000 << 009000 *[!!!!] LOAD - Method (FAILED)*
*80e800057007006d000911188c00048d00012c18197b0002037b00029210240303038b000388007a02318f00053d8c00062e1b8b00077a0120188b000860037a7a02228d00092d1d10076b101a8b000a321fae006b06188c000b7a06118d000c2c1903077b000d037b000d928b000e198b000f3b7a00c0000000* *<< 9000 (should be 009000)*
[-] LOAD - StaticField (FAILED due to last failed LOAD)
80e80006350800.....
<< 6A86 (because prev. p2=05 is not loaded)
P.S.: I couldnt find the right spec explaining "C482XXYY" in Header.cap, how it should be calculated, this answer below helped me navigate, but for Method.cap loading - it still fails https://community.oracle.com/tech/developers/discussion/1753814/globalpaltfo...
On Mon, Jan 24, 2022 at 6:24 PM Sabyrzhan Tasbolatov snovitoll@gmail.com wrote:
Hello Vadim,
Is there a specific reason to write your own code for that?
I was told that the OSS shadysim.py is a raw version, moreover there are bytes in strings that are not explained in comments etc. I wanted to understand every byte I need to send, reading specs, so I've managed to write this script, APDUs are same as in shadysim.py, except the encryption part as my SPI, KIC, KID are different from sysmoUSIM-J2.
If not, give https://github.com/martinpaljak/GlobalPlatformPro a try.
I will try again, thanks. Last time I was stuck at --key-enc (KIC1), --key-mac (KID1), params are not taken and default keys are used for some reason. Generally, I chose initially applet installation via SMS-DELIVER, AFAIK, GP is a different approach.
Another question please:
- If I have already installed USIM applet on SIM card, and I want to
 install another one, will it be a conflict? As EF_DIR needs to be updated probably? Or last SELECTed AID is saved on UICC (per specification) and it will "replace" the older applet, or should I DELETE the original one?
Thanks On Mon, Jan 24, 2022 at 5:59 PM Vadim Yanitskiy vyanitskiy@sysmocom.de wrote:
Hi Sabyrzhan,
AFAIU, in your script you're using the GlobalPlatform API to manage cardlets. Is there a specific reason to write your own code for that? If not, give https://github.com/martinpaljak/GlobalPlatformPro a try.
Best regards, Vadim.
--
- Vadim Yanitskiy <vyanitskiy at sysmocom.de> http://www.sysmocom.de/
 =======================================================================
- sysmocom - systems for mobile communications GmbH
 - Alt-Moabit 93
 - 10559 Berlin, Germany
 - Sitz / Registered office: Berlin, HRB 134158 B
 - Geschaeftsfuehrer / Managing Director: Harald Welte
 -- Sabr