ipsec, messages, imsd: the offered ESP ciphers are a list

imsd's Security-Client held one mechanism, its cipher the value of EALG,
aes-cbc when unset. TS 33.203 7.2 has the UE's first REGISTER carry "a
list of identifiers for the integrity and encryption algorithms, which
the UE supports", and imsd can install three ciphers: an offer of one
could not say so.

EALG is now a comma-separated list, offered in the order written: one
mechanism per cipher in a single Security-Client, each with the
REGISTER's SPIs and ports (7.2 NOTE 1, NOTE 2). The default stays
aes-cbc alone. A name imsd cannot install is ignored with a journal
line where it used to go out as written, `3des` is offered as
des-ede3-cbc, RFC 3329's name for it, a setting that names no cipher
gives the default, and the bring-up logs what is offered (`ESP ciphers
offered: …`).

An offer of more than one cipher needs a further rule for the 401's
list. O2 UK's P-CSCF lists six mechanisms and puts the SPIs on one: the
sha1 entry without a cipher for a null offer, the sha1 entry with
aes-cbc for an aes-cbc offer (2026-09-17, 2026-09-20). The second has
the higher q, so with both ciphers offered the highest-q offered entry
and the entry carrying the SPIs can be two entries. The entry carrying
the SPIs is therefore taken when it is the only such entry and one of
the offer; otherwise the highest-q offered entry, as before. With one
cipher offered the two name the same algorithms; they can differ in mod
or prot, and there the marked entry's are now taken, where 1.2.1 took
the highest-q entry's.

Tested: tests/Ipsec (the setting; the selection against two offered
ciphers) and tests/Messages (a Security-Client of two mechanisms); the
daemon of this commit against a stand-in P-CSCF on the workstation, with
one cipher offered and with two.
This commit is contained in:
Jorijn van der Graaf 2026-11-23 10:08:04 +01:00
commit ed2a009425
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
7 changed files with 233 additions and 68 deletions

View file

@ -1380,7 +1380,15 @@ public:
outDir_ = EnvOr("OUT_DIR", StateDir());
rtpPort_ = std::atoi(EnvOr("RTP_PORT", "50004").c_str());
precond_ = EnvOr("PRECOND", "0") == "1";
ealgOffer_ = EnvOr("EALG", "aes-cbc");
// EALG: the ESP ciphers Security-Client offers, in the order
// written (imsd::ipsec::ParseEalgOffer: with no cipher named, the
// default list). A name imsd cannot install is passed over with a
// line.
{
imsd::ipsec::EalgSetting ealg = imsd::ipsec::ParseEalgOffer(EnvOr("EALG", ""));
for (const std::string& u : ealg.unknown) Log(std::format("EALG entry '{}' is not a cipher imsd can install; ignored", u));
ealgOffer_ = std::move(ealg.ciphers);
}
// SIP_TRANSPORT: the protected leg's transport. auto (default) = TCP,
// and when the P-CSCF never answers the TCP connect, a fresh
// registration over UDP; tcp / udp force one. The challenge (first
@ -1650,7 +1658,8 @@ private:
}
// config
std::string pcscf_, dev_, outDir_, local_, ealgOffer_, mediaBin_;
std::string pcscf_, dev_, outDir_, local_, mediaBin_;
std::vector<std::string> ealgOffer_; // the ESP ciphers offered, in order
// The P-CSCF a fresh registration goes to (PCSCF=, else the first of
// PCSCF_DISCOVERED=) and the whole discovered list. pcscf_ is the one in
// use: the same, or the kernel's SA peer while a resumed registration
@ -1795,6 +1804,11 @@ private:
ctx_.ealgOffer = ealgOffer_;
SetTransport(transport_);
Log(std::format("SIP transport: {} ({})", TransportName(transport_), sipPolicy_));
{
std::string list;
for (const std::string& e : ealgOffer_) list += (list.empty() ? "" : ", ") + e;
Log(std::format("ESP ciphers offered: {}", list));
}
// USER_AGENT overrides (some networks fingerprint UAs — setting the
// stock firmware's build string gives oracle parity, journal/ims.md
// s53); USER_AGENT= (empty) omits the header.
@ -2095,8 +2109,8 @@ private:
ss_ += line;
}
Log(std::format("Security-Server: {}", ss_));
// Algorithms from the mechanism we select against our offer (RFC
// 3329 §2.3.1), SPIs/ports from the entry carrying them (O2 lists
// Algorithms from the mechanism ParseSecurityServer selects against
// our offer, SPIs/ports from the entry carrying them (O2 lists
// six and marks one; ims ledger F11). An answer we cannot use is a
// deferral on the throttle schedule, not a fatal: a fatal restarts
// imsd every RestartSec, an initial REGISTER each time.