summaryrefslogtreecommitdiff
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
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
-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
-rw-r--r--lib/mozpkix/include/pkix-test/pkixtestutil.h9
-rw-r--r--lib/mozpkix/include/pkix/pkixder.h5
-rw-r--r--lib/mozpkix/include/pkix/pkixnss.h12
-rw-r--r--lib/mozpkix/include/pkix/pkixtypes.h24
-rw-r--r--lib/mozpkix/include/pkix/pkixutil.h12
-rw-r--r--lib/mozpkix/lib/pkixbuild.cpp24
-rw-r--r--lib/mozpkix/lib/pkixc.cpp18
-rw-r--r--lib/mozpkix/lib/pkixcheck.cpp5
-rw-r--r--lib/mozpkix/lib/pkixder.cpp54
-rw-r--r--lib/mozpkix/lib/pkixnss.cpp192
-rw-r--r--lib/mozpkix/lib/pkixverify.cpp60
-rw-r--r--lib/mozpkix/test-lib/pkixtestnss.cpp16
16 files changed, 902 insertions, 178 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, 0x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 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[] = {
+ 0x6c, 0x11, 0x88, 0xc9, 0x6b, 0x06, 0xf2, 0x55, 0x67, 0xa1, 0x30, 0x3b,
+ 0x0a, 0xf5, 0x20, 0x84, 0xd7, 0x3c, 0x44, 0xc8, 0x25, 0x67, 0x58, 0x2a,
+ 0x9d, 0x7b, 0xbc, 0x92, 0x01, 0xbd, 0x4c, 0x11, 0x51, 0x2f, 0x18, 0x85,
+ 0xd5, 0xef, 0xd5, 0x35, 0x1e, 0x12, 0x89, 0x0e, 0x36, 0xaa, 0x86, 0xb8,
+ 0xaf, 0x81, 0x5b, 0xf2, 0x65, 0xde, 0x07, 0xb9, 0xbc, 0x1a, 0x22, 0xf1,
+ 0xac, 0x8e, 0x95, 0x5d, 0x3d, 0x5b, 0x15, 0x92, 0x12, 0x07, 0x24, 0x14,
+ 0x89, 0x5a, 0x00, 0xfe, 0x0c, 0xf3, 0x99, 0x0b, 0x83, 0x3f, 0x09, 0x2c,
+ 0x82, 0x06, 0x84, 0x21, 0xd3, 0x79, 0xc7, 0xac, 0x16, 0x89, 0x2e, 0x81,
+ 0xb4, 0x29, 0x88, 0x08, 0x26, 0x30, 0x79, 0x40, 0x96, 0xa7, 0xd9, 0x5c,
+ 0x67, 0xdb, 0x94, 0x77, 0x20, 0xcb, 0x07, 0x55, 0xa7, 0x37, 0xb4, 0xf9,
+ 0xcc, 0x9a, 0x9a, 0x22, 0x42, 0xb5, 0xce, 0xcc, 0x0f, 0x13, 0x54, 0x2f,
+ 0x1d, 0x7f, 0xa9, 0xb7, 0x7a, 0x06, 0x6f, 0x15, 0x16, 0xe2, 0x30, 0x5b,
+ 0xe0, 0x84, 0xe6, 0x28, 0x65, 0x53, 0x6a, 0xab, 0x67, 0x85, 0x53, 0x1b,
+ 0xaf, 0x9f, 0x9b, 0x60, 0x18, 0xb8, 0xf1, 0xd5, 0x53, 0xc9, 0x48, 0x21,
+ 0xd9, 0x81, 0xbd, 0xeb, 0x44, 0x82, 0x3c, 0x66, 0x91, 0x63, 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,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4, 0x96, 0x03, 0xd8, 0xfd, 0x80, 0xa2, 0xa1,
+ 0xc1, 0x36, 0xb3, 0x47, 0x05, 0xd1, 0x6e, 0xd2, 0x81, 0x16, 0xe4, 0x63,
+ 0x26, 0xf9, 0x96, 0x55, 0x37, 0x18, 0x4f, 0x2b, 0x7e, 0x1c, 0xd9, 0xba,
+ 0x4f, 0xde, 0x4d, 0x61, 0xc4, 0xd5, 0x7c, 0xe3, 0xa3, 0x21, 0xe8, 0xae,
+ 0xc2, 0xe9, 0x62, 0x07
+};
+
+static const uint8_t kEC256SubjectPublicKeyInfo[] = {
+ 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 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, 0xa5,
+ 0x4e, 0x5b, 0x96, 0x77, 0xfd, 0xf5, 0x5c, 0xe8, 0x61, 0x32, 0xc2, 0xd2,
+ 0xcf, 0x06, 0xef, 0x46, 0xf1, 0x51, 0x50, 0x35, 0xf7, 0xac, 0x97, 0x7a,
+ 0xfb, 0xe8, 0x9f, 0xa5, 0xc6, 0x32, 0x8a, 0xdf, 0x00, 0x9d, 0x6f, 0xd7,
+ 0x34, 0xa7, 0xe5, 0x1d, 0x85, 0x4b, 0xc2, 0x26, 0x38, 0x8c, 0x6f, 0x8f,
+ 0x75, 0xd8, 0x47, 0x08, 0xe7, 0xcb, 0x78, 0x9f, 0x3d, 0xe8, 0x5a, 0xe5,
+ 0xa1, 0x74, 0x56, 0x80, 0x62, 0x7e, 0x95, 0x2a, 0x2d, 0x6e, 0x27, 0x71,
+ 0x02, 0xf1, 0xbf, 0x5d, 0xe4, 0x7e, 0xab, 0x94, 0x92, 0x24, 0x0f, 0x31,
+ 0x51, 0x33, 0x67, 0x6a, 0xfb, 0x29, 0xae, 0xa9, 0xaf, 0xdd, 0x09, 0x77,
+ 0x08, 0xf8
+};
+
+static const uint8_t kEC521Signature[] = {
+ 0x30, 0x81, 0x87, 0x02, 0x41, 0x56, 0xa2, 0x7e, 0xff, 0x54, 0xe2, 0xb4,
+ 0x23, 0x08, 0xf8, 0xde, 0x28, 0x63, 0x77, 0x3b, 0x0f, 0x18, 0x7b, 0x5d,
+ 0xac, 0x2f, 0x57, 0x04, 0xbe, 0x15, 0x7b, 0x04, 0xb1, 0xd2, 0x7f, 0x21,
+ 0x14, 0x40, 0x18, 0xb2, 0x27, 0xe4, 0xef, 0x14, 0x54, 0x9c, 0xca, 0x90,
+ 0xd8, 0x95, 0x3a, 0xfe, 0xf8, 0xe4, 0x60, 0x98, 0x45, 0x31, 0x5e, 0x3b,
+ 0xac, 0x89, 0x48, 0x0b, 0xad, 0xe2, 0xeb, 0xa5, 0xec, 0xae, 0x02, 0x42,
+ 0x01, 0xc9, 0x16, 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));
diff --git a/lib/mozpkix/include/pkix-test/pkixtestutil.h b/lib/mozpkix/include/pkix-test/pkixtestutil.h
index 70c0fee94..44a60fea1 100644
--- a/lib/mozpkix/include/pkix-test/pkixtestutil.h
+++ b/lib/mozpkix/include/pkix-test/pkixtestutil.h
@@ -279,10 +279,11 @@ TestKeyPair* GenerateDSSKeyPair();
inline void DeleteTestKeyPair(TestKeyPair* keyPair) { delete keyPair; }
typedef std::unique_ptr<TestKeyPair> ScopedTestKeyPair;
-Result TestVerifyECDSASignedDigest(const SignedDigest& signedDigest,
- Input subjectPublicKeyInfo);
-Result TestVerifyRSAPKCS1SignedDigest(const SignedDigest& signedDigest,
- Input subjectPublicKeyInfo);
+Result TestVerifyECDSASignedData(Input data, DigestAlgorithm digestAlgorithm,
+ Input signature, Input subjectPublicKeyInfo);
+Result TestVerifyRSAPKCS1SignedData(Input data, DigestAlgorithm digestAlgorithm,
+ Input signature,
+ Input subjectPublicKeyInfo);
Result TestDigestBuf(Input item, DigestAlgorithm digestAlg,
/*out*/ uint8_t* digestBuf, size_t digestBufLen);
diff --git a/lib/mozpkix/include/pkix/pkixder.h b/lib/mozpkix/include/pkix/pkixder.h
index 379106ef4..1b0d08e0d 100644
--- a/lib/mozpkix/include/pkix/pkixder.h
+++ b/lib/mozpkix/include/pkix/pkixder.h
@@ -488,7 +488,7 @@ inline Result OptionalExtensions(Reader& input, uint8_t tag,
Result DigestAlgorithmIdentifier(Reader& input,
/*out*/ DigestAlgorithm& algorithm);
-enum class PublicKeyAlgorithm { RSA_PKCS1, ECDSA, Uninitialized };
+enum class PublicKeyAlgorithm { RSA_PKCS1, ECDSA };
Result SignatureAlgorithmIdentifierValue(
Reader& input,
@@ -524,6 +524,9 @@ struct SignedDataWithSignature final {
// certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL }
Result SignedData(Reader& input, /*out*/ Reader& tbs,
/*out*/ SignedDataWithSignature& signedDataWithSignature);
+
+// Parses an ECDSASigValue (RFC 5480) into its components r and s.
+Result ECDSASigValue(Input ecdsaSignature, /*out*/ Input& r, /*out*/ Input& s);
}
}
} // namespace mozilla::pkix::der
diff --git a/lib/mozpkix/include/pkix/pkixnss.h b/lib/mozpkix/include/pkix/pkixnss.h
index b181ca541..4c5f0a322 100644
--- a/lib/mozpkix/include/pkix/pkixnss.h
+++ b/lib/mozpkix/include/pkix/pkixnss.h
@@ -34,15 +34,15 @@ namespace pkix {
// Verifies the PKCS#1.5 signature on the given data using the given RSA public
// key.
-Result VerifyRSAPKCS1SignedDigestNSS(const SignedDigest& sd,
- Input subjectPublicKeyInfo,
- void* pkcs11PinArg);
+Result VerifyRSAPKCS1SignedDataNSS(Input data, DigestAlgorithm digestAlgorithm,
+ Input signature, Input subjectPublicKeyInfo,
+ void* pkcs11PinArg);
// Verifies the ECDSA signature on the given data using the given ECC public
// key.
-Result VerifyECDSASignedDigestNSS(const SignedDigest& sd,
- Input subjectPublicKeyInfo,
- void* pkcs11PinArg);
+Result VerifyECDSASignedDataNSS(Input data, DigestAlgorithm digestAlgorithm,
+ Input signature, Input subjectPublicKeyInfo,
+ void* pkcs11PinArg);
// Computes the digest of the given data using the given digest algorithm.
//
diff --git a/lib/mozpkix/include/pkix/pkixtypes.h b/lib/mozpkix/include/pkix/pkixtypes.h
index 6c391681f..18f52b472 100644
--- a/lib/mozpkix/include/pkix/pkixtypes.h
+++ b/lib/mozpkix/include/pkix/pkixtypes.h
@@ -52,14 +52,6 @@ enum class NamedCurve {
secp256r1 = 3,
};
-struct SignedDigest final {
- Input digest;
- DigestAlgorithm digestAlgorithm;
- Input signature;
-
- void operator=(const SignedDigest&) = delete;
-};
-
enum class EndEntityOrCA { MustBeEndEntity = 0, MustBeCA = 1 };
enum class KeyUsage : uint8_t {
@@ -305,10 +297,12 @@ class TrustDomain {
//
// CheckRSAPublicKeyModulusSizeInBits will be called before calling this
// function, so it is not necessary to repeat those checks here. However,
- // VerifyRSAPKCS1SignedDigest *is* responsible for doing the mathematical
+ // VerifyRSAPKCS1SignedData *is* responsible for doing the mathematical
// verification of the public key validity as specified in NIST SP 800-56A.
- virtual Result VerifyRSAPKCS1SignedDigest(const SignedDigest& signedDigest,
- Input subjectPublicKeyInfo) = 0;
+ virtual Result VerifyRSAPKCS1SignedData(Input data,
+ DigestAlgorithm digestAlgorithm,
+ Input signature,
+ Input subjectPublicKeyInfo) = 0;
// Check that the given named ECC curve is acceptable for ECDSA signatures.
//
@@ -323,10 +317,12 @@ class TrustDomain {
//
// CheckECDSACurveIsAcceptable will be called before calling this function,
// so it is not necessary to repeat that check here. However,
- // VerifyECDSASignedDigest *is* responsible for doing the mathematical
+ // VerifyECDSASignedData *is* responsible for doing the mathematical
// verification of the public key validity as specified in NIST SP 800-56A.
- virtual Result VerifyECDSASignedDigest(const SignedDigest& signedDigest,
- Input subjectPublicKeyInfo) = 0;
+ virtual Result VerifyECDSASignedData(Input data,
+ DigestAlgorithm digestAlgorithm,
+ Input signature,
+ Input subjectPublicKeyInfo) = 0;
// Check that the validity duration is acceptable.
//
diff --git a/lib/mozpkix/include/pkix/pkixutil.h b/lib/mozpkix/include/pkix/pkixutil.h
index b224aa1f7..987195e7a 100644
--- a/lib/mozpkix/include/pkix/pkixutil.h
+++ b/lib/mozpkix/include/pkix/pkixutil.h
@@ -192,18 +192,6 @@ inline unsigned int DaysBeforeYear(unsigned int year) {
static const size_t MAX_DIGEST_SIZE_IN_BYTES = 512 / 8; // sha-512
-Result DigestSignedData(TrustDomain& trustDomain,
- const der::SignedDataWithSignature& signedData,
- /*out*/ uint8_t (&digestBuf)[MAX_DIGEST_SIZE_IN_BYTES],
- /*out*/ der::PublicKeyAlgorithm& publicKeyAlg,
- /*out*/ SignedDigest& signedDigest);
-
-Result VerifySignedDigest(TrustDomain& trustDomain,
- der::PublicKeyAlgorithm publicKeyAlg,
- const SignedDigest& signedDigest,
- Input signerSubjectPublicKeyInfo);
-
-// Combines DigestSignedData and VerifySignedDigest
Result VerifySignedData(TrustDomain& trustDomain,
const der::SignedDataWithSignature& signedData,
Input signerSubjectPublicKeyInfo);
diff --git a/lib/mozpkix/lib/pkixbuild.cpp b/lib/mozpkix/lib/pkixbuild.cpp
index afe7e2a24..aad74b3d9 100644
--- a/lib/mozpkix/lib/pkixbuild.cpp
+++ b/lib/mozpkix/lib/pkixbuild.cpp
@@ -61,7 +61,6 @@ public:
, stapledOCSPResponse(aStapledOCSPResponse)
, subCACount(aSubCACount)
, deferredSubjectError(aDeferredSubjectError)
- , subjectSignaturePublicKeyAlg(der::PublicKeyAlgorithm::Uninitialized)
, result(Result::FATAL_ERROR_LIBRARY_FAILURE)
, resultWasSet(false)
, buildForwardCallBudget(aBuildForwardCallBudget)
@@ -84,11 +83,6 @@ private:
const unsigned int subCACount;
const Result deferredSubjectError;
- // Initialized lazily.
- uint8_t subjectSignatureDigestBuf[MAX_DIGEST_SIZE_IN_BYTES];
- der::PublicKeyAlgorithm subjectSignaturePublicKeyAlg;
- SignedDigest subjectSignature;
-
Result RecordResult(Result currentResult, /*out*/ bool& keepGoing);
Result result;
bool resultWasSet;
@@ -215,22 +209,8 @@ PathBuildingStep::Check(Input potentialIssuerDER,
return RecordResult(rv, keepGoing);
}
- // Calculate the digest of the subject's signed data if we haven't already
- // done so. We do this lazily to avoid doing it at all if we backtrack before
- // getting to this point. We cache the result to avoid recalculating it if we
- // backtrack after getting to this point.
- if (subjectSignature.digest.GetLength() == 0) {
- rv = DigestSignedData(trustDomain, subject.GetSignedData(),
- subjectSignatureDigestBuf,
- subjectSignaturePublicKeyAlg, subjectSignature);
- if (rv != Success) {
- return rv;
- }
- }
-
- rv = VerifySignedDigest(trustDomain, subjectSignaturePublicKeyAlg,
- subjectSignature,
- potentialIssuer.GetSubjectPublicKeyInfo());
+ rv = VerifySignedData(trustDomain, subject.GetSignedData(),
+ potentialIssuer.GetSubjectPublicKeyInfo());
if (rv != Success) {
return RecordResult(rv, keepGoing);
}
diff --git a/lib/mozpkix/lib/pkixc.cpp b/lib/mozpkix/lib/pkixc.cpp
index ec8cc120a..5b30af33f 100644
--- a/lib/mozpkix/lib/pkixc.cpp
+++ b/lib/mozpkix/lib/pkixc.cpp
@@ -110,10 +110,11 @@ class CodeSigningTrustDomain final : public TrustDomain {
return Success;
}
- virtual Result VerifyRSAPKCS1SignedDigest(
- const SignedDigest& signedDigest, Input subjectPublicKeyInfo) override {
- return VerifyRSAPKCS1SignedDigestNSS(signedDigest, subjectPublicKeyInfo,
- nullptr);
+ virtual Result VerifyRSAPKCS1SignedData(
+ Input data, DigestAlgorithm digestAlgorithm, Input signature,
+ Input subjectPublicKeyInfo) override {
+ return VerifyRSAPKCS1SignedDataNSS(data, digestAlgorithm, signature,
+ subjectPublicKeyInfo, nullptr);
}
virtual Result CheckECDSACurveIsAcceptable(EndEntityOrCA endEntityOrCA,
@@ -128,10 +129,11 @@ class CodeSigningTrustDomain final : public TrustDomain {
return Result::ERROR_UNSUPPORTED_ELLIPTIC_CURVE;
}
- virtual Result VerifyECDSASignedDigest(const SignedDigest& signedDigest,
- Input subjectPublicKeyInfo) override {
- return VerifyECDSASignedDigestNSS(signedDigest, subjectPublicKeyInfo,
- nullptr);
+ virtual Result VerifyECDSASignedData(
+ Input data, DigestAlgorithm digestAlgorithm, Input signature,
+ Input subjectPublicKeyInfo) override {
+ return VerifyECDSASignedDataNSS(data, digestAlgorithm, signature,
+ subjectPublicKeyInfo, nullptr);
}
virtual Result CheckValidityIsAcceptable(Time notBefore, Time notAfter,
diff --git a/lib/mozpkix/lib/pkixcheck.cpp b/lib/mozpkix/lib/pkixcheck.cpp
index 317db01e2..a0079f305 100644
--- a/lib/mozpkix/lib/pkixcheck.cpp
+++ b/lib/mozpkix/lib/pkixcheck.cpp
@@ -117,11 +117,6 @@ CheckSignatureAlgorithm(TrustDomain& trustDomain,
// for any curve that we support, the chances of us encountering a curve
// during path building is too low to be worth bothering with.
break;
- case der::PublicKeyAlgorithm::Uninitialized:
- {
- assert(false);
- return Result::FATAL_ERROR_LIBRARY_FAILURE;
- }
MOZILLA_PKIX_UNREACHABLE_DEFAULT_ENUM
}
diff --git a/lib/mozpkix/lib/pkixder.cpp b/lib/mozpkix/lib/pkixder.cpp
index 152d11a23..9dccc9639 100644
--- a/lib/mozpkix/lib/pkixder.cpp
+++ b/lib/mozpkix/lib/pkixder.cpp
@@ -608,4 +608,58 @@ OptionalVersion(Reader& input, /*out*/ Version& version)
});
}
+// From RFC 5480 Appendix A:
+// ECDSA-Sig-Value ::= SEQUENCE {
+// r INTEGER,
+// s INTEGER
+// }
+Result
+ECDSASigValue(Input ecdsaSignature, /*out*/ Input& r, /*out*/ Input& s) {
+ Reader rAndS;
+ Result rv = ExpectTagAndGetValueAtEnd(ecdsaSignature, SEQUENCE, rAndS);
+ if (rv != Success) {
+ return rv;
+ }
+
+ Input rInput;
+ Input::size_type rSignificantBytes;
+ rv = PositiveInteger(rAndS, rInput, &rSignificantBytes);
+ if (rv != Success) {
+ return rv;
+ }
+ Reader rReader(rInput);
+ // Address potential leading 0 byte due to DER encoding.
+ if (rSignificantBytes + 1 == rInput.GetLength()) {
+ rv = rReader.Skip(1);
+ if (rv != Success) {
+ return rv;
+ }
+ }
+ rv = rReader.SkipToEnd(r);
+ if (rv != Success) {
+ return rv;
+ }
+
+ Input sInput;
+ Input::size_type sSignificantBytes;
+ rv = PositiveInteger(rAndS, sInput, &sSignificantBytes);
+ if (rv != Success) {
+ return rv;
+ }
+ Reader sReader(sInput);
+ // Address potential leading 0 byte due to DER encoding.
+ if (sSignificantBytes + 1 == sInput.GetLength()) {
+ rv = sReader.Skip(1);
+ if (rv != Success) {
+ return rv;
+ }
+ }
+ rv = sReader.SkipToEnd(s);
+ if (rv != Success) {
+ return rv;
+ }
+
+ return End(rAndS);
+}
+
} } } // namespace mozilla::pkix::der
diff --git a/lib/mozpkix/lib/pkixnss.cpp b/lib/mozpkix/lib/pkixnss.cpp
index 9b293d5fd..06c1bdcbd 100644
--- a/lib/mozpkix/lib/pkixnss.cpp
+++ b/lib/mozpkix/lib/pkixnss.cpp
@@ -40,63 +40,181 @@ namespace mozilla { namespace pkix {
namespace {
Result
-VerifySignedDigest(const SignedDigest& sd,
- Input subjectPublicKeyInfo,
- SECOidTag pubKeyAlg,
- void* pkcs11PinArg)
+SubjectPublicKeyInfoToSECKEYPublicKey(Input subjectPublicKeyInfo,
+ ScopedSECKEYPublicKey& publicKey)
{
- SECOidTag digestAlg;
- switch (sd.digestAlgorithm) {
- case DigestAlgorithm::sha512: digestAlg = SEC_OID_SHA512; break;
- case DigestAlgorithm::sha384: digestAlg = SEC_OID_SHA384; break;
- case DigestAlgorithm::sha256: digestAlg = SEC_OID_SHA256; break;
- case DigestAlgorithm::sha1: digestAlg = SEC_OID_SHA1; break;
- MOZILLA_PKIX_UNREACHABLE_DEFAULT_ENUM
- }
-
- SECItem subjectPublicKeyInfoSECItem =
- UnsafeMapInputToSECItem(subjectPublicKeyInfo);
- ScopedCERTSubjectPublicKeyInfo
- spki(SECKEY_DecodeDERSubjectPublicKeyInfo(&subjectPublicKeyInfoSECItem));
+ SECItem subjectPublicKeyInfoSECItem(
+ UnsafeMapInputToSECItem(subjectPublicKeyInfo));
+ ScopedCERTSubjectPublicKeyInfo spki(
+ SECKEY_DecodeDERSubjectPublicKeyInfo(&subjectPublicKeyInfoSECItem));
if (!spki) {
return MapPRErrorCodeToResult(PR_GetError());
}
- ScopedSECKEYPublicKey
- pubKey(SECKEY_ExtractPublicKey(spki.get()));
- if (!pubKey) {
+ publicKey.reset(SECKEY_ExtractPublicKey(spki.get()));
+ if (!publicKey) {
return MapPRErrorCodeToResult(PR_GetError());
}
+ return Success;
+}
- SECItem digestSECItem(UnsafeMapInputToSECItem(sd.digest));
- SECItem signatureSECItem(UnsafeMapInputToSECItem(sd.signature));
- SECStatus srv = VFY_VerifyDigestDirect(&digestSECItem, pubKey.get(),
- &signatureSECItem, pubKeyAlg,
- digestAlg, pkcs11PinArg);
+Result
+VerifySignedData(SECKEYPublicKey* publicKey, CK_MECHANISM_TYPE mechanism,
+ SECItem* params, SECItem* signature, SECItem* data,
+ SECOidTag (&policyTags)[3], void* pkcs11PinArg)
+{
+ // Hash and signature algorithms can be disabled by policy in NSS. However,
+ // the policy engine in NSS is not currently sophisticated enough to, for
+ // example, infer that disabling SEC_OID_SHA1 (i.e. the hash algorithm SHA1)
+ // should also disable SEC_OID_PKCS1_SHA1_WITH_RSA_ENCRYPTION. Thus, this
+ // implementation checks the signature algorithm, the hash algorithm, and the
+ // signature algorithm with the hash algorithm together.
+ for (size_t i = 0; i < sizeof(policyTags) / sizeof(policyTags[0]); i++) {
+ SECOidTag policyTag = policyTags[i];
+ uint32_t policyFlags;
+ if (NSS_GetAlgorithmPolicy(policyTag, &policyFlags) != SECSuccess) {
+ return MapPRErrorCodeToResult(PR_GetError());
+ }
+ if (!(policyFlags & NSS_USE_ALG_IN_ANY_SIGNATURE)) {
+ return MapPRErrorCodeToResult(SEC_ERROR_SIGNATURE_ALGORITHM_DISABLED);
+ }
+ }
+ SECStatus srv = PK11_VerifyWithMechanism(publicKey, mechanism, params,
+ signature, data, pkcs11PinArg);
if (srv != SECSuccess) {
return MapPRErrorCodeToResult(PR_GetError());
}
-
return Success;
}
-
} // namespace
Result
-VerifyRSAPKCS1SignedDigestNSS(const SignedDigest& sd,
- Input subjectPublicKeyInfo,
- void* pkcs11PinArg)
+VerifyRSAPKCS1SignedDataNSS(Input data, DigestAlgorithm digestAlgorithm,
+ Input signature, Input subjectPublicKeyInfo, void* pkcs11PinArg)
{
- return VerifySignedDigest(sd, subjectPublicKeyInfo,
- SEC_OID_PKCS1_RSA_ENCRYPTION, pkcs11PinArg);
+ ScopedSECKEYPublicKey publicKey;
+ Result rv = SubjectPublicKeyInfoToSECKEYPublicKey(subjectPublicKeyInfo,
+ publicKey);
+ if (rv != Success) {
+ return rv;
+ }
+ SECItem signatureItem(UnsafeMapInputToSECItem(signature));
+ SECItem dataItem(UnsafeMapInputToSECItem(data));
+ CK_MECHANISM_TYPE mechanism;
+ SECOidTag signaturePolicyTag = SEC_OID_PKCS1_RSA_ENCRYPTION;
+ SECOidTag hashPolicyTag;
+ SECOidTag combinedPolicyTag;
+ switch (digestAlgorithm) {
+ case DigestAlgorithm::sha512:
+ mechanism = CKM_SHA512_RSA_PKCS;
+ hashPolicyTag = SEC_OID_SHA512;
+ combinedPolicyTag = SEC_OID_PKCS1_SHA512_WITH_RSA_ENCRYPTION;
+ break;
+ case DigestAlgorithm::sha384:
+ mechanism = CKM_SHA384_RSA_PKCS;
+ hashPolicyTag = SEC_OID_SHA384;
+ combinedPolicyTag = SEC_OID_PKCS1_SHA384_WITH_RSA_ENCRYPTION;
+ break;
+ case DigestAlgorithm::sha256:
+ mechanism = CKM_SHA256_RSA_PKCS;
+ hashPolicyTag = SEC_OID_SHA256;
+ combinedPolicyTag = SEC_OID_PKCS1_SHA256_WITH_RSA_ENCRYPTION;
+ break;
+ case DigestAlgorithm::sha1:
+ mechanism = CKM_SHA1_RSA_PKCS;
+ hashPolicyTag = SEC_OID_SHA1;
+ combinedPolicyTag = SEC_OID_PKCS1_SHA1_WITH_RSA_ENCRYPTION;
+ break;
+ MOZILLA_PKIX_UNREACHABLE_DEFAULT_ENUM
+ }
+ SECOidTag policyTags[3] =
+ { signaturePolicyTag, hashPolicyTag, combinedPolicyTag };
+ return VerifySignedData(publicKey.get(), mechanism, nullptr, &signatureItem,
+ &dataItem, policyTags, pkcs11PinArg);
}
Result
-VerifyECDSASignedDigestNSS(const SignedDigest& sd,
- Input subjectPublicKeyInfo,
- void* pkcs11PinArg)
+EncodedECDSASignatureToRawPoint(Input signature,
+ const ScopedSECKEYPublicKey& publicKey, ScopedSECItem& result) {
+ Input r;
+ Input s;
+ Result rv = der::ECDSASigValue(signature, r, s);
+ if (rv != Success) {
+ return Result::ERROR_BAD_SIGNATURE;
+ }
+ size_t signatureLength = SECKEY_SignatureLen(publicKey.get());
+ if (signatureLength == 0) {
+ return MapPRErrorCodeToResult(PR_GetError());
+ }
+ if (signatureLength % 2 != 0) {
+ return Result::FATAL_ERROR_LIBRARY_FAILURE;
+ }
+ size_t coordinateLength = signatureLength / 2;
+ if (r.GetLength() > coordinateLength || s.GetLength() > coordinateLength) {
+ return Result::ERROR_BAD_SIGNATURE;
+ }
+ ScopedSECItem signatureItem(
+ SECITEM_AllocItem(nullptr, nullptr, signatureLength));
+ if (!signatureItem) {
+ return Result::FATAL_ERROR_NO_MEMORY;
+ }
+ memset(signatureItem->data, 0, signatureLength);
+ memcpy(signatureItem->data + (coordinateLength - r.GetLength()),
+ r.UnsafeGetData(), r.GetLength());
+ memcpy(signatureItem->data + (2 * coordinateLength - s.GetLength()),
+ s.UnsafeGetData(), s.GetLength());
+ result.swap(signatureItem);
+ return Success;
+}
+
+Result
+VerifyECDSASignedDataNSS(Input data, DigestAlgorithm digestAlgorithm,
+ Input signature, Input subjectPublicKeyInfo, void* pkcs11PinArg)
{
- return VerifySignedDigest(sd, subjectPublicKeyInfo,
- SEC_OID_ANSIX962_EC_PUBLIC_KEY, pkcs11PinArg);
+ ScopedSECKEYPublicKey publicKey;
+ Result rv = SubjectPublicKeyInfoToSECKEYPublicKey(subjectPublicKeyInfo,
+ publicKey);
+ if (rv != Success) {
+ return rv;
+ }
+
+ ScopedSECItem signatureItem;
+ rv = EncodedECDSASignatureToRawPoint(signature, publicKey, signatureItem);
+ if (rv != Success) {
+ return rv;
+ }
+
+ SECItem dataItem(UnsafeMapInputToSECItem(data));
+ CK_MECHANISM_TYPE mechanism;
+ SECOidTag signaturePolicyTag = SEC_OID_ANSIX962_EC_PUBLIC_KEY;
+ SECOidTag hashPolicyTag;
+ SECOidTag combinedPolicyTag;
+ switch (digestAlgorithm) {
+ case DigestAlgorithm::sha512:
+ mechanism = CKM_ECDSA_SHA512;
+ hashPolicyTag = SEC_OID_SHA512;
+ combinedPolicyTag = SEC_OID_ANSIX962_ECDSA_SHA512_SIGNATURE;
+ break;
+ case DigestAlgorithm::sha384:
+ mechanism = CKM_ECDSA_SHA384;
+ hashPolicyTag = SEC_OID_SHA384;
+ combinedPolicyTag = SEC_OID_ANSIX962_ECDSA_SHA384_SIGNATURE;
+ break;
+ case DigestAlgorithm::sha256:
+ mechanism = CKM_ECDSA_SHA256;
+ hashPolicyTag = SEC_OID_SHA256;
+ combinedPolicyTag = SEC_OID_ANSIX962_ECDSA_SHA256_SIGNATURE;
+ break;
+ case DigestAlgorithm::sha1:
+ mechanism = CKM_ECDSA_SHA1;
+ hashPolicyTag = SEC_OID_SHA1;
+ combinedPolicyTag = SEC_OID_ANSIX962_ECDSA_SHA1_SIGNATURE;
+ break;
+ MOZILLA_PKIX_UNREACHABLE_DEFAULT_ENUM
+ }
+ SECOidTag policyTags[3] =
+ { signaturePolicyTag, hashPolicyTag, combinedPolicyTag };
+ return VerifySignedData(publicKey.get(), mechanism, nullptr,
+ signatureItem.get(), &dataItem, policyTags, pkcs11PinArg);
}
Result
diff --git a/lib/mozpkix/lib/pkixverify.cpp b/lib/mozpkix/lib/pkixverify.cpp
index bec570de6..5658386d2 100644
--- a/lib/mozpkix/lib/pkixverify.cpp
+++ b/lib/mozpkix/lib/pkixverify.cpp
@@ -27,15 +27,15 @@
namespace mozilla { namespace pkix {
Result
-DigestSignedData(TrustDomain& trustDomain,
+VerifySignedData(TrustDomain& trustDomain,
const der::SignedDataWithSignature& signedData,
- /*out*/ uint8_t(&digestBuf)[MAX_DIGEST_SIZE_IN_BYTES],
- /*out*/ der::PublicKeyAlgorithm& publicKeyAlg,
- /*out*/ SignedDigest& signedDigest)
+ Input signerSubjectPublicKeyInfo)
{
+ der::PublicKeyAlgorithm publicKeyAlg;
+ DigestAlgorithm digestAlgorithm;
Reader signatureAlg(signedData.algorithm);
Result rv = der::SignatureAlgorithmIdentifierValue(
- signatureAlg, publicKeyAlg, signedDigest.digestAlgorithm);
+ signatureAlg, publicKeyAlg, digestAlgorithm);
if (rv != Success) {
return rv;
}
@@ -43,57 +43,15 @@ DigestSignedData(TrustDomain& trustDomain,
return Result::ERROR_BAD_DER;
}
- size_t digestLen = DigestAlgorithmToSizeInBytes(signedDigest.digestAlgorithm);
- assert(digestLen <= sizeof(digestBuf));
-
- rv = trustDomain.DigestBuf(signedData.data, signedDigest.digestAlgorithm,
- digestBuf, digestLen);
- if (rv != Success) {
- return rv;
- }
- rv = signedDigest.digest.Init(digestBuf, digestLen);
- if (rv != Success) {
- return rv;
- }
-
- return signedDigest.signature.Init(signedData.signature);
-}
-
-Result
-VerifySignedDigest(TrustDomain& trustDomain,
- der::PublicKeyAlgorithm publicKeyAlg,
- const SignedDigest& signedDigest,
- Input signerSubjectPublicKeyInfo)
-{
switch (publicKeyAlg) {
case der::PublicKeyAlgorithm::ECDSA:
- return trustDomain.VerifyECDSASignedDigest(signedDigest,
- signerSubjectPublicKeyInfo);
+ return trustDomain.VerifyECDSASignedData(signedData.data,
+ digestAlgorithm, signedData.signature, signerSubjectPublicKeyInfo);
case der::PublicKeyAlgorithm::RSA_PKCS1:
- return trustDomain.VerifyRSAPKCS1SignedDigest(signedDigest,
- signerSubjectPublicKeyInfo);
- case der::PublicKeyAlgorithm::Uninitialized:
- assert(false);
- return Result::FATAL_ERROR_LIBRARY_FAILURE;
+ return trustDomain.VerifyRSAPKCS1SignedData(signedData.data,
+ digestAlgorithm, signedData.signature, signerSubjectPublicKeyInfo);
MOZILLA_PKIX_UNREACHABLE_DEFAULT_ENUM
}
}
-Result
-VerifySignedData(TrustDomain& trustDomain,
- const der::SignedDataWithSignature& signedData,
- Input signerSubjectPublicKeyInfo)
-{
- uint8_t digestBuf[MAX_DIGEST_SIZE_IN_BYTES];
- der::PublicKeyAlgorithm publicKeyAlg;
- SignedDigest signedDigest;
- Result rv = DigestSignedData(trustDomain, signedData, digestBuf,
- publicKeyAlg, signedDigest);
- if (rv != Success) {
- return rv;
- }
- return VerifySignedDigest(trustDomain, publicKeyAlg, signedDigest,
- signerSubjectPublicKeyInfo);
-}
-
} } // namespace mozilla::pkix
diff --git a/lib/mozpkix/test-lib/pkixtestnss.cpp b/lib/mozpkix/test-lib/pkixtestnss.cpp
index 1e50f46f4..45edf3ea7 100644
--- a/lib/mozpkix/test-lib/pkixtestnss.cpp
+++ b/lib/mozpkix/test-lib/pkixtestnss.cpp
@@ -335,21 +335,21 @@ GenerateDSSKeyPair()
}
Result
-TestVerifyECDSASignedDigest(const SignedDigest& signedDigest,
- Input subjectPublicKeyInfo)
+TestVerifyECDSASignedData(Input data, DigestAlgorithm digestAlgorithm,
+ Input signature, Input subjectPublicKeyInfo)
{
InitNSSIfNeeded();
- return VerifyECDSASignedDigestNSS(signedDigest, subjectPublicKeyInfo,
- nullptr);
+ return VerifyECDSASignedDataNSS(data, digestAlgorithm, signature,
+ subjectPublicKeyInfo, nullptr);
}
Result
-TestVerifyRSAPKCS1SignedDigest(const SignedDigest& signedDigest,
- Input subjectPublicKeyInfo)
+TestVerifyRSAPKCS1SignedData(Input data, DigestAlgorithm digestAlgorithm,
+ Input signature, Input subjectPublicKeyInfo)
{
InitNSSIfNeeded();
- return VerifyRSAPKCS1SignedDigestNSS(signedDigest, subjectPublicKeyInfo,
- nullptr);
+ return VerifyRSAPKCS1SignedDataNSS(data, digestAlgorithm, signature,
+ subjectPublicKeyInfo, nullptr);
}
Result