aka: the ISIM application of a card, its identity files and the identity they hold

An ISIM holds the parameters a registration starts from (TS 24.229
5.1.1.1A): the private identity in EF_IMPI, the home domain in
EF_DOMAIN and public identities in EF_IMPU (TS 31.103 4.2.2 to 4.2.4),
of which the first record's is the one to register (GSMA IR.92 2.2.1).
TS 23.003 has a UE derive its home domain and a temporary public
identity from the IMSI "if there is no ISIM application" (13.2, 13.4B);
those derived names are the only ones imsd has. This is the part of
reading an ISIM that has no I/O; the daemon does not use it yet.

ParseIsimApp finds the ISIM application of one slot in qmicli's card
status, in whatever state the modem lists it. On the two cards with an
ISIM that a read-only probe read (a US card, 2026-11-23, and a
Norwegian one, 2026-11-21) the Fairphone 6's modem lists the ISIM
`detected` beside the `ready` USIM, and on both a logical channel
opened on it and its identity files were read.

The commands are the ones that probe sent: SELECT by file identifier,
READ BINARY, READ RECORD (TS 102 221 11.1.1, 11.1.3, 11.1.5).
ApduAnswer is a card's answer, '90 00', '91 XX' and '92 XX' its normal
endings (10.2.1.1), and ApduFollowUp the command it asks for next when
the answer brought no data: GET RESPONSE for '61 XX', a command without
data again with the length named for '6C XX' (7.3.1.1.5); an answer
with data is taken for the command's last. HoldsRead takes a read's
data under the warning '62 82' as well (10.2.1.3). ParseIsimValue takes
the value of the data object with tag '80' that a file begins with,
cuts 'FF' bytes from the end of its length as the probe does, and gives
none for a value with a blank or a byte that is not printable ASCII.
IsimIdentity checks the three values before they replace the derived
names: they are written into a quoted string and between the angle
brackets of SIP header fields. It refuses a value with a quote, a
backslash, an angle bracket, a blank, a line break or another byte
outside printable ASCII, a private or a public identity of more than
255 characters, a private identity without an @ between two parts, a
domain that is not labels of letters, digits and inner hyphens, 63
characters a label and 253 in all at most, and a public identity that
does not begin sip: or is that alone.

The two readers of the card status share how they read a line;
ParseCardStatus gives what it gave.

Tested: tests/Aka (the application out of a card status with the US
card's two applications, in either order, and out of a second slot with
the Norwegian card's AID; the commands, the answers and their
follow-ups, the values, the identity and what is refused) and
tests/Messages (the two REGISTERs of an ISIM's identity against the
pinned ones).
This commit is contained in:
Jorijn van der Graaf 2026-11-23 19:32:58 +01:00
commit 3754687b0d
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
4 changed files with 653 additions and 46 deletions

View file

