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:
parent
6b0d6341d3
commit
ed2a009425
7 changed files with 233 additions and 68 deletions
|
|
@ -7,7 +7,8 @@
|
|||
// for the entry it rebuilds, states in the shape a Linux 7.2 `ip xfrm state`
|
||||
// prints, with its line for each algorithm imsd installs, and
|
||||
// the Security-Server parser, fed the operator lines as captured (O2 UK's
|
||||
// six-mechanism Mavenir shape verbatim, KPN's single mechanism).
|
||||
// six-mechanism Mavenir shape verbatim, under a null and under an aes-cbc
|
||||
// offer; KPN's single mechanism; Odido's), and the EALG list.
|
||||
import std;
|
||||
import Imsd;
|
||||
|
||||
|
|
@ -287,7 +288,7 @@ int main() {
|
|||
"ipsec-3gpp;q=0.98;alg=hmac-sha-1-96;mod=trans;ealg=aes-cbc";
|
||||
{
|
||||
// alyx's offer (EALG=null): the entry O2 marked is also the only one matching the offer
|
||||
auto ss = ParseSecurityServer(O2, "hmac-sha-1-96", "null");
|
||||
auto ss = ParseSecurityServer(O2, "hmac-sha-1-96", {"null"});
|
||||
Check(ss.has_value() && ss->mechanisms.size() == 6, "O2/null: six mechanisms");
|
||||
Check(ss && ss->selected == 3 && ss->carrier == 3 && ss->offerMatched, "O2/null: the fourth mechanism (sha1, no ealg, the SPIs) selected, offer matched");
|
||||
if (ss) {
|
||||
|
|
@ -302,43 +303,107 @@ int main() {
|
|||
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
|
||||
auto sa = ParseSecurityServer(O2, "hmac-sha-1-96", "aes-cbc");
|
||||
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");
|
||||
Check(sa && sa->Selected().ealg == "aes-cbc" && sa->Selected().alg == "hmac-sha-1-96", "O2/aes: algorithms from the selected entry");
|
||||
// an offer O2 does not list (3des alias -> des-ede3-cbc): sha1+3des (q=0.96)
|
||||
auto s3 = ParseSecurityServer(O2, "hmac-sha-1-96", "3des");
|
||||
auto s3 = ParseSecurityServer(O2, "hmac-sha-1-96", {"3des"});
|
||||
Check(s3 && s3->selected == 4 && s3->offerMatched && s3->carrier == 3, "O2/3des: the alias matches des-ede3-cbc (q=0.96), SPIs from the marked entry");
|
||||
}
|
||||
// ---- KPN: one mechanism, spaces after the separators, explicit ealg
|
||||
{
|
||||
auto ss = ParseSecurityServer("ipsec-3gpp; q=0.1; alg=hmac-sha-1-96; ealg=aes-cbc; spi-c=49889723; spi-s=49889722; port-c=33142; port-s=6000", "hmac-sha-1-96", "aes-cbc");
|
||||
auto ss = ParseSecurityServer("ipsec-3gpp; q=0.1; alg=hmac-sha-1-96; ealg=aes-cbc; spi-c=49889723; spi-s=49889722; port-c=33142; port-s=6000", "hmac-sha-1-96", {"aes-cbc"});
|
||||
Check(ss && ss->mechanisms.size() == 1 && ss->selected == 0 && ss->carrier == 0 && ss->offerMatched, "KPN: single mechanism selected, offer matched");
|
||||
Check(ss && ss->Selected().alg == "hmac-sha-1-96" && ss->Selected().ealg == "aes-cbc", "KPN: alg + ealg");
|
||||
Check(ss && ss->Selected().spiPc == 49889723u && ss->Selected().spiPs == 49889722u && ss->Selected().portPc == 33142 && ss->Selected().portPs == 6000, "KPN: SPIs + ports");
|
||||
Check(ss && ss->Selected().qMilli == 100, "KPN: q=0.1");
|
||||
auto nul = ParseSecurityServer("ipsec-3gpp; q=0.1; alg=hmac-sha-1-96; ealg=null; spi-c=33998503; spi-s=33998502; port-c=33021; port-s=6000", "hmac-sha-1-96", "null");
|
||||
auto nul = ParseSecurityServer("ipsec-3gpp; q=0.1; alg=hmac-sha-1-96; ealg=null; spi-c=33998503; spi-s=33998502; port-c=33021; port-s=6000", "hmac-sha-1-96", {"null"});
|
||||
Check(nul && nul->Selected().ealg == "null" && nul->offerMatched, "KPN: explicit ealg=null matches the null offer");
|
||||
// the P-CSCF answers a cipher we did not offer: still the only entry, installed as answered, flagged
|
||||
auto other = ParseSecurityServer("ipsec-3gpp; q=0.1; alg=hmac-sha-1-96; ealg=null; spi-c=33998503; spi-s=33998502; port-c=33021; port-s=6000", "hmac-sha-1-96", "aes-cbc");
|
||||
auto other = ParseSecurityServer("ipsec-3gpp; q=0.1; alg=hmac-sha-1-96; ealg=null; spi-c=33998503; spi-s=33998502; port-c=33021; port-s=6000", "hmac-sha-1-96", {"aes-cbc"});
|
||||
Check(other && other->selected == 0 && other->carrier == 0 && !other->offerMatched, "single entry not matching the offer: selected via the spi-s fallback, offerMatched=false");
|
||||
// the fresh-SA throttle answer: spi-s present and zero
|
||||
auto thr = ParseSecurityServer("ipsec-3gpp; q=0.1; alg=hmac-sha-1-96; ealg=aes-cbc; spi-c=1; spi-s=0; port-c=33102; port-s=6000", "hmac-sha-1-96", "aes-cbc");
|
||||
auto thr = ParseSecurityServer("ipsec-3gpp; q=0.1; alg=hmac-sha-1-96; ealg=aes-cbc; spi-c=1; spi-s=0; port-c=33102; port-s=6000", "hmac-sha-1-96", {"aes-cbc"});
|
||||
Check(thr && thr->Carrier().spiPs.has_value() && *thr->Carrier().spiPs == 0, "KPN throttle: spi-s=0 is present, not absent");
|
||||
// no SPIs anywhere: parsed, nothing to build from
|
||||
auto bare = ParseSecurityServer("ipsec-3gpp; q=0.1; alg=hmac-sha-1-96; ealg=null;", "hmac-sha-1-96", "null");
|
||||
auto bare = ParseSecurityServer("ipsec-3gpp; q=0.1; alg=hmac-sha-1-96; ealg=null;", "hmac-sha-1-96", {"null"});
|
||||
Check(bare && bare->mechanisms.size() == 1 && bare->offerMatched && !bare->Carrier().spiPs && !bare->Carrier().portPs, "no spi-s: absent, not zero");
|
||||
}
|
||||
// ---- the offer: EALG as a list, the default when it names nothing
|
||||
{
|
||||
using L = std::vector<std::string>;
|
||||
Check(DefaultEalgOffer() == L{"aes-cbc"}, "default offer: aes-cbc");
|
||||
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");
|
||||
Check(ParseEalgOffer("3des").ciphers == L{"des-ede3-cbc"} && ParseEalgOffer("des-ede3-cbc,3DES").ciphers == L{"des-ede3-cbc"}, "EALG: 3des is des-ede3-cbc, a repeat dropped");
|
||||
auto mixed = ParseEalgOffer("aes-gcm,null, HMAC-SHA-1-96,aes-gcm");
|
||||
Check(mixed.ciphers == L{"null"} && mixed.unknown == L{"aes-gcm", "hmac-sha-1-96"}, "EALG: a name imsd cannot install goes to unknown, once, in lower case without spaces");
|
||||
Check(ParseEalgOffer("").ciphers == DefaultEalgOffer() && ParseEalgOffer("").unknown.empty() && ParseEalgOffer(" , ,").ciphers == DefaultEalgOffer() && ParseEalgOffer(" , ,").unknown.empty(), "EALG: empty or blank elements name nothing: the default offer");
|
||||
Check(ParseEalgOffer("aes-gcm").ciphers == DefaultEalgOffer() && ParseEalgOffer("aes-gcm").unknown == L{"aes-gcm"}, "EALG: no known name -> the default offer, the name in unknown");
|
||||
Check(ParseEalgOffer("aes-cbc,").ciphers == L{"aes-cbc"} && ParseEalgOffer("aes-cbc,").unknown.empty(), "EALG: an empty element is no name, not the null cipher");
|
||||
}
|
||||
// ---- selection against more than one offered cipher
|
||||
{
|
||||
const std::vector<std::string> both = {"aes-cbc", "null"};
|
||||
// KPN's answer: one entry
|
||||
auto kpn = ParseSecurityServer("ipsec-3gpp; q=0.1; alg=hmac-sha-1-96; ealg=aes-cbc; spi-c=49889723; spi-s=49889722; port-c=33142; port-s=6000", "hmac-sha-1-96", both);
|
||||
Check(kpn && kpn->selected == 0 && kpn->offerMatched && kpn->Selected().ealg == "aes-cbc", "both offered, KPN's aes-cbc entry: selected, offer matched");
|
||||
// Odido's answer to an offer of the null cipher (2026-07-13), verbatim
|
||||
auto odido = ParseSecurityServer("ipsec-3gpp; q=0.1; alg=hmac-sha-1-96; ealg=null; spi-c=30890423; spi-s=30890422; port-c=32997; port-s=6000", "hmac-sha-1-96", both);
|
||||
Check(odido && odido->selected == 0 && odido->offerMatched && NormalizeEalg(odido->Selected().ealg) == "null" && odido->Carrier().spiPs == 30890422u, "both offered, Odido's null entry: selected, offer matched");
|
||||
// O2's list as it answered a null offer: the SPIs on sha1/null (q=0.94). With
|
||||
// both ciphers offered that marked entry is taken, not sha1/aes-cbc (q=0.98)
|
||||
auto o2null = ParseSecurityServer(O2, "hmac-sha-1-96", both);
|
||||
Check(o2null && o2null->selected == 3 && o2null->carrier == 3 && o2null->offerMatched, "both offered, O2's list marking sha1/null: the marked entry, not the higher-q sha1/aes-cbc");
|
||||
Check(o2null && NormalizeEalg(o2null->Selected().ealg) == "null" && o2null->Selected().alg == "hmac-sha-1-96", "both offered, O2 marking sha1/null: the selected entry is sha1 with the null cipher");
|
||||
// O2's list as it answered an aes-cbc offer (alyx report 14, 2026-09-20), verbatim: the SPIs on sha1/aes-cbc
|
||||
constexpr std::string_view O2Aes =
|
||||
"ipsec-3gpp;q=0.88;alg=hmac-md5-96;mod=trans,"
|
||||
"ipsec-3gpp;q=0.9;alg=hmac-md5-96;mod=trans;ealg=des-ede3-cbc,"
|
||||
"ipsec-3gpp;q=0.92;alg=hmac-md5-96;mod=trans;ealg=aes-cbc,"
|
||||
"ipsec-3gpp;q=0.94;alg=hmac-sha-1-96;mod=trans,"
|
||||
"ipsec-3gpp;q=0.96;alg=hmac-sha-1-96;mod=trans;ealg=des-ede3-cbc,"
|
||||
"ipsec-3gpp;q=0.98;alg=hmac-sha-1-96;mod=trans;ealg=aes-cbc;spi-c=53871876;spi-s=58749351;port-c=6058;port-s=6060";
|
||||
auto o2aes = ParseSecurityServer(O2Aes, "hmac-sha-1-96", both);
|
||||
Check(o2aes && o2aes->selected == 5 && o2aes->carrier == 5 && o2aes->offerMatched && o2aes->Selected().ealg == "aes-cbc", "both offered, O2's list marking sha1/aes-cbc: that entry");
|
||||
Check(ParseSecurityServer(O2Aes, "hmac-sha-1-96", {"aes-cbc"})->selected == 5 && ParseSecurityServer(O2Aes, "hmac-sha-1-96", {"null"})->selected == 3, "one cipher offered: the entry of that cipher, marked or not");
|
||||
// the marked entry is one we did not offer (md5): the highest-q offered entry, its SPIs
|
||||
auto md5marked = ParseSecurityServer("ipsec-3gpp;q=0.5;alg=hmac-sha-1-96;ealg=aes-cbc,ipsec-3gpp;q=0.4;alg=hmac-sha-1-96,ipsec-3gpp;q=0.9;alg=hmac-md5-96;ealg=aes-cbc;spi-c=5;spi-s=6;port-c=7;port-s=8", "hmac-sha-1-96", both);
|
||||
Check(md5marked && md5marked->selected == 0 && md5marked->carrier == 2 && md5marked->offerMatched, "both offered, the marked entry not offered: the highest-q offered entry, SPIs from the marked one");
|
||||
// every entry carries the SPIs: nothing is marked — the highest q, without q the first
|
||||
auto listq = ParseSecurityServer("ipsec-3gpp;q=0.4;alg=hmac-sha-1-96;ealg=null;spi-c=1;spi-s=2;port-c=3;port-s=4,ipsec-3gpp;q=0.5;alg=hmac-sha-1-96;ealg=aes-cbc;spi-c=1;spi-s=2;port-c=3;port-s=4", "hmac-sha-1-96", both);
|
||||
Check(listq && listq->selected == 1 && listq->carrier == 1 && listq->offerMatched, "both offered, both entries carry the SPIs: the highest q");
|
||||
auto listfirst = ParseSecurityServer("ipsec-3gpp;alg=hmac-sha-1-96;ealg=null;spi-c=1;spi-s=2;port-c=3;port-s=4,ipsec-3gpp;alg=hmac-sha-1-96;ealg=aes-cbc;spi-c=1;spi-s=2;port-c=3;port-s=4", "hmac-sha-1-96", both);
|
||||
Check(listfirst && listfirst->selected == 0 && listfirst->offerMatched, "both offered, both entries carry the SPIs, no q: the first on the list");
|
||||
// neither offered cipher listed: the P-CSCF's entry, flagged
|
||||
auto neither = ParseSecurityServer("ipsec-3gpp; q=0.1; alg=hmac-sha-1-96; ealg=des-ede3-cbc; spi-c=1; spi-s=2; port-c=3; port-s=4", "hmac-sha-1-96", both);
|
||||
Check(neither && neither->selected == 0 && !neither->offerMatched, "both offered, a 3DES answer: taken via the spi-s fallback, offerMatched=false");
|
||||
// the marked entry over a higher-q offered one also under one offered cipher (same algorithms, the entry's own mod)
|
||||
auto onecipher = ParseSecurityServer("ipsec-3gpp;q=0.9;alg=hmac-sha-1-96;ealg=aes-cbc;mod=tun,ipsec-3gpp;q=0.5;alg=hmac-sha-1-96;ealg=aes-cbc;mod=trans;spi-c=1;spi-s=2;port-c=3;port-s=4", "hmac-sha-1-96", {"aes-cbc"});
|
||||
Check(onecipher && onecipher->selected == 1 && onecipher->Selected().mod == "trans", "one cipher offered, two entries of it: the marked one");
|
||||
// the resume's choice under the same offer: O2's stored list, and a list whose two entries carry SPIs of their own
|
||||
ExistingSa sa;
|
||||
sa.spiPc = 129427852u; sa.spiPs = 133937015u; sa.portPc = 6051; sa.portPs = 6060;
|
||||
sa.securityServer = "ipsec-3gpp; q=0.1; alg=hmac-sha-1-96; ealg=aes-cbc; spi-c=129427852; spi-s=133937015; port-c=6051; port-s=6060";
|
||||
auto rsv = ChooseResumeSecurityVerify(O2, sa, both);
|
||||
Check(rsv.source == ResumeSecurityVerify::Source::Stored && rsv.value == O2 && rsv.mechanisms == 6, "resume, both offered: O2's stored list for the kernel's pair");
|
||||
constexpr std::string_view TwoPairs = "ipsec-3gpp;q=0.9;alg=hmac-sha-1-96;ealg=null;spi-c=1;spi-s=2;port-c=3;port-s=4,ipsec-3gpp;q=0.5;alg=hmac-sha-1-96;ealg=aes-cbc;spi-c=5;spi-s=6;port-c=7;port-s=8";
|
||||
ExistingSa aesPair;
|
||||
aesPair.spiPc = 5; aesPair.spiPs = 6; aesPair.portPc = 7; aesPair.portPs = 8;
|
||||
Check(ChooseResumeSecurityVerify(TwoPairs, aesPair, {"aes-cbc"}).source == ResumeSecurityVerify::Source::Stored && ChooseResumeSecurityVerify(TwoPairs, aesPair, both).source == ResumeSecurityVerify::Source::OtherSa, "resume: the offer handed in decides which entry's SPIs are held against the kernel's pair");
|
||||
}
|
||||
// ---- the resume's Security-Verify: the stored list only for the SA pair the kernel holds
|
||||
{
|
||||
using Source = ResumeSecurityVerify::Source;
|
||||
ExistingSa sa;
|
||||
sa.spiPc = 129427852u; sa.spiPs = 133937015u; sa.portPc = 6051; sa.portPs = 6060;
|
||||
sa.securityServer = "ipsec-3gpp; q=0.1; alg=hmac-sha-1-96; ealg=aes-cbc; spi-c=129427852; spi-s=133937015; port-c=6051; port-s=6060";
|
||||
auto ok = ChooseResumeSecurityVerify(O2, sa, "null");
|
||||
auto ok = ChooseResumeSecurityVerify(O2, sa, {"null"});
|
||||
Check(ok.source == Source::Stored && ok.value == O2 && ok.mechanisms == 6, "resume: O2's six-entry list whose carrier is the kernel's pair -> the list verbatim, six mechanisms");
|
||||
auto okAes = ChooseResumeSecurityVerify(O2, sa, "aes-cbc");
|
||||
Check(okAes.source == Source::Stored && okAes.value == O2, "resume: the same under the aes offer (the carrier does not depend on the offer)");
|
||||
auto okAes = ChooseResumeSecurityVerify(O2, sa, {"aes-cbc"});
|
||||
Check(okAes.source == Source::Stored && okAes.value == O2, "resume: the same under the aes offer (O2's list has one carrier)");
|
||||
constexpr std::pair<std::string_view, std::string_view> off[] = {
|
||||
{"spi-c", "ipsec-3gpp;q=0.94;alg=hmac-sha-1-96;mod=trans;spi-c=129427853;spi-s=133937015;port-c=6051;port-s=6060"},
|
||||
{"spi-s", "ipsec-3gpp;q=0.94;alg=hmac-sha-1-96;mod=trans;spi-c=129427852;spi-s=133937016;port-c=6051;port-s=6060"},
|
||||
|
|
@ -346,19 +411,19 @@ int main() {
|
|||
{"port-s", "ipsec-3gpp;q=0.94;alg=hmac-sha-1-96;mod=trans;spi-c=129427852;spi-s=133937015;port-c=6051;port-s=6061"},
|
||||
};
|
||||
for (const auto& [field, text] : off) {
|
||||
auto r = ChooseResumeSecurityVerify(text, sa, "null");
|
||||
auto r = ChooseResumeSecurityVerify(text, sa, {"null"});
|
||||
Check(r.source == Source::OtherSa && r.value == sa.securityServer, std::format("resume: {} off by one -> the rebuilt entry", field));
|
||||
}
|
||||
auto offSpiS = ChooseResumeSecurityVerify(off[1].second, sa, "null");
|
||||
auto offSpiS = ChooseResumeSecurityVerify(off[1].second, sa, {"null"});
|
||||
Check(offSpiS.storedSpiPs && *offSpiS.storedSpiPs == 133937016u, "resume: the stored spi-s is reported for the log line");
|
||||
auto none = ChooseResumeSecurityVerify("", sa, "null");
|
||||
auto none = ChooseResumeSecurityVerify("", sa, {"null"});
|
||||
Check(none.source == Source::NoneStored && none.value == sa.securityServer, "resume: nothing stored -> the rebuilt entry");
|
||||
auto junk = ChooseResumeSecurityVerify("not a list", sa, "null");
|
||||
auto junk = ChooseResumeSecurityVerify("not a list", sa, {"null"});
|
||||
Check(junk.source == Source::OtherSa && junk.value == sa.securityServer && !junk.storedSpiPs, "resume: an unparseable value -> the rebuilt entry, no spi-s to report");
|
||||
ExistingSa kpn;
|
||||
kpn.spiPc = 49889723u; kpn.spiPs = 49889722u; kpn.portPc = 33142; kpn.portPs = 6000;
|
||||
kpn.securityServer = "ipsec-3gpp; q=0.1; alg=hmac-sha-1-96; ealg=aes-cbc; spi-c=49889723; spi-s=49889722; port-c=33142; port-s=6000";
|
||||
auto k = ChooseResumeSecurityVerify(kpn.securityServer, kpn, "aes-cbc");
|
||||
auto k = ChooseResumeSecurityVerify(kpn.securityServer, kpn, {"aes-cbc"});
|
||||
Check(k.source == Source::Stored && k.value == kpn.securityServer && k.mechanisms == 1, "resume: KPN's one-entry list for its pair -> the list, one mechanism");
|
||||
}
|
||||
// ---- a state file another attempt left behind: the file's UE SPIs against the kernel pair's
|
||||
|
|
@ -373,41 +438,41 @@ int main() {
|
|||
// ---- selection rules and syntax corners
|
||||
{
|
||||
// spec-shaped list: every entry carries the SPI set, md5 preferred by q — we offered sha1, so sha1 wins (audit A1)
|
||||
auto a1 = ParseSecurityServer("ipsec-3gpp;q=0.1;alg=hmac-sha-1-96;ealg=aes-cbc;spi-c=11;spi-s=12;port-c=13;port-s=14,ipsec-3gpp;q=0.2;alg=hmac-md5-96;ealg=aes-cbc;spi-c=11;spi-s=12;port-c=13;port-s=14", "hmac-sha-1-96", "aes-cbc");
|
||||
auto a1 = ParseSecurityServer("ipsec-3gpp;q=0.1;alg=hmac-sha-1-96;ealg=aes-cbc;spi-c=11;spi-s=12;port-c=13;port-s=14,ipsec-3gpp;q=0.2;alg=hmac-md5-96;ealg=aes-cbc;spi-c=11;spi-s=12;port-c=13;port-s=14", "hmac-sha-1-96", {"aes-cbc"});
|
||||
Check(a1 && a1->selected == 0 && a1->offerMatched && a1->Selected().alg == "hmac-sha-1-96", "every entry carries SPIs, md5 preferred: the offered sha1 is selected, not the highest q");
|
||||
// two sha1 entries with different ciphers, both carrying SPIs: the offered cipher wins over q (audit A3)
|
||||
auto a3 = ParseSecurityServer("ipsec-3gpp;q=0.9;alg=hmac-sha-1-96;ealg=des-ede3-cbc;spi-c=1;spi-s=2;port-c=3;port-s=4,ipsec-3gpp;q=0.8;alg=hmac-sha-1-96;ealg=aes-cbc;spi-c=5;spi-s=6;port-c=7;port-s=8", "hmac-sha-1-96", "aes-cbc");
|
||||
auto a3 = ParseSecurityServer("ipsec-3gpp;q=0.9;alg=hmac-sha-1-96;ealg=des-ede3-cbc;spi-c=1;spi-s=2;port-c=3;port-s=4,ipsec-3gpp;q=0.8;alg=hmac-sha-1-96;ealg=aes-cbc;spi-c=5;spi-s=6;port-c=7;port-s=8", "hmac-sha-1-96", {"aes-cbc"});
|
||||
Check(a3 && a3->selected == 1 && a3->Carrier().spiPs == 6u, "offered cipher wins over a higher-q cipher we did not offer");
|
||||
// two matching entries: the higher q
|
||||
auto two = ParseSecurityServer("ipsec-3gpp;q=0.5;alg=hmac-sha-1-96;ealg=aes-cbc;spi-c=1;spi-s=2;port-c=3;port-s=4,ipsec-3gpp;q=0.9;alg=hmac-sha-1-96;ealg=aes-cbc;spi-c=5;spi-s=6;port-c=7;port-s=8", "hmac-sha-1-96", "aes-cbc");
|
||||
auto two = ParseSecurityServer("ipsec-3gpp;q=0.5;alg=hmac-sha-1-96;ealg=aes-cbc;spi-c=1;spi-s=2;port-c=3;port-s=4,ipsec-3gpp;q=0.9;alg=hmac-sha-1-96;ealg=aes-cbc;spi-c=5;spi-s=6;port-c=7;port-s=8", "hmac-sha-1-96", {"aes-cbc"});
|
||||
Check(two && two->selected == 1 && two->Selected().spiPs == 6u, "two matching entries: highest q selected");
|
||||
// nothing matches the offer (md5-only list): fallback = the highest-q carrier, flagged
|
||||
auto md5 = ParseSecurityServer("ipsec-3gpp;q=0.5;alg=hmac-md5-96;spi-c=1;spi-s=2;port-c=3;port-s=4,ipsec-3gpp;q=0.9;alg=hmac-md5-96;ealg=aes-cbc;spi-c=5;spi-s=6;port-c=7;port-s=8", "hmac-sha-1-96", "aes-cbc");
|
||||
auto md5 = ParseSecurityServer("ipsec-3gpp;q=0.5;alg=hmac-md5-96;spi-c=1;spi-s=2;port-c=3;port-s=4,ipsec-3gpp;q=0.9;alg=hmac-md5-96;ealg=aes-cbc;spi-c=5;spi-s=6;port-c=7;port-s=8", "hmac-sha-1-96", {"aes-cbc"});
|
||||
Check(md5 && md5->selected == 1 && !md5->offerMatched && md5->carrier == 1, "no match: highest-q carrier, offerMatched=false");
|
||||
// no q at all, nothing matching: the first carrier
|
||||
auto noq = ParseSecurityServer("ipsec-3gpp;alg=hmac-md5-96;spi-c=1;spi-s=2;port-c=3;port-s=4,ipsec-3gpp;alg=hmac-md5-96;ealg=aes-cbc;spi-c=5;spi-s=6;port-c=7;port-s=8", "hmac-sha-1-96", "aes-cbc");
|
||||
auto noq = ParseSecurityServer("ipsec-3gpp;alg=hmac-md5-96;spi-c=1;spi-s=2;port-c=3;port-s=4,ipsec-3gpp;alg=hmac-md5-96;ealg=aes-cbc;spi-c=5;spi-s=6;port-c=7;port-s=8", "hmac-sha-1-96", {"aes-cbc"});
|
||||
Check(noq && noq->selected == 0 && !noq->offerMatched, "no q, no match: first carrier");
|
||||
// absent alg on the entry counts as the offered one
|
||||
auto noalg = ParseSecurityServer("ipsec-3gpp;ealg=aes-cbc;spi-c=1;spi-s=2;port-c=3;port-s=4", "hmac-sha-1-96", "aes-cbc");
|
||||
auto noalg = ParseSecurityServer("ipsec-3gpp;ealg=aes-cbc;spi-c=1;spi-s=2;port-c=3;port-s=4", "hmac-sha-1-96", {"aes-cbc"});
|
||||
Check(noalg && noalg->offerMatched, "absent alg matches the offer");
|
||||
// only non-ipsec mechanisms: nothing for us
|
||||
Check(!ParseSecurityServer("tls;q=0.2,digest;d-alg=MD5", "hmac-sha-1-96", "aes-cbc").has_value(), "tls/digest only -> nullopt");
|
||||
Check(!ParseSecurityServer("tls;q=0.2,digest;d-alg=MD5", "hmac-sha-1-96", {"aes-cbc"}).has_value(), "tls/digest only -> nullopt");
|
||||
// a quoted comma must not split the list; tokens are case-insensitive
|
||||
auto q = ParseSecurityServer("digest;d-alg=MD5;d-qop=\"auth,auth-int\",IPSEC-3GPP; ALG=HMAC-SHA-1-96; EALG=AES-CBC; SPI-C=11; SPI-S=12; PORT-C=13; PORT-S=14", "HMAC-SHA-1-96", "AES-CBC");
|
||||
auto q = ParseSecurityServer("digest;d-alg=MD5;d-qop=\"auth,auth-int\",IPSEC-3GPP; ALG=HMAC-SHA-1-96; EALG=AES-CBC; SPI-C=11; SPI-S=12; PORT-C=13; PORT-S=14", "HMAC-SHA-1-96", {"AES-CBC"});
|
||||
Check(q && q->mechanisms.size() == 2 && q->mechanisms[0].name == "digest", "quoted comma stays inside the digest mechanism");
|
||||
Check(q && q->selected == 1 && q->offerMatched && q->Selected().name == "ipsec-3gpp" && q->Selected().alg == "hmac-sha-1-96" && q->Selected().ealg == "aes-cbc" && q->Selected().spiPs == 12u && q->Selected().portPs == 14, "case-insensitive names and values, lower-cased; offer compared case-insensitively");
|
||||
// prot/mod parsed for the caller to refuse
|
||||
auto tun = ParseSecurityServer("ipsec-3gpp;alg=hmac-sha-1-96;ealg=aes-cbc;prot=ah;mod=tun;spi-c=1;spi-s=2;port-c=3;port-s=4", "hmac-sha-1-96", "aes-cbc");
|
||||
auto tun = ParseSecurityServer("ipsec-3gpp;alg=hmac-sha-1-96;ealg=aes-cbc;prot=ah;mod=tun;spi-c=1;spi-s=2;port-c=3;port-s=4", "hmac-sha-1-96", {"aes-cbc"});
|
||||
Check(tun && tun->Selected().prot == "ah" && tun->Selected().mod == "tun", "prot/mod parsed");
|
||||
// spi-s beyond 32 bits, a port beyond 16 bits or zero: absent, not garbage
|
||||
auto bad = ParseSecurityServer("ipsec-3gpp;alg=hmac-sha-1-96;ealg=aes-cbc;spi-c=1;spi-s=4294967296;port-c=0;port-s=70000", "hmac-sha-1-96", "aes-cbc");
|
||||
auto bad = ParseSecurityServer("ipsec-3gpp;alg=hmac-sha-1-96;ealg=aes-cbc;spi-c=1;spi-s=4294967296;port-c=0;port-s=70000", "hmac-sha-1-96", {"aes-cbc"});
|
||||
Check(bad && !bad->Selected().spiPs && !bad->Selected().portPs && !bad->Selected().portPc && bad->Selected().spiPc == 1u, "out-of-range spi-s/port-s and port 0 are absent");
|
||||
// q syntax
|
||||
auto q1 = ParseSecurityServer("ipsec-3gpp;q=1;spi-s=1", "hmac-sha-1-96", "null");
|
||||
auto q1 = ParseSecurityServer("ipsec-3gpp;q=1;spi-s=1", "hmac-sha-1-96", {"null"});
|
||||
Check(q1 && q1->Selected().qMilli == 1000, "q=1 -> 1000");
|
||||
auto qx = ParseSecurityServer("ipsec-3gpp;q=x;spi-s=1", "hmac-sha-1-96", "null");
|
||||
auto qx = ParseSecurityServer("ipsec-3gpp;q=x;spi-s=1", "hmac-sha-1-96", {"null"});
|
||||
Check(qx && !qx->Selected().qMilli, "q=x -> no q");
|
||||
Check(!ParseSecurityServer("", "hmac-sha-1-96", "null").has_value() && !ParseSecurityServer(" , ", "hmac-sha-1-96", "null").has_value(), "empty value -> nullopt");
|
||||
Check(!ParseSecurityServer("", "hmac-sha-1-96", {"null"}).has_value() && !ParseSecurityServer(" , ", "hmac-sha-1-96", {"null"}).has_value(), "empty value -> nullopt");
|
||||
Check(NormalizeEalg("") == "null" && NormalizeEalg("3des") == "des-ede3-cbc" && NormalizeEalg("aes-cbc") == "aes-cbc", "NormalizeEalg");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -212,6 +212,24 @@ int main() {
|
|||
Check(r3same.contains("port-c=45061; port-s=45062\r\n"), "without a client port the in-use one is offered (the initial registration's second REGISTER)");
|
||||
}
|
||||
|
||||
// ---- the offer: one mechanism per offered cipher, in the list's order,
|
||||
// every one with the REGISTER's SPIs and ports
|
||||
{
|
||||
Check(c.ealgOffer == imsd::ipsec::DefaultEalgOffer(), "the default context offers the default list");
|
||||
Context two = c;
|
||||
two.ealgOffer = {"aes-cbc", "null"};
|
||||
std::string r1 = BuildRegisterInitial(two, "REGCALLID@2001:db8::db43", "FTAG5678", "REGBRANCH123456", 7449812u, 176466735u);
|
||||
Check(r1.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, ipsec-3gpp; alg=hmac-sha-1-96; ealg=null; spi-c=7449812; spi-s=176466735; port-c=45061; port-s=45062\r\n"), "two ciphers offered: two mechanisms in one Security-Client");
|
||||
std::string auth = AuthAka(two, "NONCEXYZ", "CNONCE0123456789", "RESP0000");
|
||||
std::string r2 = BuildRegisterProtected(two, "REGCALLID@2001:db8::db43", "FTAG5678", "REGBRANCH123456", 2, 7449812u, 176466735u, auth);
|
||||
Check(r2.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, ipsec-3gpp; alg=hmac-sha-1-96; ealg=null; spi-c=7449812; spi-s=176466735; port-c=45061; port-s=45062\r\n"), "the protected REGISTER repeats the initial one's Security-Client (TS 33.203 Annex H)");
|
||||
std::string r3 = BuildRegisterProtected(two, "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, ipsec-3gpp; alg=hmac-sha-1-96; ealg=null; spi-c=55555; spi-s=66666; port-c=45063; port-s=45062\r\n"), "a reregistration's new SPIs and client port in every mechanism");
|
||||
two.ealgOffer = {"null", "des-ede3-cbc"};
|
||||
std::string r4 = BuildRegisterInitial(two, "REGCALLID@2001:db8::db43", "FTAG5678", "REGBRANCH123456", 7449812u, 176466735u);
|
||||
Check(r4.contains("\r\nSecurity-Client: ipsec-3gpp; alg=hmac-sha-1-96; ealg=null; spi-c=7449812; spi-s=176466735; port-c=45061; port-s=45062, ipsec-3gpp; alg=hmac-sha-1-96; ealg=des-ede3-cbc; spi-c=7449812; spi-s=176466735; port-c=45061; port-s=45062\r\n"), "the list's order is the header's order");
|
||||
}
|
||||
|
||||
// ---- protected-leg transport follows Context.transport (SIP_TRANSPORT=udp,
|
||||
// or the auto fallback): every protected request's Via says UDP, the
|
||||
// challenge's Via stays UDP either way, and TCP is the untouched default.
|
||||
|
|
|
|||
Loading…
Reference in a new issue