summaryrefslogtreecommitdiff
path: root/gtests
diff options
context:
space:
mode:
authorDana Keeler <dkeeler@mozilla.com>2022-03-09 02:25:51 +0000
committerDana Keeler <dkeeler@mozilla.com>2022-03-09 02:25:51 +0000
commit7d2a566944c72a7347b569de6669c550fe846f6f (patch)
tree0f40418eeca48e4399043cb568d37686d6ebfc34 /gtests
parenta78986a387a20724dc0daafb93b734aeb7260247 (diff)
downloadnss-hg-7d2a566944c72a7347b569de6669c550fe846f6f.tar.gz
Bug 1755092 - rework signature verification in mozilla::pkix r=jschanck
The initial implementation of mozilla::pkix split signature verification into two steps: digesting the data that had been signed and then verifying that digest. This separation added complexity that was hidden by the VFY_* APIs. However, those APIs are in need of improvements. This patch avoids the VFY_* APIs as well as the additional complexity by removing the separate digest step and using the PK11_Verify* APIs directly. Differential Revision: https://phabricator.services.mozilla.com/D138605
Diffstat (limited to 'gtests')
-rw-r--r--gtests/mozpkix_gtest/mozpkix_gtest.gyp1
-rw-r--r--gtests/mozpkix_gtest/pkixder_pki_types_tests.cpp167
-rw-r--r--gtests/mozpkix_gtest/pkixgtest.h25
-rw-r--r--gtests/mozpkix_gtest/pkixnss_tests.cpp456
4 files changed, 639 insertions, 10 deletions
diff --git a/gtests/mozpkix_gtest/mozpkix_gtest.gyp b/gtests/mozpkix_gtest/mozpkix_gtest.gyp
index 80c348888..49cf635a1 100644
--- a/gtests/mozpkix_gtest/mozpkix_gtest.gyp
+++ b/gtests/mozpkix_gtest/mozpkix_gtest.gyp
@@ -28,6 +28,7 @@
'pkixder_universal_types_tests.cpp',
'pkixgtest.cpp',
'pkixnames_tests.cpp',
+ 'pkixnss_tests.cpp',
'pkixocsp_CreateEncodedOCSPRequest_tests.cpp',
'pkixocsp_VerifyEncodedOCSPResponse.cpp',
],
diff --git a/gtests/mozpkix_gtest/pkixder_pki_types_tests.cpp b/gtests/mozpkix_gtest/pkixder_pki_types_tests.cpp
index 977b6b42d..bdde10ebb 100644
--- a/gtests/mozpkix_gtest/pkixder_pki_types_tests.cpp
+++ b/gtests/mozpkix_gtest/pkixder_pki_types_tests.cpp
@@ -32,6 +32,7 @@
using namespace mozilla::pkix;
using namespace mozilla::pkix::der;
+using namespace mozilla::pkix::test;
class pkixder_pki_types_tests : public ::testing::Test { };
@@ -478,3 +479,169 @@ INSTANTIATE_TEST_SUITE_P(
pkixder_SignatureAlgorithmIdentifier_Invalid,
pkixder_SignatureAlgorithmIdentifier_Invalid,
testing::ValuesIn(INVALID_SIGNATURE_ALGORITHM_VALUE_TEST_INFO));
+
+struct EncodedECDSASignatureValidParams {
+ std::vector<uint8_t> signature;
+ std::vector<uint8_t> rExpected;
+ std::vector<uint8_t> sExpected;
+};
+
+::std::ostream& operator<<(::std::ostream& os, const EncodedECDSASignatureValidParams&)
+{
+ return os << "TODO (bug 1318770)";
+}
+
+static const EncodedECDSASignatureValidParams
+ ENCODEDECDSASIGNATURE_VALID_PARAMS[] =
+{
+ {
+ { 0x30, 0x07, // SEQUENCE
+ 0x02, 0x01, 0x01, // INTEGER (0x01)
+ 0x02, 0x02, 0x05, 0x06 }, // INTEGER ([0x05, 0x06])
+ { 0x01 },
+ { 0x05, 0x06 },
+ },
+ {
+ { 0x30, 0x08, // SEQUENCE
+ 0x02, 0x03, 0x00, 0xb7, 0x0a, // INTEGER ([0xb7, 0x0a]) highest bit set
+ 0x02, 0x01, 0x02 }, // INTEGER (0x02)
+ { 0xb7, 0x0a },
+ { 0x02 },
+ },
+ {
+ { 0x30, 0x09, // SEQUENCE
+ 0x02, 0x03, 0x23, 0x00, 0x55, // INTEGER ([0x23, 0x00, 0x55])
+ 0x02, 0x02, 0x00, 0xf0 }, // INTEGER (0xf0) highest bit set
+ { 0x23, 0x00, 0x55 },
+ { 0xf0 },
+ },
+ {
+ { 0x30, 0x09, // SEQUENCE
+ 0x02, 0x03, 0x00, 0x93, 0x10, // INTEGER ([0x93, 0xl0]) highest bit set
+ 0x02, 0x02, 0x00, 0xcf }, // INTEGER (0xcf) highest bit set
+ { 0x93, 0x10, },
+ { 0xcf },
+ },
+};
+
+class pkixder_ECDSASigValue_valid
+ : public ::testing::Test
+ , public ::testing::WithParamInterface<EncodedECDSASignatureValidParams>
+{
+};
+
+
+TEST_P(pkixder_ECDSASigValue_valid, pkixder_ECDSASigValue_valid)
+{
+ const EncodedECDSASignatureValidParams& params(GetParam());
+
+ Input signature;
+ ASSERT_EQ(Success,
+ signature.Init(params.signature.data(), params.signature.size()));
+ Input r;
+ Input s;
+ ASSERT_EQ(Success, ECDSASigValue(signature, r, s));
+
+ Input rExpected;
+ ASSERT_EQ(Success,
+ rExpected.Init(params.rExpected.data(), params.rExpected.size()));
+ ASSERT_TRUE(InputsAreEqual(r, rExpected));
+
+ Input sExpected;
+ ASSERT_EQ(Success,
+ sExpected.Init(params.sExpected.data(), params.sExpected.size()));
+ ASSERT_TRUE(InputsAreEqual(s, sExpected));
+}
+
+INSTANTIATE_TEST_SUITE_P(pkixder_ECDSASigValue_valid,
+ pkixder_ECDSASigValue_valid,
+ testing::ValuesIn(ENCODEDECDSASIGNATURE_VALID_PARAMS));
+
+struct EncodedECDSASignatureInvalidParams {
+ std::vector<uint8_t> signature;
+ Result expectedResult;
+};
+
+::std::ostream& operator<<(::std::ostream& os, const EncodedECDSASignatureInvalidParams&)
+{
+ return os << "TODO (bug 1318770)";
+}
+
+static const EncodedECDSASignatureInvalidParams
+ ENCODEDECDSASIGNATURE_INVALID_PARAMS[] =
+{
+ {
+ { 0x05, 0x00 }, // not a SEQUENCE
+ Result::ERROR_BAD_DER
+ },
+ {
+ { 0x30, 0x00 }, // empty SEQUENCE
+ Result::ERROR_BAD_DER
+ },
+ {
+ { 0x30, 0x06,
+ 0x05, 0x01, 0x01, // NULL, not INTEGER
+ 0x02, 0x01, 0x01 },
+ Result::ERROR_BAD_DER
+ },
+ {
+ { 0x30, 0x08,
+ 0x02, 0x01, 0x01,
+ 0x02, 0x01, 0x01,
+ 0x05, 0x00 }, // trailing data in SEQUENCE
+ Result::ERROR_BAD_DER
+ },
+ { { 0x30, 0x06,
+ 0x02, 0x01, 0x01,
+ 0x02, 0x01, 0x01,
+ 0x05, 0x00 }, // trailing data after SEQUENCE
+ Result::ERROR_BAD_DER
+ },
+ {
+ { 0x30, 0x07,
+ 0x02, 0x01, 0x00, // not a positive INTEGER
+ 0x02, 0x02, 0x0f, 0x02 },
+ Result::ERROR_INVALID_INTEGER_ENCODING
+ },
+ {
+ { 0x30, 0x08,
+ 0x02, 0x02, 0x00, 0x01, // unnecessary zero padding
+ 0x02, 0x02, 0x0f, 0x02 },
+ Result::ERROR_INVALID_INTEGER_ENCODING
+ },
+ {
+ { 0x30, 0x07,
+ 0x02, 0x01, 0x01,
+ 0x02, 0x02, 0xff, 0x02 }, // negative INTEGER
+ Result::ERROR_INVALID_INTEGER_ENCODING
+ },
+ {
+ { 0x30, 0x06,
+ 0x02, 0x01, 0x01,
+ 0x02, 0x01, 0xf0 }, // negative INTEGER
+ Result::ERROR_INVALID_INTEGER_ENCODING
+ },
+};
+
+class pkixder_ECDSASigValue_invalid
+ : public ::testing::Test
+ , public ::testing::WithParamInterface<EncodedECDSASignatureInvalidParams>
+{
+};
+
+
+TEST_P(pkixder_ECDSASigValue_invalid, pkixder_ECDSASigValue_invalid)
+{
+ const EncodedECDSASignatureInvalidParams& params(GetParam());
+
+ Input signature;
+ ASSERT_EQ(Success,
+ signature.Init(params.signature.data(), params.signature.size()));
+ Input r;
+ Input s;
+ ASSERT_EQ(params.expectedResult, ECDSASigValue(signature, r, s));
+}
+
+INSTANTIATE_TEST_SUITE_P(
+ pkixder_ECDSASigValue_invalid, pkixder_ECDSASigValue_invalid,
+ testing::ValuesIn(ENCODEDECDSASIGNATURE_INVALID_PARAMS));
diff --git a/gtests/mozpkix_gtest/pkixgtest.h b/gtests/mozpkix_gtest/pkixgtest.h
index 777f123ca..92f69350f 100644
--- a/gtests/mozpkix_gtest/pkixgtest.h
+++ b/gtests/mozpkix_gtest/pkixgtest.h
@@ -135,9 +135,9 @@ class EverythingFailsByDefaultTrustDomain : public TrustDomain {
Result::FATAL_ERROR_LIBRARY_FAILURE);
}
- Result VerifyECDSASignedDigest(const SignedDigest&, Input) override {
+ Result VerifyECDSASignedData(Input, DigestAlgorithm, Input, Input) override {
ADD_FAILURE();
- return NotReached("VerifyECDSASignedDigest should not be called",
+ return NotReached("VerifyECDSASignedData should not be called",
Result::FATAL_ERROR_LIBRARY_FAILURE);
}
@@ -148,9 +148,10 @@ class EverythingFailsByDefaultTrustDomain : public TrustDomain {
Result::FATAL_ERROR_LIBRARY_FAILURE);
}
- Result VerifyRSAPKCS1SignedDigest(const SignedDigest&, Input) override {
+ Result VerifyRSAPKCS1SignedData(Input, DigestAlgorithm, Input,
+ Input) override {
ADD_FAILURE();
- return NotReached("VerifyRSAPKCS1SignedDigest should not be called",
+ return NotReached("VerifyRSAPKCS1SignedData should not be called",
Result::FATAL_ERROR_LIBRARY_FAILURE);
}
@@ -187,9 +188,11 @@ class DefaultCryptoTrustDomain : public EverythingFailsByDefaultTrustDomain {
return Success;
}
- Result VerifyECDSASignedDigest(const SignedDigest& signedDigest,
- Input subjectPublicKeyInfo) override {
- return TestVerifyECDSASignedDigest(signedDigest, subjectPublicKeyInfo);
+ Result VerifyECDSASignedData(Input data, DigestAlgorithm digestAlgorithm,
+ Input signature,
+ Input subjectPublicKeyInfo) override {
+ return TestVerifyECDSASignedData(data, digestAlgorithm, signature,
+ subjectPublicKeyInfo);
}
Result CheckRSAPublicKeyModulusSizeInBits(EndEntityOrCA,
@@ -197,9 +200,11 @@ class DefaultCryptoTrustDomain : public EverythingFailsByDefaultTrustDomain {
return Success;
}
- Result VerifyRSAPKCS1SignedDigest(const SignedDigest& signedDigest,
- Input subjectPublicKeyInfo) override {
- return TestVerifyRSAPKCS1SignedDigest(signedDigest, subjectPublicKeyInfo);
+ Result VerifyRSAPKCS1SignedData(Input data, DigestAlgorithm digestAlgorithm,
+ Input signature,
+ Input subjectPublicKeyInfo) override {
+ return TestVerifyRSAPKCS1SignedData(data, digestAlgorithm, signature,
+ subjectPublicKeyInfo);
}
Result CheckValidityIsAcceptable(Time, Time, EndEntityOrCA,
diff --git a/gtests/mozpkix_gtest/pkixnss_tests.cpp b/gtests/mozpkix_gtest/pkixnss_tests.cpp
new file mode 100644
index 000000000..7a556284a
--- /dev/null
+++ b/gtests/mozpkix_gtest/pkixnss_tests.cpp
@@ -0,0 +1,456 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This code is made available to you under your choice of the following sets
+ * of licensing terms:
+ */
+/* 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/.
+ */
+/* Copyright 2015 Mozilla Contributors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "pkixgtest.h"
+
+#include "mozpkix/pkixder.h"
+#include "mozpkix/pkixnss.h"
+
+using namespace mozilla::pkix;
+using namespace mozilla::pkix::der;
+using namespace mozilla::pkix::test;
+
+struct VerifySignedDataNSSTestParams
+{
+ ByteString data;
+ DigestAlgorithm digestAlgorithm;
+ ByteString signature;
+ PublicKeyAlgorithm publicKeyAlgorithm;
+ ByteString subjectPublicKeyInfo;
+ Result expectedResult;
+};
+
+::std::ostream& operator<<(::std::ostream& os,
+ const VerifySignedDataNSSTestParams&)
+{
+ return os << "TODO (bug 1318770)";
+}
+
+#define BS(s) ByteString(s, MOZILLA_PKIX_ARRAY_LENGTH(s))
+
+static const uint8_t kData[] = {
+ 0x53, 0x70, 0x68, 0x79, 0x6e, 0x78, 0x20, 0x6f, 0x66, 0x20, 0x62, 0x6c,
+ 0x61, 0x63, 0x6b, 0x20, 0x71, 0x75, 0x61, 0x72, 0x74, 0x7a, 0x2c, 0x20,
+ 0x6a, 0x75, 0x64, 0x67, 0x65, 0x20, 0x6d, 0x79, 0x20, 0x76, 0x6f, 0x77,
+ 0x2e
+};
+
+static const uint8_t kRsaSubjectPublicKeyInfo[] = {
+ 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
+ 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00,
+ 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xdb, 0x75, 0x02,
+ 0x7b, 0xeb, 0xf7, 0x3b, 0x31, 0x03, 0x71, 0x77, 0x34, 0x88, 0x8f, 0xb2,
+ 0x0d, 0xa6, 0xbe, 0x7d, 0xa7, 0xdd, 0xac, 0x0e, 0x99, 0x50, 0x46, 0x69,
+ 0x90, 0xe6, 0x7c, 0x3a, 0xa6, 0xf9, 0x3e, 0x02, 0x15, 0x3c, 0xf7, 0xb9,
+ 0xf4, 0xab, 0x3d, 0x54, 0x2c, 0x0d, 0x84, 0x94, 0x37, 0x95, 0xbc, 0x2b,
+ 0x56, 0x05, 0x00, 0xfa, 0xa2, 0x08, 0xf9, 0xcd, 0xc3, 0x2b, 0x9a, 0x58,
+ 0x80, 0x11, 0x49, 0xe0, 0x69, 0xf9, 0x81, 0x08, 0x52, 0x75, 0xb4, 0xc1,
+ 0x94, 0xa2, 0x67, 0x22, 0x5b, 0xfb, 0xe4, 0x74, 0xaa, 0x24, 0xb7, 0xa3,
+ 0x5e, 0x2c, 0x6b, 0xda, 0x20, 0x09, 0x5a, 0x5e, 0x4f, 0x95, 0xe8, 0x24,
+ 0x71, 0x64, 0x65, 0x29, 0x2c, 0x44, 0xb5, 0x17, 0xec, 0xe4, 0x68, 0xc3,
+ 0x69, 0x6b, 0x53, 0x6d, 0xa1, 0xa0, 0xb1, 0x74, 0xe2, 0x28, 0x03, 0xda,
+ 0x20, 0xca, 0xa4, 0x45, 0x1e, 0xf6, 0xab, 0xc7, 0xe9, 0xcb, 0xe3, 0x9a,
+ 0x16, 0x34, 0x8f, 0xd7, 0xf3, 0x66, 0x74, 0xea, 0xe7, 0x32, 0xf3, 0xd2,
+ 0x55, 0x6c, 0x8f, 0x38, 0xb8, 0x1b, 0x38, 0x08, 0x4c, 0x1f, 0x41, 0x74,
+ 0x35, 0x9e, 0x2d, 0x29, 0xed, 0x72, 0xe3, 0xda, 0x18, 0x01, 0xf4, 0x5f,
+ 0x8d, 0x9d, 0x72, 0x13, 0x18, 0x09, 0x1f, 0xbe, 0xb0, 0x20, 0x90, 0xc4,
+ 0x3d, 0x2c, 0x4f, 0xf2, 0xdc, 0x99, 0x8a, 0xae, 0x02, 0xd6, 0xef, 0x5a,
+ 0x88, 0x08, 0x15, 0x85, 0xdd, 0xaa, 0xce, 0xe4, 0x4b, 0x3f, 0xe9, 0xf4,
+ 0xfa, 0x54, 0xde, 0xb0, 0x30, 0xdf, 0x8f, 0x14, 0x2c, 0x49, 0x69, 0x24,
+ 0xe4, 0xa9, 0xeb, 0x62, 0x15, 0xf8, 0x8a, 0xd8, 0xe4, 0x8a, 0x99, 0x2b,
+ 0xdb, 0x68, 0x8b, 0x2a, 0x61, 0xbd, 0xc0, 0x57, 0xff, 0x5f, 0xee, 0xe9,
+ 0xac, 0x06, 0x77, 0x13, 0x7b, 0x2e, 0xd1, 0x76, 0x6c, 0xe8, 0x6c, 0x73,
+ 0x1f, 0x02, 0x03, 0x01, 0x00, 0x01
+};
+
+// Use `openssl dgst -binary -sha1` to obtain the hash of the data, and then
+// `openssl pkeyutl` with `-pkeyopt rsa_padding_mode:pkcs1` and `-pkeyopt
+// digest:sha1` to create the signature.
+static const uint8_t kRsaPkcs1Sha1Signature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0xa0, 0x00,
+ 0x9b, 0x23, 0x0a, 0xef, 0xfe, 0x2d, 0x17, 0xd5, 0x99, 0x64, 0x43, 0x32,
+ 0x58, 0xae, 0x96, 0x36, 0x5e, 0x80, 0x7c, 0xb7, 0x01, 0x44, 0x06, 0x19,
+ 0xba, 0x52, 0x30, 0xc9, 0x66, 0xb4, 0x4e, 0x7e, 0xeb, 0xe2, 0x97, 0x37,
+ 0x0c, 0xbd, 0xa6, 0xe6, 0x20, 0x05, 0x47, 0x79, 0x36, 0x56, 0x48, 0x9d,
+ 0x91, 0x7e, 0x61, 0x67, 0xbd, 0xc3, 0x12, 0xa8, 0x2a, 0xf0, 0xfc, 0xee,
+ 0x78, 0x18, 0x59, 0x7e, 0xd6, 0xd1, 0x55, 0xee, 0xf5, 0xaf, 0xb8, 0xbd,
+ 0x16, 0xd8, 0x01, 0xca
+};
+
+// Similarly as above, but with sha256.
+static const uint8_t kRsaPkcs1Sha256Signature[] = {
+ 0x9c, 0xbd, 0x2d, 0x6c, 0x4a, 0xe2, 0x47, 0xc9, 0xe2, 0xd9, 0x48, 0xa6,
+ 0x3a, 0x3d, 0x43, 0xf5, 0x5e, 0xd0, 0x11, 0x9a, 0xab, 0x79, 0x71, 0xb6,
+ 0x97, 0x7c, 0x6a, 0xc7, 0x96, 0x29, 0x21, 0xbd, 0xe2, 0xe7, 0xee, 0x01,
+ 0x1b, 0x0f, 0xd1, 0x31, 0xeb, 0xa6, 0xbe, 0xec, 0xc0, 0x64, 0x63, 0xf4,
+ 0x71, 0xd4, 0x7b, 0x1b, 0x02, 0xba, 0xae, 0xf3, 0x7a, 0x81, 0x5c, 0x78,
+ 0xd5, 0x75, 0xee, 0x9a, 0x4a, 0x97, 0x64, 0x6a, 0x75, 0x12, 0xa3, 0xca,
+ 0xe5, 0x2f, 0x40, 0x43, 0x1e, 0xe0, 0x5c, 0xa2, 0x2f, 0x3e, 0xf0, 0xdd,
+ 0x5e, 0xdc, 0x57, 0x3a, 0xfc, 0x35,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48, 0xce, 0x3d, 0x02,
+ 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03,
+ 0x42, 0x00, 0x04, 0x6d, 0xd3, 0xc0, 0x54, 0xc6, 0x33, 0xd3, 0xff, 0x4a,
+ 0x43, 0x0c, 0x3a, 0x70, 0xdb, 0x97, 0xf6, 0xc9, 0x68, 0xa0, 0xb1, 0xb9,
+ 0x6e, 0x15, 0x20, 0x80, 0x50, 0x6f, 0x37, 0x8f, 0xcc, 0xe3, 0x47, 0x96,
+ 0x2c, 0x5d, 0xb8, 0x76, 0x8e, 0x67, 0x19, 0x1c, 0xc7, 0x64, 0xb4, 0xd5,
+ 0xda, 0xa6, 0x4d, 0xc5, 0x3d, 0xe6, 0xa7, 0xb3, 0xb0, 0x41, 0xfb, 0x29,
+ 0xb4, 0x2f, 0xe8, 0x72, 0xeb, 0xfb, 0xfe
+};
+
+// Similar to above, but without the RSA padding mode option.
+static const uint8_t kEC256Sha1Signature[] = {
+ 0x30, 0x46, 0x02, 0x21, 0x00, 0xa7, 0x66, 0xd0, 0x2c, 0x3e, 0x2c, 0x06,
+ 0x28, 0x84, 0x3f, 0x59, 0xe7, 0x21, 0x44, 0x7d, 0x5a, 0xca, 0xd6, 0xd5,
+ 0xe8, 0x7d, 0x0a, 0xc5, 0x26, 0x99, 0x93, 0x43, 0xf1, 0x7d, 0x07, 0x08,
+ 0xdb, 0x02, 0x21, 0x00, 0xfc, 0x02, 0xea, 0xcb, 0x3b, 0x7e, 0xd3, 0x2e,
+ 0x86, 0x09, 0x18, 0x1a, 0x46, 0x4b, 0x98, 0xfa, 0x7c, 0x4c, 0x2f, 0xf8,
+ 0x6e, 0xf7, 0x42, 0x1e, 0x5d, 0x73, 0x0b, 0x27, 0xbf, 0xd7, 0x43, 0xeb
+};
+
+static const uint8_t kEC256Signature[] = {
+ 0x30, 0x45, 0x02, 0x21, 0x00, 0xfa, 0x47, 0x24, 0x2e, 0xc0, 0x01, 0x6c,
+ 0x31, 0xca, 0x75, 0x12, 0xa4, 0x02, 0x78, 0x0d, 0xc6, 0x75, 0x30, 0x1f,
+ 0x31, 0xec, 0xc1, 0xa1, 0x1c, 0xc9, 0x3e, 0xcd, 0xa5, 0x69, 0xe2, 0x06,
+ 0x61, 0x02, 0x20, 0x7f, 0x94, 0x6e, 0x60, 0x2e, 0xdd, 0x06, 0xa6, 0xd6,
+ 0x90, 0x74, 0x36, 0x4f, 0xf4, 0xc5, 0x80, 0x8f, 0xf6, 0xf9, 0x3b, 0x6c,
+ 0xee, 0x28, 0x94, 0x93, 0xce, 0xff, 0x1e, 0xfc, 0x84, 0x10, 0x65
+};
+
+static const uint8_t kEC384SubjectPublicKeyInfo[] = {
+ 0x30, 0x76, 0x30, 0x10, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02,
+ 0x01, 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x22, 0x03, 0x62, 0x00, 0x04,
+ 0x6c, 0x7a, 0x7b, 0x3f, 0x85, 0x0d, 0x04, 0x8d, 0x8c, 0x90, 0x0a, 0x9e,
+ 0x42, 0x54, 0xfa, 0x64, 0x78, 0xd3, 0x08, 0x91, 0xe0, 0xaa, 0xc1, 0x03,
+ 0x0c, 0x6c, 0xf1, 0x8c, 0xa6, 0x32, 0x9d, 0x57, 0x10, 0x38, 0xf2, 0xee,
+ 0x27, 0x1c, 0xa8, 0x11, 0xd0, 0x1c, 0x50, 0x24, 0xd9, 0x15, 0x17, 0x3c,
+ 0xe8, 0x29, 0x67, 0x4b, 0x06, 0xe3, 0x89, 0x52, 0x62, 0x0f, 0xd6, 0x12,
+ 0x95, 0x52, 0x21, 0x3e, 0x5d, 0x7b, 0x5b, 0x04, 0xdc, 0xa1, 0x49, 0x51,
+ 0xf0, 0xed, 0x35, 0x6b, 0x1c, 0xdd, 0x09, 0x8f, 0xdf, 0x1e, 0x0a, 0x39,
+ 0xd4, 0x92, 0x38, 0x1b, 0x0a, 0xce, 0xea, 0xf9, 0x6a, 0x0e, 0x37, 0x4d
+};
+
+static const uint8_t kEC384Signature[] = {
+ 0x30, 0x65, 0x02, 0x31, 0x00, 0x8c, 0xdf, 0x30, 0xa4, 0x06, 0x2b, 0x15,
+ 0x2f, 0x2e, 0x46, 0xbb, 0x3e, 0xd1, 0xa7, 0x87, 0x29, 0x2a, 0x30, 0x74,
+ 0x29, 0x31, 0x38, 0x2a, 0x05, 0x74, 0x1c, 0xbd, 0xe6, 0xf4, 0x4b, 0x8d,
+ 0x8e, 0xa9, 0x42, 0xad, 0xea, 0x62, 0x0d, 0x36, 0xa2, 0xde, 0x6e, 0x99,
+ 0x7f, 0xa5, 0x51, 0x42, 0x1e, 0x02, 0x30, 0x35, 0xad, 0x08, 0x88, 0x52,
+ 0x40, 0x2e, 0x91, 0x44, 0xf2, 0x07, 0x0a, 0x92, 0x39, 0x35, 0x1d, 0x15,
+ 0xeb, 0x90, 0xc4, 0xd9, 0xfb, 0x83, 0xae, 0x99, 0xaa, 0x50, 0x4e, 0xc9,
+ 0x35, 0x1d, 0x3a, 0x8d, 0x40, 0x9a, 0x91, 0x14, 0x6c, 0x0d, 0x02, 0x25,
+ 0x7e, 0x48, 0x8b, 0x98, 0x9d, 0x3f, 0x14
+};
+
+static const uint8_t kEC521SubjectPublicKeyInfo[] = {
+ 0x30, 0x81, 0x9b, 0x30, 0x10, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d,
+ 0x02, 0x01, 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x23, 0x03, 0x81, 0x86,
+ 0x00, 0x04, 0x01, 0x59, 0x3c, 0x05, 0xb1, 0x74, 0x49, 0x54, 0x72, 0xea,
+ 0xf5, 0xb0, 0x43, 0x98, 0x39, 0xfe, 0xc6, 0x4e, 0x8a, 0x58, 0x62, 0x83,
+ 0xe7, 0x61, 0xeb, 0xf6, 0x50, 0x32, 0xa6, 0x1e, 0x7c, 0x6a, 0x7c, 0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16, 0x18, 0x30, 0x1b, 0xdb, 0xbb, 0x99, 0x47, 0x32, 0xa0,
+ 0x17, 0x02, 0xef, 0x30, 0x72, 0x77, 0x27, 0x06, 0x0c, 0x6d, 0x4a, 0x01,
+ 0xba, 0xb0, 0x30, 0xec, 0x8b, 0x35, 0x44, 0x9a, 0xe5, 0xd2, 0x15, 0x74,
+ 0x69, 0x67, 0x2a, 0xe8, 0x5a, 0xd3, 0xa4, 0x91, 0x39, 0x49, 0x60, 0x4f,
+ 0x90, 0x78, 0xeb, 0xb4, 0xc0, 0x77, 0x53, 0xf7, 0xf5, 0x44, 0xfc, 0x29,
+ 0x86, 0xaf, 0x95, 0x6f, 0x56, 0xcd
+};
+
+static const VerifySignedDataNSSTestParams
+ VERIFYSIGNEDDIGESTNSS_TEST_PARAMS[] =
+{
+ {
+ BS(kData),
+ DigestAlgorithm::sha1,
+ BS(kRsaPkcs1Sha1Signature),
+ PublicKeyAlgorithm::RSA_PKCS1,
+ BS(kRsaSubjectPublicKeyInfo),
+ Success,
+ },
+ {
+ BS(kData),
+ DigestAlgorithm::sha256,
+ BS(kRsaPkcs1Sha256Signature),
+ PublicKeyAlgorithm::RSA_PKCS1,
+ BS(kRsaSubjectPublicKeyInfo),
+ Success,
+ },
+ {
+ BS(kData),
+ DigestAlgorithm::sha384,
+ BS(kRsaPkcs1Sha384Signature),
+ PublicKeyAlgorithm::RSA_PKCS1,
+ BS(kRsaSubjectPublicKeyInfo),
+ Success,
+ },
+ {
+ BS(kData),
+ DigestAlgorithm::sha512,
+ BS(kRsaPkcs1Sha512Signature),
+ PublicKeyAlgorithm::RSA_PKCS1,
+ BS(kRsaSubjectPublicKeyInfo),
+ Success,
+ },
+ {
+ BS(kData),
+ DigestAlgorithm::sha1,
+ BS(kEC256Sha1Signature),
+ PublicKeyAlgorithm::ECDSA,
+ BS(kEC256SubjectPublicKeyInfo),
+ Success,
+ },
+ {
+ BS(kData),
+ DigestAlgorithm::sha256,
+ BS(kEC256Signature),
+ PublicKeyAlgorithm::ECDSA,
+ BS(kEC256SubjectPublicKeyInfo),
+ Success,
+ },
+ {
+ BS(kData),
+ DigestAlgorithm::sha384,
+ BS(kEC384Signature),
+ PublicKeyAlgorithm::ECDSA,
+ BS(kEC384SubjectPublicKeyInfo),
+ Success,
+ },
+ {
+ BS(kData),
+ DigestAlgorithm::sha512,
+ BS(kEC521Signature),
+ PublicKeyAlgorithm::ECDSA,
+ BS(kEC521SubjectPublicKeyInfo),
+ Success,
+ },
+ // Wrong digest algorithm - RSA PKCS#1
+ {
+ BS(kData),
+ DigestAlgorithm::sha256,
+ BS(kRsaPkcs1Sha384Signature),
+ PublicKeyAlgorithm::RSA_PKCS1,
+ BS(kRsaSubjectPublicKeyInfo),
+ Result::ERROR_BAD_SIGNATURE,
+ },
+ // Wrong digest algorithm - ECDSA
+ {
+ BS(kData),
+ DigestAlgorithm::sha1,
+ BS(kEC256Signature),
+ PublicKeyAlgorithm::ECDSA,
+ BS(kEC256SubjectPublicKeyInfo),
+ Result::ERROR_BAD_SIGNATURE,
+ },
+ // ECDSA key for RSA PKCS#1 signature
+ {
+ BS(kData),
+ DigestAlgorithm::sha256,
+ BS(kRsaPkcs1Sha256Signature),
+ PublicKeyAlgorithm::ECDSA,
+ BS(kEC256SubjectPublicKeyInfo),
+ Result::ERROR_BAD_SIGNATURE,
+ },
+ // RSA PKCS#1 key for ECDSA signature
+ {
+ BS(kData),
+ DigestAlgorithm::sha256,
+ BS(kEC256Signature),
+ PublicKeyAlgorithm::RSA_PKCS1,
+ BS(kRsaSubjectPublicKeyInfo),
+ Result::ERROR_BAD_SIGNATURE,
+ },
+ // Wrong data.
+ {
+ BS(kRsaSubjectPublicKeyInfo),
+ DigestAlgorithm::sha384,
+ BS(kEC384Signature),
+ PublicKeyAlgorithm::ECDSA,
+ BS(kEC384SubjectPublicKeyInfo),
+ Result::ERROR_BAD_SIGNATURE,
+ },
+};
+
+class pkixnss_VerifySignedDataNSS
+ : public ::testing::Test
+ , public ::testing::WithParamInterface<VerifySignedDataNSSTestParams>
+{
+};
+
+void CheckVerifySignedData(PublicKeyAlgorithm publicKeyAlgorithm, Input data,
+ DigestAlgorithm digestAlgorithm, Input signature, Input subjectPublicKeyInfo,
+ Result expectedResult)
+{
+ switch (publicKeyAlgorithm) {
+ case PublicKeyAlgorithm::RSA_PKCS1:
+ ASSERT_EQ(expectedResult,
+ VerifyRSAPKCS1SignedDataNSS(data, digestAlgorithm, signature,
+ subjectPublicKeyInfo, nullptr));
+ break;
+ case PublicKeyAlgorithm::ECDSA:
+ ASSERT_EQ(expectedResult,
+ VerifyECDSASignedDataNSS(data, digestAlgorithm, signature,
+ subjectPublicKeyInfo, nullptr));
+ break;
+ default:
+ ASSERT_FALSE(true);
+ }
+}
+
+TEST_P(pkixnss_VerifySignedDataNSS, VerifySignedDataNSS)
+{
+ const VerifySignedDataNSSTestParams& params(GetParam());
+
+ ByteString data(params.data);
+ Input dataInput;
+ ASSERT_EQ(Success, dataInput.Init(data.data(), data.length()));
+ ByteString signature(params.signature);
+ Input signatureInput;
+ ASSERT_EQ(Success, signatureInput.Init(signature.data(), signature.length()));
+
+ Input subjectPublicKeyInfo;
+ ASSERT_EQ(Success,
+ subjectPublicKeyInfo.Init(params.subjectPublicKeyInfo.data(),
+ params.subjectPublicKeyInfo.length()));
+ CheckVerifySignedData(params.publicKeyAlgorithm, dataInput,
+ params.digestAlgorithm, signatureInput, subjectPublicKeyInfo,
+ params.expectedResult);
+
+ if (params.expectedResult == Success) {
+ signature[signature.length() - 4] = ~signature[signature.length() - 4];
+
+ CheckVerifySignedData(params.publicKeyAlgorithm, dataInput,
+ params.digestAlgorithm, signatureInput, subjectPublicKeyInfo,
+ Result::ERROR_BAD_SIGNATURE);
+
+ signature[signature.length() - 4] = ~signature[signature.length() - 4];
+ data[data.length() - 10] = ~data[data.length() - 10];
+
+ CheckVerifySignedData(params.publicKeyAlgorithm, dataInput,
+ params.digestAlgorithm, signatureInput, subjectPublicKeyInfo,
+ Result::ERROR_BAD_SIGNATURE);
+ }
+}
+
+INSTANTIATE_TEST_SUITE_P(
+ pkixnss_VerifySignedDataNSS, pkixnss_VerifySignedDataNSS,
+ testing::ValuesIn(VERIFYSIGNEDDIGESTNSS_TEST_PARAMS));