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:
parent
2ec2426597
commit
6b0d6341d3
4 changed files with 73 additions and 9 deletions
|
|
@ -3,7 +3,9 @@
|
|||
|
||||
// Imsd:Ipsec unit tests — the `ip xfrm` setup command sequence (byte-exact
|
||||
// argv), the warm-SA reader, fed `ip xfrm state`/`policy` output in the
|
||||
// exact shape captured from a registered FP6 (addresses/keys synthetic), and
|
||||
// exact shape captured from a registered FP6 (addresses/keys synthetic) and,
|
||||
// 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).
|
||||
import std;
|
||||
|
|
@ -77,6 +79,42 @@ int main() {
|
|||
Check(sa && sa->spiPc == 0x0526f2c1u, "spi_pc (UE->P reqid2)");
|
||||
Check(sa && sa->securityServer == "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", "reconstructed Security-Server value");
|
||||
}
|
||||
// the rebuilt entry names the pair's own algorithms: the state towards
|
||||
// the P-CSCF's server port as `ip xfrm state` prints it for each
|
||||
// algorithm imsd installs (the null cipher has no key: a trailing space)
|
||||
{
|
||||
constexpr std::string_view Sha1 = "\tauth-trunc hmac(sha1) 0x00112233445566778899aabbccddeeff 96\n";
|
||||
constexpr std::string_view Md5 = "\tauth-trunc hmac(md5) 0x00112233445566778899aabbccddeeff 96\n";
|
||||
constexpr std::string_view Aes = "\tenc cbc(aes) 0xffeeddccbbaa99887766554433221100\n";
|
||||
constexpr std::string_view Null = "\tenc ecb(cipher_null) \n";
|
||||
constexpr std::string_view Des3 = "\tenc cbc(des3_ede) 0xffeeddccbbaa99887766554433221100ffeeddccbbaa9988\n";
|
||||
// `first` is the reqid-1 state's two lines (the state that gives spi-s),
|
||||
// `second` the reqid-2 state's
|
||||
auto rebuilt = [](std::string_view first, std::string_view second, bool reqid1Listed1st = false) {
|
||||
auto block = [](std::string_view spi, int reqid, std::string_view lines) {
|
||||
return std::format(
|
||||
"src 2001:db8:1111:2222:3333:4444:5555:db43 dst 2001:db8::105\n"
|
||||
"\tproto esp spi {} reqid {} mode transport\n"
|
||||
"\treplay-window 0 \n"
|
||||
"{}"
|
||||
"\tanti-replay context: seq 0x0, oseq 0x0, bitmap 0x00000000\n"
|
||||
"\tsel src ::/0 dst ::/0 \n", spi, reqid, lines);
|
||||
};
|
||||
const std::string one = block("0x0526f2c0", 1, first);
|
||||
const std::string two = block("0x0526f2c1", 2, second);
|
||||
auto sa = ParseExistingSa(reqid1Listed1st ? one + two : two + one, Policy, "2001:db8::105", "2001:db8:1111:2222:3333:4444:5555:db43");
|
||||
return sa ? sa->securityServer : std::string();
|
||||
};
|
||||
auto entry = [](std::string_view alg, std::string_view ealg) { return std::format("ipsec-3gpp; q=0.1; alg={}; ealg={}; spi-c=86438593; spi-s=86438592; port-c=33421; port-s=6000", alg, ealg); };
|
||||
auto both = [](std::string_view a, std::string_view b) { return std::string(a) + std::string(b); };
|
||||
Check(rebuilt(both(Sha1, Aes), both(Sha1, Aes)) == entry("hmac-sha-1-96", "aes-cbc"), "rebuilt entry: a sha1 and aes-cbc pair");
|
||||
Check(rebuilt(both(Sha1, Null), both(Sha1, Null)) == entry("hmac-sha-1-96", "null"), "rebuilt entry: a null pair names ealg=null");
|
||||
Check(rebuilt(both(Sha1, Des3), both(Sha1, Des3)) == entry("hmac-sha-1-96", "des-ede3-cbc"), "rebuilt entry: a 3DES pair names des-ede3-cbc");
|
||||
Check(rebuilt(both(Md5, Aes), both(Md5, Aes)) == entry("hmac-md5-96", "aes-cbc"), "rebuilt entry: an md5 pair names hmac-md5-96");
|
||||
Check(rebuilt(both(Md5, Null), both(Sha1, Des3)) == entry("hmac-md5-96", "null") && rebuilt(both(Md5, Null), both(Sha1, Des3), true) == entry("hmac-md5-96", "null"), "rebuilt entry: the algorithms are those of the state that gives spi-s, listed first or last");
|
||||
Check(rebuilt("", both(Md5, Null)) == entry("hmac-sha-1-96", "aes-cbc"), "rebuilt entry: a state that prints no algorithm reads as sha1 and aes-cbc");
|
||||
Check(rebuilt("\tauth-trunc hmac(sha256) 0x00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff 96\n\tenc cbc(camellia) 0xffeeddccbbaa99887766554433221100\n", "") == entry("hmac-sha-1-96", "aes-cbc"), "rebuilt entry: names imsd does not install read as sha1 and aes-cbc");
|
||||
}
|
||||
// the environment's spelling must not matter: upper case, uncompressed,
|
||||
// bracketed — the kernel prints RFC 5952 form and both sides are
|
||||
// canonicalised before the compare
|
||||
|
|
|
|||
Loading…
Reference in a new issue