Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(456)

Side by Side Diff: net/socket/ssl_client_socket_unittest.cc

Issue 2400033005: Use BoringSSL scopers in //net. (Closed)
Patch Set: eroman comments Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/socket/ssl_client_socket_impl.cc ('k') | net/socket/ssl_server_socket_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <utility> 10 #include <utility>
11 11
12 #include <openssl/bio.h> 12 #include <openssl/bio.h>
13 #include <openssl/evp.h> 13 #include <openssl/evp.h>
14 #include <openssl/pem.h> 14 #include <openssl/pem.h>
15 15
16 #include "base/callback_helpers.h" 16 #include "base/callback_helpers.h"
17 #include "base/files/file_util.h" 17 #include "base/files/file_util.h"
18 #include "base/location.h" 18 #include "base/location.h"
19 #include "base/macros.h" 19 #include "base/macros.h"
20 #include "base/memory/ref_counted.h" 20 #include "base/memory/ref_counted.h"
21 #include "base/run_loop.h" 21 #include "base/run_loop.h"
22 #include "base/single_thread_task_runner.h" 22 #include "base/single_thread_task_runner.h"
23 #include "base/threading/thread_task_runner_handle.h" 23 #include "base/threading/thread_task_runner_handle.h"
24 #include "base/time/time.h" 24 #include "base/time/time.h"
25 #include "crypto/scoped_openssl_types.h"
26 #include "net/base/address_list.h" 25 #include "net/base/address_list.h"
27 #include "net/base/io_buffer.h" 26 #include "net/base/io_buffer.h"
28 #include "net/base/net_errors.h" 27 #include "net/base/net_errors.h"
29 #include "net/base/test_completion_callback.h" 28 #include "net/base/test_completion_callback.h"
30 #include "net/cert/asn1_util.h" 29 #include "net/cert/asn1_util.h"
31 #include "net/cert/ct_policy_enforcer.h" 30 #include "net/cert/ct_policy_enforcer.h"
32 #include "net/cert/ct_policy_status.h" 31 #include "net/cert/ct_policy_status.h"
33 #include "net/cert/ct_verifier.h" 32 #include "net/cert/ct_verifier.h"
34 #include "net/cert/mock_cert_verifier.h" 33 #include "net/cert/mock_cert_verifier.h"
35 #include "net/cert/test_root_certs.h" 34 #include "net/cert/test_root_certs.h"
(...skipping 3097 matching lines...) Expand 10 before | Expand all | Expand 10 after
3133 // Loads a PEM-encoded private key file into a SSLPrivateKey object. 3132 // Loads a PEM-encoded private key file into a SSLPrivateKey object.
3134 // |filepath| is the private key file path. 3133 // |filepath| is the private key file path.
3135 // Returns the new SSLPrivateKey. 3134 // Returns the new SSLPrivateKey.
3136 scoped_refptr<SSLPrivateKey> LoadPrivateKeyOpenSSL( 3135 scoped_refptr<SSLPrivateKey> LoadPrivateKeyOpenSSL(
3137 const base::FilePath& filepath) { 3136 const base::FilePath& filepath) {
3138 std::string data; 3137 std::string data;
3139 if (!base::ReadFileToString(filepath, &data)) { 3138 if (!base::ReadFileToString(filepath, &data)) {
3140 LOG(ERROR) << "Could not read private key file: " << filepath.value(); 3139 LOG(ERROR) << "Could not read private key file: " << filepath.value();
3141 return nullptr; 3140 return nullptr;
3142 } 3141 }
3143 crypto::ScopedBIO bio(BIO_new_mem_buf(const_cast<char*>(data.data()), 3142 bssl::UniquePtr<BIO> bio(BIO_new_mem_buf(const_cast<char*>(data.data()),
3144 static_cast<int>(data.size()))); 3143 static_cast<int>(data.size())));
3145 if (!bio) { 3144 if (!bio) {
3146 LOG(ERROR) << "Could not allocate BIO for buffer?"; 3145 LOG(ERROR) << "Could not allocate BIO for buffer?";
3147 return nullptr; 3146 return nullptr;
3148 } 3147 }
3149 crypto::ScopedEVP_PKEY result( 3148 bssl::UniquePtr<EVP_PKEY> result(
3150 PEM_read_bio_PrivateKey(bio.get(), nullptr, nullptr, nullptr)); 3149 PEM_read_bio_PrivateKey(bio.get(), nullptr, nullptr, nullptr));
3151 if (!result) { 3150 if (!result) {
3152 LOG(ERROR) << "Could not decode private key file: " << filepath.value(); 3151 LOG(ERROR) << "Could not decode private key file: " << filepath.value();
3153 return nullptr; 3152 return nullptr;
3154 } 3153 }
3155 return WrapOpenSSLPrivateKey(std::move(result)); 3154 return WrapOpenSSLPrivateKey(std::move(result));
3156 } 3155 }
3157 3156
3158 } // namespace 3157 } // namespace
3159 3158
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
3670 // Replace it with an alert. 3669 // Replace it with an alert.
3671 raw_transport->ReplaceReadResult( 3670 raw_transport->ReplaceReadResult(
3672 FormatTLS12Alert(49 /* AlertDescription.access_denied */)); 3671 FormatTLS12Alert(49 /* AlertDescription.access_denied */));
3673 raw_transport->UnblockReadResult(); 3672 raw_transport->UnblockReadResult();
3674 3673
3675 rv = callback.GetResult(rv); 3674 rv = callback.GetResult(rv);
3676 EXPECT_THAT(rv, IsError(ERR_BAD_SSL_CLIENT_AUTH_CERT)); 3675 EXPECT_THAT(rv, IsError(ERR_BAD_SSL_CLIENT_AUTH_CERT));
3677 } 3676 }
3678 3677
3679 } // namespace net 3678 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/ssl_client_socket_impl.cc ('k') | net/socket/ssl_server_socket_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698