| OLD | NEW |
| 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 <openssl/evp.h> | 7 #include <openssl/evp.h> |
| 8 #include <openssl/mem.h> | 8 #include <openssl/mem.h> |
| 9 #include <openssl/x509.h> | 9 #include <openssl/x509.h> |
| 10 | 10 |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
| 14 #include "crypto/auto_cbb.h" | |
| 15 #include "crypto/scoped_openssl_types.h" | |
| 16 #include "net/cert/x509_certificate.h" | 14 #include "net/cert/x509_certificate.h" |
| 17 #include "net/ssl/ssl_private_key.h" | 15 #include "net/ssl/ssl_private_key.h" |
| 18 | 16 |
| 19 namespace net { | 17 namespace net { |
| 20 | 18 |
| 21 namespace { | 19 namespace { |
| 22 | 20 |
| 23 // Serializes the SubjectPublicKeyInfo for |cert|. | 21 // Serializes the SubjectPublicKeyInfo for |cert|. |
| 24 bool GetCertificateSPKI(const X509Certificate* cert, std::string* spki) { | 22 bool GetCertificateSPKI(const X509Certificate* cert, std::string* spki) { |
| 25 crypto::ScopedEVP_PKEY pkey(X509_get_pubkey(cert->os_cert_handle())); | 23 bssl::UniquePtr<EVP_PKEY> pkey(X509_get_pubkey(cert->os_cert_handle())); |
| 26 if (!pkey) { | 24 if (!pkey) { |
| 27 LOG(ERROR) << "Can't extract private key from certificate!"; | 25 LOG(ERROR) << "Can't extract private key from certificate!"; |
| 28 return false; | 26 return false; |
| 29 } | 27 } |
| 30 | 28 |
| 31 crypto::AutoCBB cbb; | 29 bssl::ScopedCBB cbb; |
| 32 uint8_t* der; | 30 uint8_t* der; |
| 33 size_t der_len; | 31 size_t der_len; |
| 34 if (!CBB_init(cbb.get(), 0) || | 32 if (!CBB_init(cbb.get(), 0) || |
| 35 !EVP_marshal_public_key(cbb.get(), pkey.get()) || | 33 !EVP_marshal_public_key(cbb.get(), pkey.get()) || |
| 36 !CBB_finish(cbb.get(), &der, &der_len)) { | 34 !CBB_finish(cbb.get(), &der, &der_len)) { |
| 37 return false; | 35 return false; |
| 38 } | 36 } |
| 39 | 37 |
| 40 spki->assign(reinterpret_cast<char*>(der), | 38 spki->assign(reinterpret_cast<char*>(der), |
| 41 reinterpret_cast<char*>(der) + der_len); | 39 reinterpret_cast<char*>(der) + der_len); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 78 |
| 81 void OpenSSLClientKeyStore::Flush() { | 79 void OpenSSLClientKeyStore::Flush() { |
| 82 key_map_.clear(); | 80 key_map_.clear(); |
| 83 } | 81 } |
| 84 | 82 |
| 85 OpenSSLClientKeyStore::OpenSSLClientKeyStore() {} | 83 OpenSSLClientKeyStore::OpenSSLClientKeyStore() {} |
| 86 | 84 |
| 87 OpenSSLClientKeyStore::~OpenSSLClientKeyStore() {} | 85 OpenSSLClientKeyStore::~OpenSSLClientKeyStore() {} |
| 88 | 86 |
| 89 } // namespace net | 87 } // namespace net |
| OLD | NEW |