Notes
How a SIM actually works
Most pages online start in the middle: MF, DF, EF, a tree of file IDs. Useful if you already know why the card exists. This starts one step earlier — the idea the whole industry is built on — then lands on the same files, with names you can keep.
1. Hide a key. Prove you have it.
A smart card is a tiny computer whose job is to protect a secret in both software and hardware. The key lives in the chip. The plastic around it is not the protection. Steal the card, you still cannot read the key.
So how does anyone know the key is in there? You do not look. You ask. Send a random challenge. The card computes an answer with the key it will not show. If the answer matches, the key is present — and it never left the chip.
That is the whole concept. Telecom took that computer and called it a SIM. eSIM did not replace the idea. It replaced the plastic: same card, same keys, same applications — you swap the profile over the air (RSP) instead of swapping the piece of plastic.
2. Then it became Java.
Early SIMs ran a proprietary OS. Later the industry put a JVM on the card: Java Card. Inside that JVM you have a stack, and on the stack you have applications. They are called applets because they are reactive — they wait for an event, then they run.
The language with the terminal is APDU: command in, response out. The modem is usually in charge. When the SIM needs the modem to do something — show a menu, send an SMS, run a call — it cannot just grab the bus. That is proactive: the modem periodically asks “what next?”, and the SIM answers “run this for me.”
3. First meeting: Reset → ATR → Terminal Profile
Plug the card in. The modem resets it. The SIM answers with an ATR (Answer To Reset): here is what I am, here are my capabilities.
Then the terminal declares what it can do. That message is the Terminal Profile — not to be mixed up with Terminal Response, which is the modem answering a proactive command later. The profile is the jackpot if you want to know what kind of device you are sitting in, without trusting an IMEI.
We published a parser for it. Paste a profile in the tools, or take the code from GitHub (morestk).
Cheap modems sometimes lie in that profile. Consumer handsets usually do not. That gap is why one research applet stayed in the lab — the story is here.
4. Why applets existed in the first place
After a while the card was not only “hold the key.” It ran applications.
Callback. Catch an outgoing call, turn it into a USSD so the network can call you back. Cheaper in markets where incoming was the cheap direction.
Multi-IMSI. Still around. Switch the IMSI when the local roaming picture is thin — a young operator, or a place with no agreement. If you need that implemented, it is applet work, not a product checkbox.
There was also locking a SIM to a piece of hardware via IMEI. Fraud learned to fake the IMEI. SIMboxes drive hundreds of SIMs at once. If that is your problem, contact us — the on-card work is patent pending and not described here.
5. Two kinds of keys you do not want walking out
Network keys (OPC / Ki): how the SIM authenticates to the radio network.
OTA keys: how you control the card later. Two protocols, two specs: SCP80 is the SMS (and CAT_TP) secured packet — ETSI TS 102 225 / 102 226, with the 3GPP SMS dialect in TS 31.115. GlobalPlatform just numbered that protocol '80'. SCP81 is RAM over HTTP with PSK-TLS — GlobalPlatform Amendment B (identifier '81'). Generate them on site so they never leave the operator. That is also why MoreOTA is on-premise.
We design and build that key-generation chain, and we consult on it — what to do, what to avoid. Security & applets.
6. The electrical profile — three file types
“Electrical profile” is the file structure you order on the card: folders, applications, and the files inside them, each with access rights. ETSI TS 102 221 names the everyday elementary files in three shapes (a fourth, BER-TLV, arrived later — most operator profiles still live in these three):
- Transparent
One stretch of bytes. Read or write by offset — like a single document.
IMSI, ICCID
- Linear fixed
Equal-length records, addressed by number — like rows in a table.
Phonebook (ADN), ARR
- Cyclic
Still records — same as linear. Read and write go in a circle: the newest write overwrites the oldest. TS 102 221 §8.2.2.3.
Last numbers dialled (EF LND)
Access: PIN1 · PIN2 · PUK1 · PUK2 · ADM · ARR per file OTA keyset (SCP80): KVN '01'–'0F' · KIc + KID + DEK/KIK · TS 102 225 annex A SCP81 (HTTP): PSK-TLS + DEK, typically KVN '40'–'4F' · GP Amendment B / SGP.02
Still records — same as linear — but read and write go in a circle: the newest write overwrites the oldest (ETSI TS 102 221 §8.2.2.3). Folders (DF) and applications (ADF) group files for a technology — GSM, USIM, ISIM. You do not dump everything in one pile.
Access is not “the file is open.” Each file has a privilege: PIN1, PIN2, PUK1, PUK2, ADM (administrative — sometimes ADM1, ADM3). ARR files store, per file, who may read or write. That is how you stop a handset from touching something only OTA should touch.
7. Keysets — where OTA actually lives
On the card a “keyset” is a GlobalPlatform key version number (KVN). Keys that share a KVN work together. The three you hear in SMS OTA are:
- KIc — ciphering (key identifier '01')
- KID — integrity / cryptographic checksum ('02')
- DEK (often still called KIK) — encrypts keys when you rotate them later ('03')
That triple is SCP80. ETSI TS 102 225 annex A.1: for each Security Domain the KVN range is '01'–'0F' — that is 1 to 15, not 16. Zero is reserved. Those four bits sit in KIc/KID b8–b5 of the SMS packet; both versions must match when they are not zero, or the card rejects with status 06.
Most operators load one SCP80 version. Two is the grown-up layout: one for the operator, one to hand a third party without giving them the house keys.
SCP81 is not another SMS keyset. Amendment B’s keyset is a PSK-TLS key plus a DEK under the same KVN (PSK at identifier '01', DEK at '02'). The version is a full byte, not the four-bit SMS field. Amendment B’s own example is KVN '40'. GSMA SGP.02 §2.2.5.1 puts SCP81 in '40'–'4F' (decimal 64–79). Copy an SCP80 version 1 into HTTP and the session will not find a PSK.
Lineage, so the numbers stop blurring: GSM 11.11 is the SIM–ME interface; GSM 11.14 is SIM Toolkit (proactive commands, Terminal Profile) — now 3GPP TS 51.011 / 51.014 and TS 31.111. Neither is the OTA packet. OTA security was GSM 03.48 (3GPP TS 23.048). From Release 5 it split: generic packet → ETSI TS 102 225 / 102 226; SMS/USSD/HTTP wrapping → 3GPP TS 31.115 / 31.116.
If a card then goes quiet after an OTA command, that is not always a defect. Sometimes silence is the security.