| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/cert/internal/trust_store_nss.h" | 5 #include "net/cert/internal/trust_store_nss.h" |
| 6 | 6 |
| 7 #include <cert.h> | 7 #include <cert.h> |
| 8 #include <certdb.h> | 8 #include <certdb.h> |
| 9 | 9 |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "crypto/scoped_test_nss_db.h" | 12 #include "crypto/scoped_test_nss_db.h" |
| 13 #include "net/cert/internal/test_helpers.h" | 13 #include "net/cert/internal/test_helpers.h" |
| 14 #include "net/cert/scoped_nss_types.h" | 14 #include "net/cert/scoped_nss_types.h" |
| 15 #include "net/cert/x509_certificate.h" | 15 #include "net/cert/x509_certificate.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 17 |
| 18 namespace net { | 18 namespace net { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 class TrustStoreNSSTest : public testing::Test { | 22 class TrustStoreNSSTest : public testing::Test { |
| 23 public: | 23 public: |
| 24 void SetUp() override { | 24 void SetUp() override { |
| 25 ASSERT_TRUE(test_nssdb_.is_open()); | 25 ASSERT_TRUE(test_nssdb_.is_open()); |
| 26 | 26 |
| 27 VerifyCertChainTest test; |
| 27 ParsedCertificateList chain; | 28 ParsedCertificateList chain; |
| 28 bool unused_verify_result; | |
| 29 der::GeneralizedTime unused_time; | |
| 30 std::string unused_errors; | |
| 31 | |
| 32 ReadVerifyCertChainTestFromFile( | 29 ReadVerifyCertChainTestFromFile( |
| 33 "net/data/verify_certificate_chain_unittest/key-rollover-oldchain.pem", | 30 "net/data/verify_certificate_chain_unittest/key-rollover-oldchain.pem", |
| 34 &chain, &oldroot_, &unused_time, &unused_verify_result, &unused_errors); | 31 &test); |
| 32 chain = test.chain; |
| 33 oldroot_ = test.trust_anchor; |
| 34 |
| 35 ASSERT_EQ(2U, chain.size()); | 35 ASSERT_EQ(2U, chain.size()); |
| 36 target_ = chain[0]; | 36 target_ = chain[0]; |
| 37 oldintermediate_ = chain[1]; | 37 oldintermediate_ = chain[1]; |
| 38 ASSERT_TRUE(target_); | 38 ASSERT_TRUE(target_); |
| 39 ASSERT_TRUE(oldintermediate_); | 39 ASSERT_TRUE(oldintermediate_); |
| 40 ASSERT_TRUE(oldroot_); | 40 ASSERT_TRUE(oldroot_); |
| 41 | 41 |
| 42 scoped_refptr<TrustAnchor> unused_root; | |
| 43 ReadVerifyCertChainTestFromFile( | 42 ReadVerifyCertChainTestFromFile( |
| 44 "net/data/verify_certificate_chain_unittest/" | 43 "net/data/verify_certificate_chain_unittest/" |
| 45 "key-rollover-longrolloverchain.pem", | 44 "key-rollover-longrolloverchain.pem", |
| 46 &chain, &unused_root, &unused_time, &unused_verify_result, | 45 &test); |
| 47 &unused_errors); | 46 chain = test.chain; |
| 47 |
| 48 ASSERT_EQ(4U, chain.size()); | 48 ASSERT_EQ(4U, chain.size()); |
| 49 newintermediate_ = chain[1]; | 49 newintermediate_ = chain[1]; |
| 50 newroot_ = TrustAnchor::CreateFromCertificateNoConstraints(chain[2]); | 50 newroot_ = TrustAnchor::CreateFromCertificateNoConstraints(chain[2]); |
| 51 newrootrollover_ = chain[3]; | 51 newrootrollover_ = chain[3]; |
| 52 ASSERT_TRUE(newintermediate_); | 52 ASSERT_TRUE(newintermediate_); |
| 53 ASSERT_TRUE(newroot_); | 53 ASSERT_TRUE(newroot_); |
| 54 ASSERT_TRUE(newrootrollover_); | 54 ASSERT_TRUE(newrootrollover_); |
| 55 | 55 |
| 56 trust_store_nss_.reset(new TrustStoreNSS(trustSSL)); | 56 trust_store_nss_.reset(new TrustStoreNSS(trustSSL)); |
| 57 } | 57 } |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 TrustCert(newroot_.get()); | 195 TrustCert(newroot_.get()); |
| 196 EXPECT_TRUE(TrustStoreContains(target_, TrustAnchors())); | 196 EXPECT_TRUE(TrustStoreContains(target_, TrustAnchors())); |
| 197 EXPECT_TRUE(TrustStoreContains(newintermediate_, {newroot_, oldroot_})); | 197 EXPECT_TRUE(TrustStoreContains(newintermediate_, {newroot_, oldroot_})); |
| 198 EXPECT_TRUE(TrustStoreContains(oldintermediate_, {newroot_, oldroot_})); | 198 EXPECT_TRUE(TrustStoreContains(oldintermediate_, {newroot_, oldroot_})); |
| 199 EXPECT_TRUE(TrustStoreContains(oldroot_->cert(), {newroot_, oldroot_})); | 199 EXPECT_TRUE(TrustStoreContains(oldroot_->cert(), {newroot_, oldroot_})); |
| 200 } | 200 } |
| 201 | 201 |
| 202 } // namespace | 202 } // namespace |
| 203 | 203 |
| 204 } // namespace net | 204 } // namespace net |
| OLD | NEW |