| 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 "net/cert/nss_cert_database.h" | 5 #include "net/cert/nss_cert_database.h" |
| 6 | 6 |
| 7 #include <cert.h> | 7 #include <cert.h> |
| 8 #include <certdb.h> | 8 #include <certdb.h> |
| 9 #include <pk11pub.h> | 9 #include <pk11pub.h> |
| 10 | 10 |
| 11 #include <algorithm> | 11 #include <algorithm> |
| 12 #include <memory> | 12 #include <memory> |
| 13 | 13 |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/files/file_util.h" | 16 #include "base/files/file_util.h" |
| 17 #include "base/lazy_instance.h" | 17 #include "base/lazy_instance.h" |
| 18 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
| 19 #include "base/run_loop.h" | 19 #include "base/run_loop.h" |
| 20 #include "base/strings/string16.h" | 20 #include "base/strings/string16.h" |
| 21 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 23 #include "base/threading/thread_task_runner_handle.h" | 23 #include "base/threading/thread_task_runner_handle.h" |
| 24 #include "crypto/scoped_nss_types.h" | 24 #include "crypto/scoped_nss_types.h" |
| 25 #include "crypto/scoped_test_nss_db.h" | 25 #include "crypto/scoped_test_nss_db.h" |
| 26 #include "net/base/crypto_module.h" | 26 #include "net/base/crypto_module.h" |
| 27 #include "net/base/hash_value.h" |
| 27 #include "net/base/net_errors.h" | 28 #include "net/base/net_errors.h" |
| 28 #include "net/base/test_data_directory.h" | 29 #include "net/base/test_data_directory.h" |
| 29 #include "net/cert/cert_status_flags.h" | 30 #include "net/cert/cert_status_flags.h" |
| 30 #include "net/cert/cert_verify_proc_nss.h" | 31 #include "net/cert/cert_verify_proc_nss.h" |
| 31 #include "net/cert/cert_verify_result.h" | 32 #include "net/cert/cert_verify_result.h" |
| 32 #include "net/cert/x509_certificate.h" | 33 #include "net/cert/x509_certificate.h" |
| 33 #include "net/test/cert_test_util.h" | 34 #include "net/test/cert_test_util.h" |
| 34 #include "net/third_party/mozilla_security_manager/nsNSSCertificateDB.h" | 35 #include "net/third_party/mozilla_security_manager/nsNSSCertificateDB.h" |
| 35 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
| 36 | 37 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 CERTCertList* cert_list = PK11_ListCertsInSlot(test_nssdb_.slot()); | 103 CERTCertList* cert_list = PK11_ListCertsInSlot(test_nssdb_.slot()); |
| 103 for (CERTCertListNode* node = CERT_LIST_HEAD(cert_list); | 104 for (CERTCertListNode* node = CERT_LIST_HEAD(cert_list); |
| 104 !CERT_LIST_END(node, cert_list); | 105 !CERT_LIST_END(node, cert_list); |
| 105 node = CERT_LIST_NEXT(node)) { | 106 node = CERT_LIST_NEXT(node)) { |
| 106 result.push_back(X509Certificate::CreateFromHandle( | 107 result.push_back(X509Certificate::CreateFromHandle( |
| 107 node->cert, X509Certificate::OSCertHandles())); | 108 node->cert, X509Certificate::OSCertHandles())); |
| 108 } | 109 } |
| 109 CERT_DestroyCertList(cert_list); | 110 CERT_DestroyCertList(cert_list); |
| 110 | 111 |
| 111 // Sort the result so that test comparisons can be deterministic. | 112 // Sort the result so that test comparisons can be deterministic. |
| 112 std::sort(result.begin(), result.end(), X509Certificate::LessThan()); | 113 std::sort( |
| 114 result.begin(), result.end(), |
| 115 [](const scoped_refptr<X509Certificate>& lhs, |
| 116 const scoped_refptr<X509Certificate>& rhs) { |
| 117 return SHA256HashValueLessThan()( |
| 118 X509Certificate::CalculateFingerprint256(lhs->os_cert_handle()), |
| 119 X509Certificate::CalculateFingerprint256(rhs->os_cert_handle())); |
| 120 }); |
| 113 return result; | 121 return result; |
| 114 } | 122 } |
| 115 | 123 |
| 116 std::unique_ptr<NSSCertDatabase> cert_db_; | 124 std::unique_ptr<NSSCertDatabase> cert_db_; |
| 117 const CertificateList empty_cert_list_; | 125 const CertificateList empty_cert_list_; |
| 118 crypto::ScopedTestNSSDB test_nssdb_; | 126 crypto::ScopedTestNSSDB test_nssdb_; |
| 119 scoped_refptr<CryptoModule> public_module_; | 127 scoped_refptr<CryptoModule> public_module_; |
| 120 }; | 128 }; |
| 121 | 129 |
| 122 TEST_F(CertDatabaseNSSTest, ListCertsSync) { | 130 TEST_F(CertDatabaseNSSTest, ListCertsSync) { |
| (...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 974 EXPECT_EQ(NSSCertDatabase::TRUST_DEFAULT, | 982 EXPECT_EQ(NSSCertDatabase::TRUST_DEFAULT, |
| 975 cert_db_->GetCertTrust(certs2[0].get(), SERVER_CERT)); | 983 cert_db_->GetCertTrust(certs2[0].get(), SERVER_CERT)); |
| 976 | 984 |
| 977 new_certs = ListCerts(); | 985 new_certs = ListCerts(); |
| 978 ASSERT_EQ(2U, new_certs.size()); | 986 ASSERT_EQ(2U, new_certs.size()); |
| 979 EXPECT_STRNE(new_certs[0]->os_cert_handle()->nickname, | 987 EXPECT_STRNE(new_certs[0]->os_cert_handle()->nickname, |
| 980 new_certs[1]->os_cert_handle()->nickname); | 988 new_certs[1]->os_cert_handle()->nickname); |
| 981 } | 989 } |
| 982 | 990 |
| 983 } // namespace net | 991 } // namespace net |
| OLD | NEW |