I am currently working on a soft phone working on windows, the goal is to be able to make a call from a standard phone number, using a sim card, through VoLTE (Voice over LTE).
Currently I am able to contact the HSS/HLR and receive a 401 Unauthorized with a nonce (According to he standard RFC3310). This nonce should be given as a input a AKAv1-MD5 algorithm, which will return a new value that can be send to the HSS/HLR and the authorization is done, this can only be done on a sim card. It cannot be done on a computer due to another input to the algorithm which is highly confidential and only known by a sim card.
Therefore, I would like to know how I can interface with a sim card through a sim card reader, send the nonce to the card, and let it calculate the response and return it.
As my project is written in C# it is preferable if some headers for C# exists.
Since I am using VoLTE the sim card must be a USIM, hence the interface must be to a USIM.
I can, if needed get the Ki key from the sim card, because I working together with a telephone operator.
You are (most probably) looking for the AUTHENTICATE
command as defined in 3GPP TS 31.102 (the former variants of the same command were referred to as RUN GSM ALGORITHM
or INTERNAL AUTHENTICATE
in the past).
To use it, you must meet some conditions, citing TS 31.102:
The function is related to a particular USIM and shall not be executable unless the USIM application has been selected and activated, and the current directory is the USIM ADF or any subdirectory under this ADF and a successful PIN verification procedure has been performed (see clause 5).
The selection of the USIM application is described in section USIM application selection, some notes:
EF.DIR file format is specified in ETSI TS 102 221 (originates from ISO 7816-4)
USIM AID should start with A00000000900001
(RID=A0000000090
, PIX=0001...
) as defined in ETSI TS 101 220
For PIN verification the VERIFY PIN
command should be used as defined in ETSI TS 102 221 (it might be easier to disable PIN at all). Beware that you need to pad the PIN value with 'FF'
bytes, citing:
PIN and PIN2 are coded on 8 bytes. Only (decimal) digits (0‑9) shall be used, coded in ITU‑T T.50 [5] with bit 8 set to zero. The minimum number of digits is 4. If the number of digits presented by the user is less than 8 then the ME shall pad the presented PIN with 'FF' before sending it to the 3GPP application.
The underlying cryptography is >somewhat< described in 3GPP TS 33.102 (probably the section Authentication and key agreement).
To actually communicate with the smart card from .NET use pcsc-sharp. Some example code is here and here.
If you can get the Ki
and know the correct algorithm then I would strongly recommend using the 'emulation approach' if possible (can't help here -- but see e.g. this post with some interesting links).
Disclaimer: My hobbyist GSM experience ended several years ago (before 2.5G) so please do validate my thoughts
Good luck -- you will definitely need it!
EDIT>
Osmocom provides a simple tool -- Osmo-sim-auth which performs the authentication -- might be helpful for you.