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

Side by Side Diff: net/ssl/openssl_client_key_store.cc

Issue 2786173003: Convert android to use X509CertificateBytes instead of X509CertificateOpenSSL. (Closed)
Patch Set: ssl_server_socket_impl.cc simplifications Created 3 years, 8 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_server_socket_impl.cc ('k') | net/ssl/openssl_ssl_util.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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "net/ssl/openssl_client_key_store.h" 5 #include "net/ssl/openssl_client_key_store.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/singleton.h" 9 #include "base/memory/singleton.h"
10 #include "net/cert/asn1_util.h"
10 #include "net/cert/x509_certificate.h" 11 #include "net/cert/x509_certificate.h"
11 #include "net/ssl/ssl_private_key.h" 12 #include "net/ssl/ssl_private_key.h"
12 #include "third_party/boringssl/src/include/openssl/evp.h" 13 #include "third_party/boringssl/src/include/openssl/evp.h"
13 #include "third_party/boringssl/src/include/openssl/mem.h" 14 #include "third_party/boringssl/src/include/openssl/mem.h"
14 #include "third_party/boringssl/src/include/openssl/x509.h" 15 #include "third_party/boringssl/src/include/openssl/x509.h"
15 16
16 namespace net { 17 namespace net {
17 18
18 namespace { 19 namespace {
19 20
20 // Serializes the SubjectPublicKeyInfo for |cert|. 21 // Serializes the SubjectPublicKeyInfo for |cert|.
21 bool GetCertificateSPKI(const X509Certificate* cert, std::string* spki) { 22 bool GetCertificateSPKI(const X509Certificate* cert, std::string* spki) {
23 #if BUILDFLAG(USE_BYTE_CERTS)
24 base::StringPiece cert_der(
25 reinterpret_cast<const char*>(CRYPTO_BUFFER_data(cert->os_cert_handle())),
26 CRYPTO_BUFFER_len(cert->os_cert_handle()));
27 base::StringPiece spki_tmp;
28 if (!asn1::ExtractSPKIFromDERCert(cert_der, &spki_tmp))
29 return false;
30 spki_tmp.CopyToString(spki);
31 return true;
32 #else
22 bssl::UniquePtr<EVP_PKEY> pkey(X509_get_pubkey(cert->os_cert_handle())); 33 bssl::UniquePtr<EVP_PKEY> pkey(X509_get_pubkey(cert->os_cert_handle()));
23 if (!pkey) { 34 if (!pkey) {
24 LOG(ERROR) << "Can't extract private key from certificate!"; 35 LOG(ERROR) << "Can't extract private key from certificate!";
25 return false; 36 return false;
26 } 37 }
27 38
28 bssl::ScopedCBB cbb; 39 bssl::ScopedCBB cbb;
29 uint8_t* der; 40 uint8_t* der;
30 size_t der_len; 41 size_t der_len;
31 if (!CBB_init(cbb.get(), 0) || 42 if (!CBB_init(cbb.get(), 0) ||
32 !EVP_marshal_public_key(cbb.get(), pkey.get()) || 43 !EVP_marshal_public_key(cbb.get(), pkey.get()) ||
33 !CBB_finish(cbb.get(), &der, &der_len)) { 44 !CBB_finish(cbb.get(), &der, &der_len)) {
34 return false; 45 return false;
35 } 46 }
36 47
37 spki->assign(reinterpret_cast<char*>(der), 48 spki->assign(reinterpret_cast<char*>(der),
38 reinterpret_cast<char*>(der) + der_len); 49 reinterpret_cast<char*>(der) + der_len);
39 OPENSSL_free(der); 50 OPENSSL_free(der);
40 return true; 51 return true;
52 #endif
41 } 53 }
42 54
43 } // namespace 55 } // namespace
44 56
45 OpenSSLClientKeyStore* OpenSSLClientKeyStore::GetInstance() { 57 OpenSSLClientKeyStore* OpenSSLClientKeyStore::GetInstance() {
46 return base::Singleton<OpenSSLClientKeyStore>::get(); 58 return base::Singleton<OpenSSLClientKeyStore>::get();
47 } 59 }
48 60
49 bool OpenSSLClientKeyStore::RecordClientCertPrivateKey( 61 bool OpenSSLClientKeyStore::RecordClientCertPrivateKey(
50 const X509Certificate* client_cert, 62 const X509Certificate* client_cert,
(...skipping 26 matching lines...) Expand all
77 89
78 void OpenSSLClientKeyStore::Flush() { 90 void OpenSSLClientKeyStore::Flush() {
79 key_map_.clear(); 91 key_map_.clear();
80 } 92 }
81 93
82 OpenSSLClientKeyStore::OpenSSLClientKeyStore() {} 94 OpenSSLClientKeyStore::OpenSSLClientKeyStore() {}
83 95
84 OpenSSLClientKeyStore::~OpenSSLClientKeyStore() {} 96 OpenSSLClientKeyStore::~OpenSSLClientKeyStore() {}
85 97
86 } // namespace net 98 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/ssl_server_socket_impl.cc ('k') | net/ssl/openssl_ssl_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698