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

Side by Side Diff: net/cert/x509_util_openssl.cc

Issue 2682413003: Add a CRYPTO_BUFFER_POOL to SSLClientSocketImpl. (Closed)
Patch Set: Created 3 years, 10 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/cert/x509_util_openssl.h ('k') | net/socket/ssl_client_socket_impl.cc » ('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/cert/x509_util_openssl.h" 5 #include "net/cert/x509_util_openssl.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
11 11
12 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/strings/string_piece.h" 15 #include "base/strings/string_piece.h"
16 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
17 #include "crypto/ec_private_key.h" 17 #include "crypto/ec_private_key.h"
18 #include "crypto/openssl_util.h" 18 #include "crypto/openssl_util.h"
19 #include "crypto/rsa_private_key.h" 19 #include "crypto/rsa_private_key.h"
20 #include "net/cert/internal/parse_certificate.h" 20 #include "net/cert/internal/parse_certificate.h"
21 #include "net/cert/internal/signature_algorithm.h" 21 #include "net/cert/internal/signature_algorithm.h"
22 #include "net/cert/x509_cert_types.h" 22 #include "net/cert/x509_cert_types.h"
23 #include "net/cert/x509_certificate.h" 23 #include "net/cert/x509_certificate.h"
24 #include "net/cert/x509_util.h" 24 #include "net/cert/x509_util.h"
25 #include "third_party/boringssl/src/include/openssl/asn1.h" 25 #include "third_party/boringssl/src/include/openssl/asn1.h"
26 #include "third_party/boringssl/src/include/openssl/digest.h" 26 #include "third_party/boringssl/src/include/openssl/digest.h"
27 #include "third_party/boringssl/src/include/openssl/mem.h" 27 #include "third_party/boringssl/src/include/openssl/mem.h"
28 #include "third_party/boringssl/src/include/openssl/pool.h"
28 29
29 namespace net { 30 namespace net {
30 31
31 namespace { 32 namespace {
32 33
33 const EVP_MD* ToEVP(x509_util::DigestAlgorithm alg) { 34 const EVP_MD* ToEVP(x509_util::DigestAlgorithm alg) {
34 switch (alg) { 35 switch (alg) {
35 case x509_util::DIGEST_SHA1: 36 case x509_util::DIGEST_SHA1:
36 return EVP_sha1(); 37 return EVP_sha1();
37 case x509_util::DIGEST_SHA256: 38 case x509_util::DIGEST_SHA256:
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 184
184 private: 185 private:
185 int der_cache_ex_index_; 186 int der_cache_ex_index_;
186 187
187 DISALLOW_COPY_AND_ASSIGN(DERCacheInitSingleton); 188 DISALLOW_COPY_AND_ASSIGN(DERCacheInitSingleton);
188 }; 189 };
189 190
190 base::LazyInstance<DERCacheInitSingleton>::Leaky g_der_cache_singleton = 191 base::LazyInstance<DERCacheInitSingleton>::Leaky g_der_cache_singleton =
191 LAZY_INSTANCE_INITIALIZER; 192 LAZY_INSTANCE_INITIALIZER;
192 193
194 class BufferPoolSingleton {
195 public:
196 BufferPoolSingleton() : pool_(CRYPTO_BUFFER_POOL_new()) {}
197 CRYPTO_BUFFER_POOL* pool() { return pool_; }
198
199 private:
200 // The singleton is leaky, so there is no need to use a smart pointer.
201 CRYPTO_BUFFER_POOL* pool_;
202 };
203
204 base::LazyInstance<BufferPoolSingleton>::Leaky g_buffer_pool_singleton =
205 LAZY_INSTANCE_INITIALIZER;
206
193 } // namespace 207 } // namespace
194 208
195 bool CreateSelfSignedCert(crypto::RSAPrivateKey* key, 209 bool CreateSelfSignedCert(crypto::RSAPrivateKey* key,
196 DigestAlgorithm alg, 210 DigestAlgorithm alg,
197 const std::string& common_name, 211 const std::string& common_name,
198 uint32_t serial_number, 212 uint32_t serial_number,
199 base::Time not_valid_before, 213 base::Time not_valid_before,
200 base::Time not_valid_after, 214 base::Time not_valid_after,
201 std::string* der_encoded) { 215 std::string* der_encoded) {
202 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); 216 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE);
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 der_encoded_certificate.size(), digest.data(), &out_size, 354 der_encoded_certificate.size(), digest.data(), &out_size,
341 digest_evp_md, nullptr)) 355 digest_evp_md, nullptr))
342 return false; 356 return false;
343 357
344 digest.resize(out_size); 358 digest.resize(out_size);
345 token->assign(kChannelBindingPrefix); 359 token->assign(kChannelBindingPrefix);
346 token->append(digest.begin(), digest.end()); 360 token->append(digest.begin(), digest.end());
347 return true; 361 return true;
348 } 362 }
349 363
364 CRYPTO_BUFFER_POOL* GetBufferPool() {
365 return g_buffer_pool_singleton.Get().pool();
366 }
367
350 } // namespace x509_util 368 } // namespace x509_util
351 369
352 } // namespace net 370 } // namespace net
OLDNEW
« no previous file with comments | « net/cert/x509_util_openssl.h ('k') | net/socket/ssl_client_socket_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698