2

I have written an applet on a sim card and successfully installed it on my sim. Now I want to send/receive APDUs to my sim card applet using an android application.

Some libraries (e.g. Seek) need rooted devices and do the task but I don't want to root devices. Is there any android libraries to interface my applet? All I have found is applications to use NFC or Bluetooth to send or receive APDUs to contactless cards, but I need to interface contact sims inserted to mobile sim card slot.

Appendix 1:

These are all applets existing on my USIM (output of GPShell list function):

mode_211
enable_trace
establish_context
card_connect -readerNumber 1
select -AID A000000151000000
Command --> 00A4040008A000000151000000
Wrapped command --> 00A4040008A000000151000000
Response <-- 6F108408A000000151000000A5049F6501FF9000
open_sc -scp 2 -scpimpl 0x55 -security 1 -keyind 0 -keyver 0 -mac_key 404142434445464748494a4b4c4d4e4f -enc_key 404142434445464748494a4b4c4d4e4f
Command --> 805000000853160BA36116264B00
Wrapped command --> 805000000853160BA36116264B00
Response <-- 000081210103B99E856DFF020032D2AE118D648EC6F57DFA6581CCC39000
Command --> 8482010010395D6343C2D216F30460633603DD27A2
Wrapped command --> 8482010010395D6343C2D216F30460633603DD27A2
Response <-- 9000
get_status -element 20
Command --> 80F22000024F0000
Wrapped command --> 84F220000A4F0075545E9C0668BCDA00
Response <-- 07A0000001515350010005A000000087010006A00000025108010010A0000000090005FFFFFFFF8915000000010008A000000151100303010010A0000000185000000000000052418050010007E0E1E2E3E4E501010008A00000015141434C01009000

List of elements (AID state privileges)
a0000001515350  1       0
a000000087      1       0
a00000025108    1       0
a0000000090005ffffffff8915000000        1       0
a000000151100303        1       0
a0000000185000000000000052418050        1       0
e0e1e2e3e4e501  1       0
a00000015141434c        1       0
get_status -element 40
Command --> 80F24000024F0000
Wrapped command --> 84F240000A4F0023B1458CFDA5C36100
Response <-- 10A0000000871002FF82FF3089010000FF070410A0000000871004FF47F00189000001FF070010A000000087ABCDFF47F00189000001FF070007A0000002510801070009A00000015110030301870010A0000000185000000000000052418041070009A0000000035350410107C009A0000000035350410207C009A0000000035350410307C009A0000000035350410407C009A0000000035350410507C009A00000000353504106078008E0E1E2E3E4E50102070209A00000015141434C0007029000

List of elements (AID state privileges)
a0000000871002ff82ff3089010000ff        7       4
a0000000871004ff47f00189000001ff        7       0
a000000087abcdff47f00189000001ff        7       0
a0000002510801  7       0
a00000015110030301      87      0
a0000000185000000000000052418041        7       0
a00000000353504101      7       c0
a00000000353504102      7       c0
a00000000353504103      7       c0
a00000000353504104      7       c0
a00000000353504105      7       c0
a00000000353504106      7       80
e0e1e2e3e4e50102        7       2
a00000015141434c00      7       2
card_disconnect
release_context

e0e1e2e3e4e50102 is my applet and a00000015141434c00 is allow all ARA applet.

MJay
  • 987
  • 1
  • 13
  • 36

1 Answers1

2

Since Android 9 there is android.se.omapi package providing such access (implementing SIMalliance Open Mobile API). For older devices supporting OMAPI, see e.g. here, here, here.

To get access to your applet there has to be an ARA-M applet on SIM configured to allow your application to connect to your applet (there is a MIT licensed implementation available here and a special all-allowed implementation here).

Access configuration can be performed with GlobalPlatformPro.

Disclaimer: A lot has changed since I was dealing with this so please do validate my thoughts.

Good luck!

vlp
  • 7,811
  • 2
  • 23
  • 51
  • Do you know any guide or sample scripts to configure ARA-M applet? It always returns me `Failed to communicate with card in JnaCardTerminal{scardHandle=SCardContext{cd00000100000001}, name=ACS ACR83U 0}: SCardTransmit got response 0x57 (null: null)` when trying to run gp commands – MJay Jul 23 '19 at 05:02
  • Is that just manually install ARA-M alongside my sim applets and do the configurations? – MJay Jul 23 '19 at 05:10
  • 2
    @MJay When do you get this error? When installing ARA-M applet or when configuring it? SEEK for Android contains a simple ARA-M implementation which always allows all access -- maybe try [this one](https://github.com/seek-for-android/allow-all-ara) first. – vlp Jul 23 '19 at 06:51
  • Thank you, I will check it right now. I get this error while configuring ARA-M. – MJay Jul 23 '19 at 06:54
  • I tested allow-all-ara-master. I installed it on my sim card along with my applet by which I want to communicate. But again, I cannot connect to sim card, android application says `No Sim card inserted` and `sim card is locked` and OS says `sim card is locked`. Is there anything I have forgotten to do? Thanks for your help vlp. – MJay Jul 23 '19 at 08:06
  • 1
    Did your SIM work in the phone before (e.g. was it able to register to the network)? There needs to be a working (U)SIM application present on the card. – vlp Jul 23 '19 at 08:33
  • I own have a Java usim (smart card), which is programmed with a customized applet by an ACR reader connected to PC. So, my usim is not a general sim card. – MJay Jul 23 '19 at 09:07
  • My phone is single slot sim. I insert my usim into sim slot. When I turn on the phone, os displays `SIM is blocked`. – MJay Jul 23 '19 at 09:11
  • @Mjay I understand you have a Java Card, but does it have a (U)SIM applet loaded and personalized? Phone expects SIM card to support e.g. [TS 51.011](https://portal.3gpp.org/desktopmodules/Specifications/SpecificationDetails.aspx?specificationId=2793), [TS 31.10](https://portal.3gpp.org/desktopmodules/Specifications/SpecificationDetails.aspx?specificationId=1803) which must be implemented somehow... – vlp Jul 23 '19 at 10:29
  • can you please see 'Appendix 1' I just inserted (editted) in my main question post. I added list of applications on my USIM. If there is something missing, where can I get SIM applet to load on my sim? – MJay Jul 23 '19 at 10:55
  • 1
    @Mjay USIM AID should start with `A00000000900001` (as per [ETSI TS 101 220](http://www.etsi.org/deliver/etsi_ts/101200_101299/101220/12.00.00_60/ts_101220v120000p.pdf)) and there is no such application. You might try sending e.g. `A0A40000027F10` to verify `DF TELECOM` presence (as per TS 51.011). If you have an off-the-shelf Java Card then there almost certainly won't be any U(SIM) application loaded and personalized... – vlp Jul 23 '19 at 11:29
  • 1
    ...I don't know where to get a working SIM card with known GP keys (but you might find [Sysmocom SIM/USIM cards for sale](http://shop.sysmocom.de/t/sim-card-related/sim-cards) useful). Please do validate my thoughts as my hobbyist GSM experience ended several years ago (before 2.5G). – vlp Jul 23 '19 at 11:30
  • Can I find those applets anywhere to install them manually on my U(SIM)? – MJay Jul 23 '19 at 11:34
  • @Mjay I don't know. Probably not.. Good luck with your project! – vlp Jul 23 '19 at 11:46
  • Thanks, just I have to mention that my USIM only supports `ETSI TS 102 221 (Class A, B, C)`, `EMV2000` and `ISO7816` standards. – MJay Jul 24 '19 at 08:45