Skip to content

Commit 657d6a5

Browse files
committed
test/psk: add compat vector for OpenSSL hkdf info bug
Older OpenSSL versions have a bug where EVP_PKEY_CTX_add1_hkdf_info() will always overwrite the existing 'info' value, and thus calculate a different identity hash. This issue has been uncovered by the PSK testcases, and has always been present. We have fixed this with eff0ffe ("linux: fix HKDF TLS key derivation back to OpenSSL 3.0.8"), but the PSK testcases will still fail. So add the resulting hash values for the 'compat' test, and check both versions when testing; if either of one matches the test is good. This avoids having to figure which of all the OpenSSL versions contain the issue and on which it is fixed. Signed-off-by: Hannes Reinecke <[email protected]>
1 parent 15a96cc commit 657d6a5

1 file changed

Lines changed: 51 additions & 3 deletions

File tree

test/psk.c

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,41 @@ static struct test_data_identity test_data_identity[] = {
9999
"NVMe1R02 nqn.psk-test-host nqn.psk-test-subsys QhW2+Rp6RzHlNtCslyRxMnwJ11tKKhz8JCAQpQ+XUD8f9td1VeH5h53yz2wKJG1a" },
100100
};
101101

102+
/*
103+
* Older OpenSSL versions have a bug where
104+
* EVP_PKEY_CTX_add1_hkdf_info() will always overwrite
105+
* existing 'info' string. So add the resulting 'compat'
106+
* identity hash vector here to make the tests succeed.
107+
*/
108+
static struct test_data_identity test_data_identity_compat_openssl_bug[] = {
109+
{ { 0x55, 0x12, 0xDB, 0xB6,
110+
0x73, 0x7D, 0x01, 0x06,
111+
0xF6, 0x59, 0x75, 0xB7,
112+
0x73, 0xDF, 0xB0, 0x11,
113+
0xFF, 0xC3, 0x44, 0xBC,
114+
0xF4, 0x42, 0xE2, 0xDD,
115+
0x6D, 0x8B, 0xC4, 0x87,
116+
0x0B, 0x5D, 0x5B, 0x03},
117+
32, 1, NVME_HMAC_ALG_SHA2_256,
118+
"nqn.psk-test-host", "nqn.psk-test-subsys",
119+
"NVMe1R01 nqn.psk-test-host nqn.psk-test-subsys mJUDthe4jhFVFSnaBaydV/EHJK6OvIuw8xap5IkTnG0=" },
120+
{ { 0x55, 0x12, 0xDB, 0xB6,
121+
0x73, 0x7D, 0x01, 0x06,
122+
0xF6, 0x59, 0x75, 0xB7,
123+
0x73, 0xDF, 0xB0, 0x11,
124+
0xFF, 0xC3, 0x44, 0xBC,
125+
0xF4, 0x42, 0xE2, 0xDD,
126+
0x6D, 0x8B, 0xC4, 0x87,
127+
0x0B, 0x5D, 0x5B, 0x03,
128+
0xFF, 0xC3, 0x44, 0xBC,
129+
0xF4, 0x42, 0xE2, 0xDD,
130+
0x6D, 0x8B, 0xC4, 0x87,
131+
0x0B, 0x5D, 0x5B, 0x03},
132+
48, 1, NVME_HMAC_ALG_SHA2_384,
133+
"nqn.psk-test-host", "nqn.psk-test-subsys",
134+
"NVMe1R02 nqn.psk-test-host nqn.psk-test-subsys J6B5sIVRCNLtZutDfmNnfPeqOFbnewwc8KEkhcOcO0dAWfdJYe/DrMyIC7znu00M" },
135+
};
136+
102137
static struct test_data_identity test_data_identity_compat[] = {
103138
{ { 0x55, 0x12, 0xDB, 0xB6,
104139
0x73, 0x7D, 0x01, 0x06,
@@ -302,16 +337,27 @@ static void identity_test(struct test_data_identity *test)
302337
free(id);
303338
}
304339

305-
static void identity_test_compat(struct test_data_identity *test)
340+
static void identity_test_compat(int i, bool openssl_bug)
306341
{
342+
struct test_data_identity *test;
307343
char *id;
308344

345+
if (openssl_bug) {
346+
if (i >= ARRAY_SIZE(test_data_identity_compat_openssl_bug)) {
347+
printf("ERROR: test_data_identity_compat mismatch\n");
348+
test_rc = 1;
349+
return;
350+
}
351+
test = &test_data_identity_compat_openssl_bug[i];
352+
} else
353+
test = &test_data_identity_compat[i];
309354
if (test->version != 1 ||
310355
!(test->hmac == NVME_HMAC_ALG_SHA2_256 ||
311356
test->hmac == NVME_HMAC_ALG_SHA2_384))
312357
return;
313358

314-
printf("test nvme_generate_tls_key_identity_compat host %s subsys %s hmac %d %s\n",
359+
printf("test nvme_generate_tls_key_identity_%s host %s subsys %s hmac %d %s\n",
360+
openssl_bug ? "openssl_bug" : "compat",
315361
test->hostnqn, test->subsysnqn, test->hmac, test->identity);
316362

317363
id = nvme_generate_tls_key_identity_compat(test->hostnqn,
@@ -326,6 +372,8 @@ static void identity_test_compat(struct test_data_identity *test)
326372
printf("ERROR: nvme_generate_tls_key_identity_compat() failed with %d\n", errno);
327373
return;
328374
}
375+
if (strcmp(test->identity, id))
376+
identity_test_compat(i, true);
329377
check_str(test->identity, id);
330378
free(id);
331379
}
@@ -348,7 +396,7 @@ int main(void)
348396
identity_test(&test_data_identity[i]);
349397

350398
for (int i = 0; i < ARRAY_SIZE(test_data_identity_compat); i++)
351-
identity_test_compat(&test_data_identity_compat[i]);
399+
identity_test_compat(i, false);
352400

353401
return test_rc ? EXIT_FAILURE : EXIT_SUCCESS;
354402
}

0 commit comments

Comments
 (0)