@ -44,7 +44,7 @@ PipeWire. The verified device/carrier combinations are in the README.
| `interfaces/Imsd-Sip.cppm` | `imsd::sip` — SIP as a text layer plus TCP framing: header extraction (from the header section only: a read ends at the first empty line after the start line, empty lines before it skipped; a header is asked for by its long name and found under that or its compact form — RFC 3261 7.3.3: the RFC's ten, and `o` for Event and `x` for Session-Expires — with or without white space before the colon; `Unfolded`, by which the framers hand a message on with its folded header lines — 7.3.1 — joined; `HeaderUri`: the party a header names; `Body`, moved here out of `CallMachine`), status codes, the granted lifetime, `ResponseOf` transaction matching (the Call-ID, and the CSeq as its number and its method, whatever spaces or tabs part them and whatever zeros stand before the number), `CutShortRequest`: the header section of a request — any but an ACK or a CANCEL — whose datagram has fewer body bytes than the Content-Length read from it says, which its 400 is built from. Not a full RFC 3261 parser, deliberately. |
| `interfaces/Imsd-Sdp.cppm` | `imsd::sdp` — SDP offer/answer: the AMR-WB + AMR + telephone-event offer (optional IR.92 preconditions; `OfferedTelephoneEventPt` names its telephone-event numbers), the parser the media plane needs (the codec, its payload type and mode, and the telephone-event payload type the m-line lists at that codec's clock), `BuildAnswer` for the terminating side, the `CODECS` override. |
| `interfaces/Imsd-Sms.cppm` | `imsd::sms` — the short message codecs SMS over IP rides on (TS 24.341 carries the bytes a 2G/3G phone puts in an RP-DATA, in a SIP MESSAGE body): the GSM 7-bit default alphabet with its extension table and the septet packing, UCS-2 (TS 23.038); the SM-TL PDUs (TS 23.040: SMS-SUBMIT built, one per segment with the concatenation header when the text needs more than one; SMS-DELIVER, SMS-STATUS-REPORT and SMS-SUBMIT-REPORT parsed; the SMS-DELIVER-REPORT that acknowledges a delivery; the user-data header — concatenation, application ports — and the `Reassembler` of a concatenated message); the SM-RL messages (TS 24.011: RP-DATA, RP-ACK, RP-ERROR in both directions, the cause values) and `RpCauseIsTemporary`, the causes of a submission after which imsd sends the segment again; EF_SMSP (TS 31.102 §4.2.27), where the (U)SIM names the service centre, and qmicli's hex dump of it. Byte-level only: no SIP, no clock, no I/O. |
| `interfaces/Imsd-Aka.cppm` | `imsd::aka` — USIM AKA glue: the AKAv1-MD5 digest (RFC 3310), IMPI/IMPU/realm from IMSI + MCC/MNC, parsers for `qmicli --uim-get-card-status` and `mmcli` output, the AUTHENTICATE APDU and its response. |
| `interfaces/Imsd-Aka.cppm` | `imsd::aka` — the card's side of a registration: the AKAv1-MD5 digest (RFC 3310), IMPI/IMPU/realm from IMSI + MCC/MNC, parsers for `qmicli --uim-get-card-status` and `mmcli` output, the AUTHENTICATE APDU and its response; since 1.2.3 the ISIM: the application of the slot in use out of the card status (`ParseIsimApp`, in whatever state the modem lists it), the SELECT and the two READ commands its identity files are read with, a card's answer (`ApduAnswer`: `90 00`, `91 XX` and `92 XX` are its normal endings; `HoldsRead` takes a read's data under `62 82` as well) and the command it asks for next (`ApduFollowUp`, for an answer without data: GET RESPONSE for `61 XX`, a command without data again for `6C XX`), the value a file holds (`ParseIsimValue`: the data object with tag `80`, the `FF` bytes at the end of its length cut, no blank and no byte outside printable ASCII) and `IsimIdentity`, the check of the three values — an `@` between two parts, a domain of labels of letters, digits and inner hyphens, 63 characters a label and 253 in all at most, a `sip:` at the start and more after it, the two identities 255 characters at most, no blank, no byte outside printable ASCII and no `"`, `\`, `<` or `>` — before they replace the derived names. |
| `interfaces/Imsd-Ipsec.cppm` | `imsd::ipsec` — the two ESP SA pairs (TS 33.203) as `ip xfrm` argv lists, the ESP ciphers offered (`ParseEalgOffer`, `DefaultEalgOffer`), the Security-Server mechanism selection, and the reader that reconstructs SPIs/ports from `ip xfrm state`/`policy` text for a warm resume, and (1.0.0) `SaPeer`, the P-CSCF the kernel's pair is to, read from the `dir out` policies that carry imsd's fingerprint, `OwnXfrmDeleteCommands`, the deletes by exact key of what two rules select — the policies carrying imsd's fingerprint and the reqid-1/2 transport-mode ESP states in their direction or on the UE's ims-PDN address, whoever installed them (§12), and `FileNamesAnotherPair`, whether a state file's `spi_uc`/`spi_us` name the kernel's pair (unknown on either side decides nothing). |
| `interfaces/Imsd-Messages.cppm` | `imsd::msg` — every SIP request and response imsd sends, built from an explicit `Context` and per-request variables so the builders are pure functions; `tests/Messages` is their suite. Also `IsEmergency`. Since 1.2.0 the SIP MESSAGE of SMS over IP (`BuildMessageSms`: an RP-DATA to the service centre's PSI, or an RP-ACK/RP-ERROR to the IP-SM-GW with In-Reply-To — TS 24.341 5.3.1.2 and 5.3.2.4), the `+g.3gpp.smsip` Contact tag behind `Context::smsOverIp`, `BuildResponse`, the final for an inbound MESSAGE outside a call's dialog (the 200, the 480, the 488): each Via row echoed in order and the To echoed with a tag added unless it already holds `tag=` (RFC 3261 8.2.6.2); since 1.2.1 `BuildBadRequest`, the 400 to a request cut short of the Content-Length read from it — any but an ACK or a CANCEL, in a call's dialog or not —, in that shape, a To tag it adds made from the request's header section and a secret of the run (RFC 3261 8.2.7); of requests that came whole, in-dialog requests, a MESSAGE among them, and the shell's answers to any other request outside a call — a NOTIFY, an OPTIONS, a method it does not handle; not an INVITE, whose 486 while a call exists is `BuildInviteResponse`'s — keep `BuildResponse200`'s hop-by-hop shape; and `ScPsi`, the service centre's PSI from its international number — never a dialled-number guess. |
| `interfaces/Imsd-Engine.cppm` | `imsd::engine` — the decisions as pure reducers: `CallMachine` (one call's dialog, returning `Action`s for the shell), `RegRecovery` (the registration recovery policy, §7.4) and, since 1.2.0, SMS over IP (§7.9): `SmsOutbound` (one short message of ours on its way to the service centre, segment by segment, since 1.2.1 a segment that gets no answer, or an RP-ERROR with cause 41, sent once more with TP-RD set — TS 23.040 9.2.3.6 —, returning `SmsAction`s) and `OnSmsMessage` (what an inbound MESSAGE outside a call's dialog leads to: its final, the message or status report it delivered, the delivery report to send), and `RecentTransactions` (an inbound request's retransmission — the same Call-ID, CSeq and Via branch within 32 s (`TimerJ`), the branch being the value of the first `branch=` of its first Via row and a request with none or an empty one never matched — answered with the same final and not handled again) and, since 1.2.1, `RecentSubmissions` (the Call-IDs of the MESSAGEs our submissions went out in, an hour each, by which a submit report for one that is no longer in flight is known for ours — TS 24.341 5.3.1.2); `SameRecipient` and `StatusReportBook`, a status report's match to the message that asked for one — TP-MR and recipient — and its word for the whole message, with `SmsWordOrder`, the order of a message's words: the submission's first, a report's held until then (§7.9); `RunToken`, `SentSmsId` and `ReceivedSmsId`, the ids (§8.4); `StoredSms` with `FormatStoredSms`/`ParseStoredSms`, the record codec of the received-message store, and `StoredSmsBefore`, `List`'s order. |
@ -256,7 +256,28 @@ What the suites pin:
text parsers, the AUTHENTICATE APDU and its response parser, the class
byte of a command on a logical channel (the channel itself for 0 to 3,
`4X` for 4 to 19 — TS 102 221 10.1.1; AUTHENTICATE on channels 3 and
4, GET RESPONSE on channel 7).
4, GET RESPONSE on channel 7); the ISIM application of a slot (a card with a `ready` USIM and
a `detected` ISIM in one slot, in either order — the applications, states
and AIDs the fp6 journal's probe read off a reporter's card, 2026-11-23,
in the lines qmicli prints for an application —; another slot's ISIM not
taken, a twelve-byte AID, a CSIM, a missing state line) and the slot of
a line whose number does not parse, the SELECT and the READ
commands byte for byte on standard and extended channels, a card's answer
and its follow-up (`61 XX`, `6C XX` to a read and to a command with
data, an error, data with `61 XX`; `91 XX` and `92 XX` normal endings,
`90 01` and `93 00` none; a read's data
taken under `62 82`, not under `62 81` or `63 82`), `ParseIsimValue` (the
three length forms, the padding after the object and `FF` at the end of
its length, an unused record, another tag, a length past the data, a
blank, a line break, a NUL, an `FF` before the value's end, a byte above
ASCII) and `IsimIdentity` (names unlike the derived ones, the derived
ones themselves, and what is refused: a private identity without an `@`
between two parts, a domain that is not labels of letters, digits and
inner hyphens or that has a label of 64 characters or 254 characters in
all, a public identity that does not begin `sip:` or
is that alone, a private or a public identity of 256 characters, a
quote, a backslash, an angle bracket, a blank or a line break in one of
the three).
- `Ipsec` — the exact `ip xfrm` argv lists for the SA pairs, the `EALG`
setting, the Security-Server mechanism selection against one offered
cipher and against two (KPN's entry and Odido's, O2's six with the SPIs
@ -289,7 +310,10 @@ What the suites pin:
TLVs) and the error names (OutOfCall, NoEffect, an unknown code as `?`).
- `Messages` — the outgoing SIP messages: the initial and the protected
REGISTER, the reg-event SUBSCRIBE and the INVITEs byte-for-byte, their
variants (a Security-Client for another offer among them), the in-dialog
variants (a Security-Client for another offer among them; the two
REGISTERs of an identity an ISIM holds, byte for byte the pinned ones
with the card's names for the derived ones, and `RuriFor` at an
ISIM's home domain), the in-dialog
requests, the ACKs, the CANCEL and
`BuildResponse200` by their lines, `BuildInviteResponse` by the lines of
one 180 and by a 486 without a Record-Route (`tests/Engine` checks the
@ -2679,6 +2703,27 @@ the related code.
01:17:41–45, 28–36 min after their SC time stamps; what held them is
unknown. The registrar echoes `+g.3gpp.smsip` in the reg-event reginfo
(`<unknown-param name="+g.3gpp.smsip"/>`) on both AORs.
- **Cards with an ISIM** (the fp6 journal's read-only probe on two
reporters' phones; the dev phone's card has none). A US card on AT&T's
network (operator name "Dark Star", SIM operator 310 280; 2026-11-23) and
a Norwegian one (Ice, 242 14; 2026-11-21) each list a USIM `ready` and
an ISIM `detected` in one slot of the Fairphone 6. On both a logical
channel opened on the ISIM's AID in that state and the probe read
EF_IMPI, EF_DOMAIN and EF_IMPU's record 1: it sends SELECT by file
identifier with P2 `04` and takes a `61 XX` for the file selected, sends
READ BINARY and READ RECORD with Le `00` and follows a `61 XX` or a
`6C XX` to those (which it got on the way it does not print), and cuts
`FF` bytes from the end of a value. The US card holds names of the
operator's own in all three
(the private identity `<IMSI>@private.att.net`, the home domain
`one.att.net`, the public identity `sip:<IMSI>@one.att.net`) and has no
EF_P-CSCF and no EF_IST (`6A 82` to their SELECT); the Norwegian card
holds the names TS 23.003 derives from the IMSI, an EF_P-CSCF of three
unused records and an EF_IST of seven zero bytes. On the dev phone's
USIM (a KPN eSIM, 2026-11-21, by hand) that SELECT answered `61 19` for
one file and `61 1C` for another, the
two reads data and `90 00` at once, and the SELECT of a file the
application does not have `6A 82`.
- **A folded `WWW-Authenticate`** — the 401 to the unprotected REGISTER
came with its `WWW-Authenticate` over four lines on KPN (2026-07-18)
and on Odido (2026-07-13), the nonce on the second (RFC 3261 7.3.1; one