ipsec: the Security-Verify rebuilt from the kernel's SA names the SA's algorithms

A resume sends the 401's Security-Server list from the state file as its
Security-Verify, and where the file holds none for the pair in the
kernel, one mechanism rebuilt from that pair: its SPIs and ports, with
alg=hmac-sha-1-96 and ealg=aes-cbc written in whatever the pair was
installed with. Over a pair with the null cipher, 3DES or hmac-md5-96
that entry named an algorithm the pair does not use, and RFC 3329 2.3.1
has a server answer a Security-Verify that differs from its own list
with a 494.

ParseExistingSa now reads the two names from the state it takes spi-s
from: `ip xfrm state` prints them on its auth-trunc and enc lines, in
the kernel's names for what imsd installs. A state that prints neither
line, or another name, reads as hmac-sha-1-96 and aes-cbc, as before.

Tested: tests/Ipsec, on the lines `ip xfrm state` prints for the SAs
imsd installs (Linux 7.2, iproute2 7.2).
This commit is contained in:
Jorijn van der Graaf 2026-11-23 10:07:59 +01:00
commit 6b0d6341d3
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
4 changed files with 73 additions and 9 deletions

View file

@ -255,7 +255,9 @@ What the suites pin:
- `Aka` — the AKAv1-MD5 digest, identity derivation, the `qmicli`/`mmcli`
text parsers, the AUTHENTICATE APDU and its response parser.
- `Ipsec` — the exact `ip xfrm` argv lists for the SA pairs, the
Security-Server mechanism selection, the SA reader, the SA peer
Security-Server mechanism selection, the SA reader (the entry it
rebuilds names the pair's integrity algorithm and cipher, read from the
lines the kernel prints for them), the SA peer
(`SaPeer`: the one address a reqid-1 and a reqid-2 `dir out` transport
policy both name with imsd's protected port as the selector's sport — the
fingerprint —, the pair kept beside a VPN's policies;
@ -480,7 +482,10 @@ Rules:
list; KPN's has one mechanism, so on the bench the stored value and the
rebuilt one are the same bytes; O2's six-entry list has not resumed on
this code, and the state-file round trip is shell code no test
reaches); a Security-Server list `PersistState` writes empty (one with
reaches); a resume whose rebuilt entry names another algorithm than
`hmac-sha-1-96` or another cipher than `aes-cbc` (pinned in `tests/Ipsec`
on the lines `ip xfrm state` prints; no such pair has been resumed on a
network); 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
@ -1074,7 +1079,7 @@ The daemon's own bring-up (`BringUp()` in `main.cpp`):
`spi_uc`/`spi_us` are not the pair's, step 3), it sends —
on the resume's re-REGISTER, the keepalive re-REGISTERs, the reg-event
SUBSCRIBE and INVITEs, until its next fresh registration — the one
entry rebuilt from the SA
entry rebuilt from the SA, with the algorithms the kernel prints for it
(`Imsd:Ipsec`, which makes the choice): KPN's one-entry answer to the
default offer in the same bytes, not a list such as O2's six, which RFC 3329 §2.3.1 has the server answer with a
494 when it does not mirror its own; a refused resume registers fresh (with