diff --git a/AGENTS.md b/AGENTS.md index b3ba586..6d3f42d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -493,7 +493,15 @@ Rules: `tests/Ipsec` with two of O2's recorded lists, each its answer to an offer of one cipher, and run against a stand-in P-CSCF that marks the lower-q of the two as far as the `SA:` line; no capture holds O2's - answer to imsd offering two); a Security-Server list `PersistState` writes empty (one with + answer to imsd offering two); the default offer's null cipher taken + by a network (KPN named `aes-cbc` to the two-cipher offer at a fresh + registration and answered a reregistration that carried it 200: the dev + phone, 2026-11-22, an earlier build of this change, on 1.2.0; the + selection of a null entry is pinned in `tests/Ipsec` with Odido's answer + of 2026-07-13 to the Python stack's offer of the null cipher and ran + against a stand-in P-CSCF on the workstation as far as the `SA:` line; + no capture holds a registration of imsd's over a null SA pair); a + Security-Server list `PersistState` writes empty (one with a quote, a backslash or a newline — neither KPN's nor O2's list has one; the resume of such a file ran with a hand-edited empty key, 2026-10-11); a state write of a standing registration after a fresh @@ -2466,6 +2474,14 @@ only the imsd side of its bus choice. or paired, between any addresses — goes, with the reqid-1/2 transport-mode ESP states in its direction, and a reqid-1/2 transport-mode ESP state on the UE's ims-PDN address goes whoever made it (`tests/Ipsec` pins both). +- Whether the signalling is encrypted inside the SAs is the P-CSCF's + choice (TS 33.203 5.1.3): the default offer names `aes-cbc` and the null + cipher, and with the null cipher selected the SAs protect the + signalling's integrity and do not encrypt it. `EALG=aes-cbc` offers + encryption only; a P-CSCF that answers it with the null cipher alone is + followed all the same (README, `EALG`: when no entry matches). The + protected REGISTER repeats the Security-Client for the P-CSCF to compare + with the first one's (TS 33.203 Annex H). - The bus policies deliberately let any local account *reach* both names; authorization is polkit's, not the policy file's. Keep it that way: a policy that names an account breaks the moment the account is called @@ -2549,6 +2565,18 @@ the related code. one succeed, while the fresh registrations that followed were accepted: the origin of the 5.1.1.4.2 refresh shape. KPN accepts both shapes without a challenge. +- **The security offer.** KPN answered the two-cipher offer with one + mechanism, `hmac-sha-1-96` with `aes-cbc`, at a fresh registration, and + answered a reregistration that carried it 200 (the dev phone, 2026-11-22, + an earlier build of this change, on 1.2.0). Odido answered an offer that + named the null cipher with one mechanism naming `ealg=null`: the + Python stack's offer of that one cipher (2026-07-13) and the four + mechanisms of another Fairphone 6's own IMS client, which then + registered (2026-07-15). On KPN's ims PDN (MTU 1280) the netdev counted + one datagram fragmented in two after a boot with one fresh registration, + with one mechanism offered and with two (the dev phone, 2026-11-22): + the first REGISTER goes over UDP whatever its size, and KPN challenged + both. - **KPN closes a registration's previous reg-event subscription with `noresource`** when a new one replaces it: that end is not renewed. - **Modem attach-family forcing** (Odido, O2 UK, Swisscom): an APN-string diff --git a/README.md b/README.md index 9d49eb2..a0772c7 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ Configuration is environment variables in `/etc/imsd.env`, none are required. | `HOLDS_FILE` | `/run/imsd.holds` (root) / `$XDG_RUNTIME_DIR/imsd.holds` (`/tmp/imsd.holds` without a runtime dir) | the waits the network imposed (a `Retry-After`, the refusal schedule), where that schedule stands whether the old registration is gone (`old_gone`) and the refusal count (`refusals`: a resume refused without a Retry-After at a start with no fresh target is one, the restart's the second), kept across a restart of imsd for the PDN they were set on — not across a reboot; `/dev/null` switches the file off (only a regular file is ever removed; anything else is emptied). `imsd-handover.sh` honours it too | | `RESUME` | `auto` | `0` forces a fresh registration (ignores a warm SA) where there is a fresh target; with none the untried pair is removed and the bring-up ends as AGENTS §7.2 (the daemon's own bring-up) step 1 says | | `REFRESH_INTERVAL` | *(auto)* | keepalive re-REGISTER period in s; default = half the granted expiry, clamped to [120, 1800] | -| `EALG` | `aes-cbc` | the ESP ciphers offered, in order: a comma-separated list of `aes-cbc`, `null` (no encryption) and `des-ede3-cbc`; a name imsd cannot install is ignored with a journal line. From the 401's `Security-Server` list imsd selects the `ipsec-3gpp` mechanism the P-CSCF put the SPIs on when it is the only such entry and one of the offer, else the mechanism of the offer with the highest preference (the `q` of RFC 3329 §2.3.1), and takes the SPIs/ports from the entry carrying them (some cores list every mechanism they support and put the SPIs on the one they applied); when no entry matches, the P-CSCF's SPI-carrying entry is taken as listed (`hmac-md5-96`, an absent `ealg` = null) where imsd can install it, and the journal says so. The offer is logged at bring-up beside the SIP transport, the line, the selection and the SA parameters at every fresh registration | +| `EALG` | `aes-cbc,null` | the ESP ciphers offered, in order: a comma-separated list of `aes-cbc`, `null` (no encryption) and `des-ede3-cbc`; a name imsd cannot install is ignored with a journal line. From the 401's `Security-Server` list imsd selects the `ipsec-3gpp` mechanism the P-CSCF put the SPIs on when it is the only such entry and one of the offer, else the mechanism of the offer with the highest preference (the `q` of RFC 3329 §2.3.1), and takes the SPIs/ports from the entry carrying them (some cores list every mechanism they support and put the SPIs on the one they applied); when no entry matches, the P-CSCF's SPI-carrying entry is taken as listed (`hmac-md5-96`, an absent `ealg` = null) where imsd can install it, and the journal says so. The offer is logged at bring-up beside the SIP transport, the line, the selection and the SA parameters at every fresh registration | | `SIP_TRANSPORT` | `auto` | transport of the protected leg (the second REGISTER and everything after it): `tcp`, `udp`, or `auto` = TCP, falling back to a fresh registration over UDP when the P-CSCF leaves two TCP connects unanswered — but only on a phone that has never registered over TCP: once the state file records a TCP registration, a silent connect is treated as an outage, not a policy (delete the file or set `udp` to override, e.g. after a SIM change). The challenge (first REGISTER) is always UDP. Over UDP a REGISTER or INVITE larger than ~1.2 KB leaves as IPv6 fragments at the ims PDN's 1280-byte MTU (the journal says so once per flow); there are no SIP retransmission timers over UDP yet, so a lost datagram costs a timeout. The SAs, the listener and the firewall rule cover both transports | | `SMS_OVER_IMS` | `0` | `1` takes short messages over IMS (AGENTS.md §7.9): the REGISTER Contact advertises `+g.3gpp.smsip` and `net.catcrafts.IMS1.Messaging.Send` submits one; off, imsd does not advertise it and refuses `Send` (AGENTS.md §7.9 says how imsd answers a text the network sends anyway) | | `SMSC` | *(EF_SMSP)* | the service centre a submission is addressed to, in international form (`+31653131313`; spaces, dashes and dots dropped; a national or `00`-prefixed number, or a `*` or `#` in it, is refused at bring-up); unset, imsd reads the (U)SIM's EF_SMSP record 1. Without either, `Send` fails with the reason | diff --git a/interfaces/Imsd-Ipsec.cppm b/interfaces/Imsd-Ipsec.cppm index 25f6128..2960187 100644 --- a/interfaces/Imsd-Ipsec.cppm +++ b/interfaces/Imsd-Ipsec.cppm @@ -83,8 +83,13 @@ export namespace imsd::ipsec { } // The ESP ciphers offered in Security-Client when EALG names none, in - // the order offered. - std::vector DefaultEalgOffer() { return {"aes-cbc"}; } + // the order offered. The UE announces the IPsec algorithms it supports + // (TS 24.229 5.1.1.2.2 d; TS 33.203 7.2), and of the ciphers it must + // support (7.1 by TS 33.210 5.3.3: RFC 8221's NULL, AES-CBC and + // AES-GCM) these are the two EncArgs can key. Whether the signalling is + // encrypted is the P-CSCF's choice (TS 33.203 5.1.3); aes-cbc comes + // first for a P-CSCF that goes by the UE's order. + std::vector DefaultEalgOffer() { return {"aes-cbc", "null"}; } // An EALG setting ("aes-cbc, null") read as the ciphers to offer, in the // order written: case-insensitive, spaces and tabs ignored, "3des" for diff --git a/interfaces/Imsd-Messages.cppm b/interfaces/Imsd-Messages.cppm index 958dd29..d11bf35 100644 --- a/interfaces/Imsd-Messages.cppm +++ b/interfaces/Imsd-Messages.cppm @@ -9,7 +9,8 @@ context and the per-request variables (tags, branches, CSeq) so the builders are pure functions with no hidden state: the engine owns the dialog bookkeeping and the transport owns the socket, this module only formats bytes. That makes each message byte-pinnable — tests/Messages compares a REGISTER pair and an INVITE -with strings cross-generated from the Python reference stack, header for header. +with strings cross-generated from the Python reference stack, header for header +but for the divergences that suite's header names. Covers: the unprotected + protected REGISTER and the refresh re-REGISTER (sec-agree, Security-Client/Verify, AKAv1-MD5 Authorization); the INVITE with diff --git a/tests/Ipsec/main.cpp b/tests/Ipsec/main.cpp index ea43a4b..5bdf223 100644 --- a/tests/Ipsec/main.cpp +++ b/tests/Ipsec/main.cpp @@ -302,7 +302,7 @@ int main() { Check(m.text == "ipsec-3gpp;q=0.94;alg=hmac-sha-1-96;mod=trans;spi-c=129427852;spi-s=133937015;port-c=6051;port-s=6060", "O2/null: selected text verbatim"); Check(ss->mechanisms[1].ealg == "des-ede3-cbc" && !ss->mechanisms[1].spiPs, "O2/null: the 3DES entry is parsed but carries no SPIs"); } - // the default offer (EALG=aes-cbc): the spec picks sha1+aes (q=0.98); the SPIs stay with the marked entry + // an offer of aes-cbc alone: sha1+aes (q=0.98) is the offered entry; the SPIs stay with the marked entry auto sa = ParseSecurityServer(O2, "hmac-sha-1-96", {"aes-cbc"}); Check(sa && sa->selected == 5 && sa->offerMatched, "O2/aes: sha1+aes-cbc (q=0.98) selected for the aes offer"); Check(sa && sa->carrier == 3 && sa->Carrier().spiPs == 133937015u && sa->Carrier().portPs == 6060, "O2/aes: SPIs/ports from the entry carrying them"); @@ -333,7 +333,7 @@ int main() { // ---- the offer: EALG as a list, the default when it names nothing { using L = std::vector; - Check(DefaultEalgOffer() == L{"aes-cbc"}, "default offer: aes-cbc"); + Check(DefaultEalgOffer() == L{"aes-cbc", "null"}, "default offer: aes-cbc, then null"); Check(ParseEalgOffer("null").ciphers == L{"null"} && ParseEalgOffer("aes-cbc").ciphers == L{"aes-cbc"}, "EALG: one name is a list of one"); Check(ParseEalgOffer("null,aes-cbc").ciphers == L{"null", "aes-cbc"}, "EALG: the order written is the order offered"); Check(ParseEalgOffer(" AES-CBC ,\tNull ").ciphers == L{"aes-cbc", "null"}, "EALG: case, spaces and tabs ignored"); diff --git a/tests/Messages/main.cpp b/tests/Messages/main.cpp index e08c4da..64ef0c3 100644 --- a/tests/Messages/main.cpp +++ b/tests/Messages/main.cpp @@ -8,7 +8,7 @@ // by the lines of one 180 and by its answers to an INVITE in long and in // compact form). A divergence here is a wire-format change, i.e. a // registration or call that the commercial IMS core may reject; these are the -// hardest pins in the project. Two deliberate post-parity divergences: +// hardest pins in the project. Three deliberate post-parity divergences: // the REGISTER Contact carries +sip.instance and the MMTEL ICSI feature tag // (the Python stack registered without them, which made the network divert // incoming calls to voicemail — see ContactFeatures in Imsd:Messages), and @@ -16,7 +16,9 @@ // TS 24.229 coding and what the stock modem sends on the wire; the Python // stack's plain-colon form is a different string under RFC 3841 matching // and left terminating access-domain selection routing incoming calls to -// CS fallback (observed live 2026-07-20). Then the SMS over IP shapes: the +// CS fallback (observed live 2026-07-20); and the REGISTERs' Security-Client +// carries the default offer's two mechanisms, where the Python stack offered +// one cipher. Then the SMS over IP shapes: the // +g.3gpp.smsip Contact tag behind Context::smsOverIp, the MESSAGE carrying // an RP-DATA to the service centre and the one carrying an RP-ACK to the // IP-SM-GW with In-Reply-To (TS 24.341 5.3.1.2, 5.3.2.4), and a final other @@ -68,7 +70,7 @@ namespace { "Authorization: Digest username=\"001010123456789@ims.mnc001.mcc001.3gppnetwork.org\", realm=\"ims.mnc001.mcc001.3gppnetwork.org\", uri=\"sip:ims.mnc001.mcc001.3gppnetwork.org\", nonce=\"\", response=\"\"\r\n" "Require: sec-agree\r\n" "Proxy-Require: sec-agree\r\n" - "Security-Client: ipsec-3gpp; alg=hmac-sha-1-96; ealg=aes-cbc; spi-c=7449812; spi-s=176466735; port-c=45061; port-s=45062\r\n" + "Security-Client: ipsec-3gpp; alg=hmac-sha-1-96; ealg=aes-cbc; spi-c=7449812; spi-s=176466735; port-c=45061; port-s=45062, ipsec-3gpp; alg=hmac-sha-1-96; ealg=null; spi-c=7449812; spi-s=176466735; port-c=45061; port-s=45062\r\n" "Supported: sec-agree, path\r\n" "Expires: 600000\r\n" "P-Access-Network-Info: 3GPP-E-UTRAN-FDD;utran-cell-id-3gpp=0010112340ABCDE0\r\n" @@ -88,7 +90,7 @@ namespace { "Authorization: Digest username=\"001010123456789@ims.mnc001.mcc001.3gppnetwork.org\", realm=\"ims.mnc001.mcc001.3gppnetwork.org\", uri=\"sip:ims.mnc001.mcc001.3gppnetwork.org\", nonce=\"NONCEXYZ\", qop=auth, nc=00000001, cnonce=\"CNONCE0123456789\", response=\"RESP0000\", algorithm=AKAv1-MD5\r\n" "Require: sec-agree\r\n" "Proxy-Require: sec-agree\r\n" - "Security-Client: ipsec-3gpp; alg=hmac-sha-1-96; ealg=aes-cbc; spi-c=7449812; spi-s=176466735; port-c=45061; port-s=45062\r\n" + "Security-Client: ipsec-3gpp; alg=hmac-sha-1-96; ealg=aes-cbc; spi-c=7449812; spi-s=176466735; port-c=45061; port-s=45062, ipsec-3gpp; alg=hmac-sha-1-96; ealg=null; spi-c=7449812; spi-s=176466735; port-c=45061; port-s=45062\r\n" "Security-Verify: ipsec-3gpp; q=0.1; alg=hmac-sha-1-96; ealg=aes-cbc; spi-c=86438593; spi-s=86438592; port-c=33421; port-s=6000\r\n" "Supported: sec-agree, path\r\n" "Expires: 600000\r\n" @@ -187,7 +189,8 @@ namespace { int main() { Context c = MakeCtx(); - // ---- REGISTER (initial + protected), byte-exact vs Python + // ---- REGISTER (initial + protected), byte-exact (the header of this + // file has what differs from the Python stack's bytes) Eq(BuildRegisterInitial(c, "REGCALLID@2001:db8::db43", "FTAG5678", "REGBRANCH123456", 7449812u, 176466735u), Reg1, "unprotected REGISTER"); @@ -205,7 +208,7 @@ int main() { { std::string auth = AuthAka(c, "NONCEXYZ", "CNONCE0123456789", "RESP0000"); std::string r3 = BuildRegisterProtected(c, "REGCALLID@2001:db8::db43", "FTAG5678", "REGBRANCH123456", 3, 55555u, 66666u, auth, 45063); - Check(r3.contains("\r\nSecurity-Client: ipsec-3gpp; alg=hmac-sha-1-96; ealg=aes-cbc; spi-c=55555; spi-s=66666; port-c=45063; port-s=45062\r\n"), "refresh Security-Client: new SPIs, a new client port, the same server port"); + Check(r3.contains("\r\nSecurity-Client: ipsec-3gpp; alg=hmac-sha-1-96; ealg=aes-cbc; spi-c=55555; spi-s=66666; port-c=45063; port-s=45062, ipsec-3gpp; alg=hmac-sha-1-96; ealg=null; spi-c=55555; spi-s=66666; port-c=45063; port-s=45062\r\n"), "refresh Security-Client: new SPIs, a new client port, the same server port, in both mechanisms"); Check(r3.contains("\r\nCSeq: 3 REGISTER\r\n") && r3.contains("\r\nVia: SIP/2.0/TCP [2001:db8::db43]:45062;") && r3.contains("@[2001:db8::db43]:45062>"), "refresh: CSeq+1, the server port in Via and Contact"); Check(r3.contains(std::format("\r\n{}\r\n", auth)), "refresh carries the last challenge answer verbatim"); std::string r3same = BuildRegisterProtected(c, "REGCALLID@2001:db8::db43", "FTAG5678", "REGBRANCH123456", 3, 55555u, 66666u, auth); @@ -216,6 +219,9 @@ int main() { // every one with the REGISTER's SPIs and ports { Check(c.ealgOffer == imsd::ipsec::DefaultEalgOffer(), "the default context offers the default list"); + Context one = c; + one.ealgOffer = {"aes-cbc"}; + Check(BuildRegisterInitial(one, "REGCALLID@2001:db8::db43", "FTAG5678", "REGBRANCH123456", 7449812u, 176466735u).contains("\r\nSecurity-Client: ipsec-3gpp; alg=hmac-sha-1-96; ealg=aes-cbc; spi-c=7449812; spi-s=176466735; port-c=45061; port-s=45062\r\n"), "one cipher offered: one mechanism, the header as it was before the default offer had two"); Context two = c; two.ealgOffer = {"aes-cbc", "null"}; std::string r1 = BuildRegisterInitial(two, "REGCALLID@2001:db8::db43", "FTAG5678", "REGBRANCH123456", 7449812u, 176466735u);