[NSS] Update NSS

This commit is contained in:
Moonchild 2026-01-14 22:30:19 +01:00 • committed by OwnedByWuigi
commit 96a9380208
7 changed files with 142 additions and 30 deletions

View file

@ -14,6 +14,7 @@
'der_getint_unittest.cc',
'der_quickder_unittest.cc',
'p12_import_unittest.cc',
'p7_import_unittest.cc',
'<(DEPTH)/gtests/common/gtests.cc'
],
'dependencies': [

View file

@ -230,6 +230,13 @@ static const uint8_t cert_p12[] = {
0x51, 0x04, 0x08, 0xa1, 0x52, 0xdd, 0x64, 0x46, 0xe9, 0x9e, 0x3e, 0x02,
0x02, 0x08, 0x00};
unsigned char leak_p12[] = {
0x30, 0x82, 0x20, 0x20, 0x02, 0x01, 0xff, 0x30, 0x82, 0x09, 0x20, 0x06,
0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x02, 0xa0, 0x50,
0x30, 0x3f, 0x02, 0x01, 0x20, 0x31, 0x0d, 0x30, 0x0b, 0x06, 0x09, 0x60,
0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04, 0x30, 0x20, 0x06, 0x09,
0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01};
class PK12ImportTest : public ::testing::Test {};
TEST_F(PK12ImportTest, ImportPK12With2P7) {
@ -247,4 +254,20 @@ TEST_F(PK12ImportTest, ImportPK12With2P7) {
ASSERT_EQ(SECFailure, rv);
}
TEST_F(PK12ImportTest, FailsToImportButShouldNotLeak) {
SECItem password = {siBuffer, nullptr, 0};
ScopedPK11SlotInfo slot(PK11_GetInternalSlot());
ScopedSEC_PKCS12DecoderContext dcx(
SEC_PKCS12DecoderStart(&password, slot.get(), nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr));
ASSERT_TRUE(dcx);
SECStatus rv = SEC_PKCS12DecoderUpdate(
dcx.get(), const_cast<uint8_t *>(leak_p12), sizeof(leak_p12));
ASSERT_EQ(SECSuccess, rv);
rv = SEC_PKCS12DecoderVerify(dcx.get());
// This is not a valid PKCS12 file, so a failing return value is expected.
// However, the implementation shouldn't leak memory as a result.
ASSERT_EQ(SECFailure, rv);
}
} // namespace nss_test

View file

@ -0,0 +1,60 @@
+/* -*- 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/. */
+
+#include "nss.h"
+#include "secpkcs7.h"
+
+#include "gtest/gtest.h"
#include "nss_scoped_ptrs.h"
namespace nss_test {
// This is an invalid PKCS7 message. Among other things, it contains some
// unknown hash OIDs. This should fail to parse, but it should be safe to try.
static const uint8_t p7_with_unknown_hashes[] = {
0x30, 0x4d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07,
0x02, 0xa0, 0x40, 0x30, 0x3e, 0x02, 0x01, 0x20, 0x31, 0x27, 0x30, 0x0b,
0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x05, 0x30,
0x0b, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x05,
0x30, 0x0b, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02,
0x04, 0x30, 0x10, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,
0x07, 0x01, 0xa0, 0x03, 0x04, 0x01, 0x00};
// This is an invalid PKCS7 message. It contains multiple hash OIDs (that's not
// what makes it invalid). When it fails to parse, the associated digest data
// structures should be freed correctly.
static const uint8_t p7_with_multiple_hashes[] = {
0x30, 0x4d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07,
0x02, 0xa0, 0x40, 0x30, 0x3e, 0x02, 0x01, 0x20, 0x31, 0x27, 0x30, 0x0b,
0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x30,
0x0b, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02,
0x30, 0x0b, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02,
0x04, 0x30, 0x10, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,
0x07, 0x01, 0xa0, 0x03, 0x04, 0x01, 0x00};
class P7ImportTest : public ::testing::Test {};
TEST_F(P7ImportTest, FailSafeWithUnknownHashes) {
ScopedSEC_PKCS7DecoderContext dcx(SEC_PKCS7DecoderStart(
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr));
ASSERT_TRUE(dcx);
SECStatus rv = SEC_PKCS7DecoderUpdate(
dcx.get(), reinterpret_cast<const char*>(p7_with_unknown_hashes),
sizeof(p7_with_unknown_hashes));
ASSERT_EQ(SECFailure, rv);
}
TEST_F(P7ImportTest, NoLeakWithMultipleHashes) {
ScopedSEC_PKCS7DecoderContext dcx(SEC_PKCS7DecoderStart(
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr));
ASSERT_TRUE(dcx);
SECStatus rv = SEC_PKCS7DecoderUpdate(
dcx.get(), reinterpret_cast<const char*>(p7_with_multiple_hashes),
sizeof(p7_with_multiple_hashes));
ASSERT_EQ(SECFailure, rv);
}
} // namespace nss_test