OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chromeos/network/network_cert_migrator.h" | 5 #include "chromeos/network/network_cert_migrator.h" |
6 | 6 |
7 #include <cert.h> | 7 #include <cert.h> |
8 | 8 |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 | 108 |
109 void SetupTestClientCert() { | 109 void SetupTestClientCert() { |
110 std::string pkcs12_data; | 110 std::string pkcs12_data; |
111 ASSERT_TRUE(base::ReadFileToString( | 111 ASSERT_TRUE(base::ReadFileToString( |
112 net::GetTestCertsDirectory().Append("websocket_client_cert.p12"), | 112 net::GetTestCertsDirectory().Append("websocket_client_cert.p12"), |
113 &pkcs12_data)); | 113 &pkcs12_data)); |
114 | 114 |
115 net::CertificateList client_cert_list; | 115 net::CertificateList client_cert_list; |
116 scoped_refptr<net::CryptoModule> module(net::CryptoModule::CreateFromHandle( | 116 scoped_refptr<net::CryptoModule> module(net::CryptoModule::CreateFromHandle( |
117 test_nssdb_->GetPrivateSlot().get())); | 117 test_nssdb_->GetPrivateSlot().get())); |
118 ASSERT_EQ( | 118 ASSERT_EQ(net::OK, |
119 net::OK, | 119 test_nssdb_->ImportFromPKCS12(module.get(), |
120 test_nssdb_->ImportFromPKCS12( | 120 pkcs12_data, |
121 module, pkcs12_data, base::string16(), false, &client_cert_list)); | 121 base::string16(), |
| 122 false, |
| 123 &client_cert_list)); |
122 ASSERT_TRUE(!client_cert_list.empty()); | 124 ASSERT_TRUE(!client_cert_list.empty()); |
123 test_client_cert_ = client_cert_list[0]; | 125 test_client_cert_ = client_cert_list[0]; |
124 | 126 |
125 int slot_id = -1; | 127 int slot_id = -1; |
126 test_client_cert_pkcs11_id_ = CertLoader::GetPkcs11IdAndSlotForCert( | 128 test_client_cert_pkcs11_id_ = CertLoader::GetPkcs11IdAndSlotForCert( |
127 *test_client_cert_, &slot_id); | 129 *test_client_cert_, &slot_id); |
128 ASSERT_FALSE(test_client_cert_pkcs11_id_.empty()); | 130 ASSERT_FALSE(test_client_cert_pkcs11_id_.empty()); |
129 ASSERT_NE(-1, slot_id); | 131 ASSERT_NE(-1, slot_id); |
130 test_client_cert_slot_id_ = base::IntToString(slot_id); | 132 test_client_cert_slot_id_ = base::IntToString(slot_id); |
131 } | 133 } |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 ShillServiceClient::TestInterface* service_test_; | 285 ShillServiceClient::TestInterface* service_test_; |
284 scoped_refptr<net::X509Certificate> test_ca_cert_; | 286 scoped_refptr<net::X509Certificate> test_ca_cert_; |
285 scoped_refptr<net::X509Certificate> test_client_cert_; | 287 scoped_refptr<net::X509Certificate> test_client_cert_; |
286 std::string test_client_cert_pkcs11_id_; | 288 std::string test_client_cert_pkcs11_id_; |
287 std::string test_client_cert_slot_id_; | 289 std::string test_client_cert_slot_id_; |
288 std::string test_ca_cert_pem_; | 290 std::string test_ca_cert_pem_; |
289 base::MessageLoop message_loop_; | 291 base::MessageLoop message_loop_; |
290 | 292 |
291 private: | 293 private: |
292 void CleanupTestCert() { | 294 void CleanupTestCert() { |
293 if (test_ca_cert_) | 295 if (test_ca_cert_.get()) |
294 ASSERT_TRUE(test_nssdb_->DeleteCertAndKey(test_ca_cert_.get())); | 296 ASSERT_TRUE(test_nssdb_->DeleteCertAndKey(test_ca_cert_.get())); |
295 | 297 |
296 if (test_client_cert_) | 298 if (test_client_cert_.get()) |
297 ASSERT_TRUE(test_nssdb_->DeleteCertAndKey(test_client_cert_.get())); | 299 ASSERT_TRUE(test_nssdb_->DeleteCertAndKey(test_client_cert_.get())); |
298 } | 300 } |
299 | 301 |
300 scoped_ptr<NetworkStateHandler> network_state_handler_; | 302 scoped_ptr<NetworkStateHandler> network_state_handler_; |
301 scoped_ptr<NetworkCertMigrator> network_cert_migrator_; | 303 scoped_ptr<NetworkCertMigrator> network_cert_migrator_; |
302 crypto::ScopedTestNSSChromeOSUser user_; | 304 crypto::ScopedTestNSSChromeOSUser user_; |
303 scoped_ptr<net::NSSCertDatabaseChromeOS> test_nssdb_; | 305 scoped_ptr<net::NSSCertDatabaseChromeOS> test_nssdb_; |
304 | 306 |
305 DISALLOW_COPY_AND_ASSIGN(NetworkCertMigratorTest); | 307 DISALLOW_COPY_AND_ASSIGN(NetworkCertMigratorTest); |
306 }; | 308 }; |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 base::RunLoop().RunUntilIdle(); | 498 base::RunLoop().RunUntilIdle(); |
497 | 499 |
498 std::string pkcs11_id; | 500 std::string pkcs11_id; |
499 std::string slot_id; | 501 std::string slot_id; |
500 GetVpnCertId(false /* IPsec */, &slot_id, &pkcs11_id); | 502 GetVpnCertId(false /* IPsec */, &slot_id, &pkcs11_id); |
501 EXPECT_EQ(test_client_cert_pkcs11_id_, pkcs11_id); | 503 EXPECT_EQ(test_client_cert_pkcs11_id_, pkcs11_id); |
502 EXPECT_EQ(test_client_cert_slot_id_, slot_id); | 504 EXPECT_EQ(test_client_cert_slot_id_, slot_id); |
503 } | 505 } |
504 | 506 |
505 } // namespace chromeos | 507 } // namespace chromeos |
OLD | NEW |