| 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/socket/ssl_client_socket.h" | 5 #include "net/socket/ssl_client_socket.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include <openssl/bio.h> | 10 #include <openssl/bio.h> |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 #if defined(USE_OPENSSL_CERTS) | 51 #if defined(USE_OPENSSL_CERTS) |
| 52 | 52 |
| 53 const SSLConfig kDefaultSSLConfig; | 53 const SSLConfig kDefaultSSLConfig; |
| 54 | 54 |
| 55 // Loads a PEM-encoded private key file into a scoped EVP_PKEY object. | 55 // Loads a PEM-encoded private key file into a scoped EVP_PKEY object. |
| 56 // |filepath| is the private key file path. | 56 // |filepath| is the private key file path. |
| 57 // |*pkey| is reset to the new EVP_PKEY on success, untouched otherwise. | 57 // |*pkey| is reset to the new EVP_PKEY on success, untouched otherwise. |
| 58 // Returns true on success, false on failure. | 58 // Returns true on success, false on failure. |
| 59 bool LoadPrivateKeyOpenSSL( | 59 bool LoadPrivateKeyOpenSSL( |
| 60 const base::FilePath& filepath, | 60 const base::FilePath& filepath, |
| 61 OpenSSLClientKeyStore::ScopedEVP_PKEY* pkey) { | 61 crypto::ScopedEVP_PKEY* pkey) { |
| 62 std::string data; | 62 std::string data; |
| 63 if (!base::ReadFileToString(filepath, &data)) { | 63 if (!base::ReadFileToString(filepath, &data)) { |
| 64 LOG(ERROR) << "Could not read private key file: " | 64 LOG(ERROR) << "Could not read private key file: " |
| 65 << filepath.value() << ": " << strerror(errno); | 65 << filepath.value() << ": " << strerror(errno); |
| 66 return false; | 66 return false; |
| 67 } | 67 } |
| 68 crypto::ScopedBIO bio(BIO_new_mem_buf( | 68 crypto::ScopedBIO bio(BIO_new_mem_buf( |
| 69 const_cast<char*>(reinterpret_cast<const char*>(data.data())), | 69 const_cast<char*>(reinterpret_cast<const char*>(data.data())), |
| 70 static_cast<int>(data.size()))); | 70 static_cast<int>(data.size()))); |
| 71 if (!bio.get()) { | 71 if (!bio.get()) { |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 | 243 |
| 244 ASSERT_TRUE(ConnectToTestServer(ssl_options)); | 244 ASSERT_TRUE(ConnectToTestServer(ssl_options)); |
| 245 | 245 |
| 246 base::FilePath certs_dir = GetTestCertsDirectory(); | 246 base::FilePath certs_dir = GetTestCertsDirectory(); |
| 247 SSLConfig ssl_config = kDefaultSSLConfig; | 247 SSLConfig ssl_config = kDefaultSSLConfig; |
| 248 ssl_config.send_client_cert = true; | 248 ssl_config.send_client_cert = true; |
| 249 ssl_config.client_cert = ImportCertFromFile(certs_dir, "client_1.pem"); | 249 ssl_config.client_cert = ImportCertFromFile(certs_dir, "client_1.pem"); |
| 250 | 250 |
| 251 // This is required to ensure that signing works with the client | 251 // This is required to ensure that signing works with the client |
| 252 // certificate's private key. | 252 // certificate's private key. |
| 253 OpenSSLClientKeyStore::ScopedEVP_PKEY client_private_key; | 253 crypto::ScopedEVP_PKEY client_private_key; |
| 254 ASSERT_TRUE(LoadPrivateKeyOpenSSL(certs_dir.AppendASCII("client_1.key"), | 254 ASSERT_TRUE(LoadPrivateKeyOpenSSL(certs_dir.AppendASCII("client_1.key"), |
| 255 &client_private_key)); | 255 &client_private_key)); |
| 256 EXPECT_TRUE(RecordPrivateKey(ssl_config, client_private_key.get())); | 256 EXPECT_TRUE(RecordPrivateKey(ssl_config, client_private_key.get())); |
| 257 | 257 |
| 258 int rv; | 258 int rv; |
| 259 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv)); | 259 ASSERT_TRUE(CreateAndConnectSSLClientSocket(ssl_config, &rv)); |
| 260 | 260 |
| 261 EXPECT_EQ(OK, rv); | 261 EXPECT_EQ(OK, rv); |
| 262 EXPECT_TRUE(sock_->IsConnected()); | 262 EXPECT_TRUE(sock_->IsConnected()); |
| 263 | 263 |
| 264 EXPECT_TRUE(CheckSSLClientSocketSentCert()); | 264 EXPECT_TRUE(CheckSSLClientSocketSentCert()); |
| 265 | 265 |
| 266 sock_->Disconnect(); | 266 sock_->Disconnect(); |
| 267 EXPECT_FALSE(sock_->IsConnected()); | 267 EXPECT_FALSE(sock_->IsConnected()); |
| 268 } | 268 } |
| 269 #endif // defined(USE_OPENSSL_CERTS) | 269 #endif // defined(USE_OPENSSL_CERTS) |
| 270 | 270 |
| 271 } // namespace | 271 } // namespace |
| 272 } // namespace net | 272 } // namespace net |
| OLD | NEW |