| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <cert.h> | 5 #include <cert.h> |
| 6 #include <certdb.h> | 6 #include <certdb.h> |
| 7 #include <pk11pub.h> | 7 #include <pk11pub.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/message_loop/message_loop_proxy.h" | 16 #include "base/message_loop/message_loop_proxy.h" |
| 17 #include "base/path_service.h" | 17 #include "base/path_service.h" |
| 18 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
| 19 #include "base/strings/string16.h" | 19 #include "base/strings/string16.h" |
| 20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
| 21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| 22 #include "crypto/nss_util.h" | |
| 23 #include "crypto/nss_util_internal.h" | |
| 24 #include "crypto/scoped_nss_types.h" | 22 #include "crypto/scoped_nss_types.h" |
| 23 #include "crypto/scoped_test_nss_db.h" |
| 25 #include "net/base/crypto_module.h" | 24 #include "net/base/crypto_module.h" |
| 26 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
| 27 #include "net/base/test_data_directory.h" | 26 #include "net/base/test_data_directory.h" |
| 28 #include "net/cert/cert_status_flags.h" | 27 #include "net/cert/cert_status_flags.h" |
| 29 #include "net/cert/cert_verify_proc_nss.h" | 28 #include "net/cert/cert_verify_proc_nss.h" |
| 30 #include "net/cert/cert_verify_result.h" | 29 #include "net/cert/cert_verify_result.h" |
| 31 #include "net/cert/nss_cert_database.h" | 30 #include "net/cert/nss_cert_database.h" |
| 32 #include "net/cert/x509_certificate.h" | 31 #include "net/cert/x509_certificate.h" |
| 33 #include "net/test/cert_test_util.h" | 32 #include "net/test/cert_test_util.h" |
| 34 #include "net/third_party/mozilla_security_manager/nsNSSCertificateDB.h" | 33 #include "net/third_party/mozilla_security_manager/nsNSSCertificateDB.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 52 destination->swap(*source); | 51 destination->swap(*source); |
| 53 } | 52 } |
| 54 | 53 |
| 55 } // namespace | 54 } // namespace |
| 56 | 55 |
| 57 class CertDatabaseNSSTest : public testing::Test { | 56 class CertDatabaseNSSTest : public testing::Test { |
| 58 public: | 57 public: |
| 59 virtual void SetUp() { | 58 virtual void SetUp() { |
| 60 ASSERT_TRUE(test_nssdb_.is_open()); | 59 ASSERT_TRUE(test_nssdb_.is_open()); |
| 61 cert_db_.reset(new NSSCertDatabase( | 60 cert_db_.reset(new NSSCertDatabase( |
| 62 crypto::ScopedPK11Slot(crypto::GetPersistentNSSKeySlot()), | 61 crypto::ScopedPK11Slot( |
| 63 crypto::ScopedPK11Slot(crypto::GetPersistentNSSKeySlot()))); | 62 PK11_ReferenceSlot(test_nssdb_.slot())) /* public slot */, |
| 63 crypto::ScopedPK11Slot( |
| 64 PK11_ReferenceSlot(test_nssdb_.slot())) /* private slot */)); |
| 64 | 65 |
| 65 // Test db should be empty at start of test. | 66 // Test db should be empty at start of test. |
| 66 EXPECT_EQ(0U, ListCerts().size()); | 67 EXPECT_EQ(0U, ListCerts().size()); |
| 67 } | 68 } |
| 68 | 69 |
| 69 virtual void TearDown() { | 70 virtual void TearDown() { |
| 70 // Run the message loop to process any observer callbacks (e.g. for the | 71 // Run the message loop to process any observer callbacks (e.g. for the |
| 71 // ClientSocketFactory singleton) so that the scoped ref ptrs created in | 72 // ClientSocketFactory singleton) so that the scoped ref ptrs created in |
| 72 // NSSCertDatabase::NotifyObservers* get released. | 73 // NSSCertDatabase::NotifyObservers* get released. |
| 73 base::MessageLoop::current()->RunUntilIdle(); | 74 base::MessageLoop::current()->RunUntilIdle(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 91 ImportCertFromFile(GetTestCertsDirectory(), name)); | 92 ImportCertFromFile(GetTestCertsDirectory(), name)); |
| 92 if (!cert.get()) | 93 if (!cert.get()) |
| 93 return false; | 94 return false; |
| 94 | 95 |
| 95 certs->push_back(cert); | 96 certs->push_back(cert); |
| 96 return true; | 97 return true; |
| 97 } | 98 } |
| 98 | 99 |
| 99 CertificateList ListCerts() { | 100 CertificateList ListCerts() { |
| 100 CertificateList result; | 101 CertificateList result; |
| 101 | 102 CERTCertList* cert_list = PK11_ListCertsInSlot(test_nssdb_.slot()); |
| 102 CERTCertList* cert_list = | |
| 103 PK11_ListCertsInSlot(cert_db_->GetPublicSlot().get()); | |
| 104 for (CERTCertListNode* node = CERT_LIST_HEAD(cert_list); | 103 for (CERTCertListNode* node = CERT_LIST_HEAD(cert_list); |
| 105 !CERT_LIST_END(node, cert_list); | 104 !CERT_LIST_END(node, cert_list); |
| 106 node = CERT_LIST_NEXT(node)) { | 105 node = CERT_LIST_NEXT(node)) { |
| 107 result.push_back(X509Certificate::CreateFromHandle( | 106 result.push_back(X509Certificate::CreateFromHandle( |
| 108 node->cert, X509Certificate::OSCertHandles())); | 107 node->cert, X509Certificate::OSCertHandles())); |
| 109 } | 108 } |
| 110 CERT_DestroyCertList(cert_list); | 109 CERT_DestroyCertList(cert_list); |
| 111 | 110 |
| 112 // Sort the result so that test comparisons can be deterministic. | 111 // Sort the result so that test comparisons can be deterministic. |
| 113 std::sort(result.begin(), result.end(), X509Certificate::LessThan()); | 112 std::sort(result.begin(), result.end(), X509Certificate::LessThan()); |
| (...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1017 EXPECT_EQ(NSSCertDatabase::TRUST_DEFAULT, | 1016 EXPECT_EQ(NSSCertDatabase::TRUST_DEFAULT, |
| 1018 cert_db_->GetCertTrust(certs2[0].get(), SERVER_CERT)); | 1017 cert_db_->GetCertTrust(certs2[0].get(), SERVER_CERT)); |
| 1019 | 1018 |
| 1020 new_certs = ListCerts(); | 1019 new_certs = ListCerts(); |
| 1021 ASSERT_EQ(2U, new_certs.size()); | 1020 ASSERT_EQ(2U, new_certs.size()); |
| 1022 EXPECT_STRNE(new_certs[0]->os_cert_handle()->nickname, | 1021 EXPECT_STRNE(new_certs[0]->os_cert_handle()->nickname, |
| 1023 new_certs[1]->os_cert_handle()->nickname); | 1022 new_certs[1]->os_cert_handle()->nickname); |
| 1024 } | 1023 } |
| 1025 | 1024 |
| 1026 } // namespace net | 1025 } // namespace net |
| OLD | NEW |