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(PK11_ReferenceSlot(test_nssdb_.slot())))); |
63 | 62 |
64 // Test db should be empty at start of test. | 63 // Test db should be empty at start of test. |
65 EXPECT_EQ(0U, ListCertsInSlot().size()); | 64 EXPECT_EQ(0U, ListCertsInSlot().size()); |
66 } | 65 } |
67 | 66 |
68 virtual void TearDown() { | 67 virtual void TearDown() { |
69 // Run the message loop to process any observer callbacks (e.g. for the | 68 // Run the message loop to process any observer callbacks (e.g. for the |
70 // ClientSocketFactory singleton) so that the scoped ref ptrs created in | 69 // ClientSocketFactory singleton) so that the scoped ref ptrs created in |
71 // NSSCertDatabase::NotifyObservers* get released. | 70 // NSSCertDatabase::NotifyObservers* get released. |
72 base::MessageLoop::current()->RunUntilIdle(); | 71 base::MessageLoop::current()->RunUntilIdle(); |
(...skipping 17 matching lines...) Expand all Loading... |
90 ImportCertFromFile(GetTestCertsDirectory(), name)); | 89 ImportCertFromFile(GetTestCertsDirectory(), name)); |
91 if (!cert.get()) | 90 if (!cert.get()) |
92 return false; | 91 return false; |
93 | 92 |
94 certs->push_back(cert); | 93 certs->push_back(cert); |
95 return true; | 94 return true; |
96 } | 95 } |
97 | 96 |
98 CertificateList ListCertsInSlot() { | 97 CertificateList ListCertsInSlot() { |
99 CertificateList result; | 98 CertificateList result; |
100 CERTCertList* cert_list = | 99 CERTCertList* cert_list = PK11_ListCertsInSlot(test_nssdb_.slot()); |
101 PK11_ListCertsInSlot(cert_db_->GetPublicSlot().get()); | |
102 for (CERTCertListNode* node = CERT_LIST_HEAD(cert_list); | 100 for (CERTCertListNode* node = CERT_LIST_HEAD(cert_list); |
103 !CERT_LIST_END(node, cert_list); | 101 !CERT_LIST_END(node, cert_list); |
104 node = CERT_LIST_NEXT(node)) { | 102 node = CERT_LIST_NEXT(node)) { |
105 result.push_back(X509Certificate::CreateFromHandle( | 103 result.push_back(X509Certificate::CreateFromHandle( |
106 node->cert, X509Certificate::OSCertHandles())); | 104 node->cert, X509Certificate::OSCertHandles())); |
107 } | 105 } |
108 CERT_DestroyCertList(cert_list); | 106 CERT_DestroyCertList(cert_list); |
109 | 107 |
110 // Sort the result so that test comparisons can be deterministic. | 108 // Sort the result so that test comparisons can be deterministic. |
111 std::sort(result.begin(), result.end(), X509Certificate::LessThan()); | 109 std::sort(result.begin(), result.end(), X509Certificate::LessThan()); |
(...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1015 EXPECT_EQ(NSSCertDatabase::TRUST_DEFAULT, | 1013 EXPECT_EQ(NSSCertDatabase::TRUST_DEFAULT, |
1016 cert_db_->GetCertTrust(certs2[0].get(), SERVER_CERT)); | 1014 cert_db_->GetCertTrust(certs2[0].get(), SERVER_CERT)); |
1017 | 1015 |
1018 new_certs = ListCertsInSlot(); | 1016 new_certs = ListCertsInSlot(); |
1019 ASSERT_EQ(2U, new_certs.size()); | 1017 ASSERT_EQ(2U, new_certs.size()); |
1020 EXPECT_STRNE(new_certs[0]->os_cert_handle()->nickname, | 1018 EXPECT_STRNE(new_certs[0]->os_cert_handle()->nickname, |
1021 new_certs[1]->os_cert_handle()->nickname); | 1019 new_certs[1]->os_cert_handle()->nickname); |
1022 } | 1020 } |
1023 | 1021 |
1024 } // namespace net | 1022 } // namespace net |
OLD | NEW |