re-introduce old nss im too tired for this

This commit is contained in:
wuggy 2026-06-30 06:37:32 +01:00
commit 3a838106b9
2871 changed files with 1374431 additions and 1762417 deletions

View file

@ -1,5 +1,4 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
@ -68,6 +67,18 @@ size_t GetHashLength(SSLHashType hash) {
return 0;
}
CK_MECHANISM_TYPE GetHkdfMech(SSLHashType hash) {
switch (hash) {
case ssl_hash_sha256:
return CKM_NSS_HKDF_SHA256;
case ssl_hash_sha384:
return CKM_NSS_HKDF_SHA384;
default:
ADD_FAILURE() << "Unknown hash: " << hash;
}
return CKM_INVALID_MECHANISM;
}
PRUint16 GetSomeCipherSuiteForHash(SSLHashType hash) {
switch (hash) {
case ssl_hash_sha256:
@ -161,7 +172,7 @@ class TlsHkdfTest : public ::testing::Test,
ScopedPK11SymKey prkk(prk);
DumpKey("Output", prkk);
VerifyKey(prkk, CKM_HKDF_DERIVE, expected);
VerifyKey(prkk, GetHkdfMech(base_hash), expected);
// Now test the public wrapper.
PRUint16 cs = GetSomeCipherSuiteForHash(base_hash);
@ -169,21 +180,20 @@ class TlsHkdfTest : public ::testing::Test,
ikmk2.get(), &prk);
ASSERT_EQ(SECSuccess, rv);
ASSERT_NE(nullptr, prk);
VerifyKey(ScopedPK11SymKey(prk), CKM_HKDF_DERIVE, expected);
VerifyKey(ScopedPK11SymKey(prk), GetHkdfMech(base_hash), expected);
}
void HkdfExpandLabel(ScopedPK11SymKey* prk, SSLHashType base_hash,
const uint8_t* session_hash, size_t session_hash_len,
const char* label, size_t label_len,
const DataBuffer& expected) {
ASSERT_NE(nullptr, prk);
std::cerr << "Hash = " << kHashName[base_hash] << std::endl;
std::vector<uint8_t> output(expected.len());
SECStatus rv = tls13_HkdfExpandLabelRaw(
prk->get(), base_hash, session_hash, session_hash_len, label, label_len,
ssl_variant_stream, &output[0], output.size());
SECStatus rv = tls13_HkdfExpandLabelRaw(prk->get(), base_hash, session_hash,
session_hash_len, label, label_len,
&output[0], output.size());
ASSERT_EQ(SECSuccess, rv);
DumpData("Output", &output[0], output.size());
EXPECT_EQ(0, memcmp(expected.data(), &output[0], expected.len()));
@ -195,15 +205,15 @@ class TlsHkdfTest : public ::testing::Test,
session_hash, session_hash_len, label, label_len,
&secret);
EXPECT_EQ(SECSuccess, rv);
ASSERT_NE(nullptr, secret);
VerifyKey(ScopedPK11SymKey(secret), CKM_HKDF_DERIVE, expected);
ASSERT_NE(nullptr, prk);
VerifyKey(ScopedPK11SymKey(secret), GetHkdfMech(base_hash), expected);
// Verify that a key can be created with a different key type and size.
rv = SSL_HkdfExpandLabelWithMech(
SSL_LIBRARY_VERSION_TLS_1_3, cs, prk->get(), session_hash,
session_hash_len, label, label_len, CKM_DES3_CBC_PAD, 24, &secret);
EXPECT_EQ(SECSuccess, rv);
ASSERT_NE(nullptr, secret);
ASSERT_NE(nullptr, prk);
ScopedPK11SymKey with_mech(secret);
EXPECT_EQ(static_cast<CK_MECHANISM_TYPE>(CKM_DES3_CBC_PAD),
PK11_GetMechanism(with_mech.get()));
@ -427,7 +437,7 @@ TEST_P(TlsHkdfTest, BadExpandLabelWrapperInput) {
}
static const SSLHashType kHashTypes[] = {ssl_hash_sha256, ssl_hash_sha384};
INSTANTIATE_TEST_SUITE_P(AllHashFuncs, TlsHkdfTest,
::testing::ValuesIn(kHashTypes));
INSTANTIATE_TEST_CASE_P(AllHashFuncs, TlsHkdfTest,
::testing::ValuesIn(kHashTypes));
} // namespace nss_test