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

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

Issue 1422573008: Plumbing SSLPrivateKey (//net) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removing un-needed forward decl. Created 5 years, 1 month 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/ssl/ssl_platform_key.h ('k') | net/ssl/ssl_platform_key_mac.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/ssl_platform_key.h" 5 #include "net/ssl/ssl_platform_key.h"
6 6
7 #include <openssl/digest.h> 7 #include <openssl/digest.h>
8 #include <openssl/evp.h> 8 #include <openssl/evp.h>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "crypto/scoped_openssl_types.h" 13 #include "crypto/scoped_openssl_types.h"
14 #include "net/base/net_errors.h" 14 #include "net/base/net_errors.h"
15 #include "net/ssl/openssl_client_key_store.h" 15 #include "net/ssl/openssl_client_key_store.h"
16 #include "net/ssl/ssl_platform_key_task_runner.h"
16 #include "net/ssl/ssl_private_key.h" 17 #include "net/ssl/ssl_private_key.h"
17 #include "net/ssl/threaded_ssl_private_key.h" 18 #include "net/ssl/threaded_ssl_private_key.h"
18 19
19 namespace net { 20 namespace net {
20 21
21 namespace { 22 namespace {
22 23
23 class SSLPlatformKeyAndroid : public ThreadedSSLPrivateKey::Delegate { 24 class SSLPlatformKeyAndroid : public ThreadedSSLPrivateKey::Delegate {
24 public: 25 public:
25 SSLPlatformKeyAndroid(crypto::ScopedEVP_PKEY key, SSLPrivateKey::Type type) 26 SSLPlatformKeyAndroid(crypto::ScopedEVP_PKEY key, SSLPrivateKey::Type type)
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 return OK; 99 return OK;
99 } 100 }
100 101
101 private: 102 private:
102 crypto::ScopedEVP_PKEY key_; 103 crypto::ScopedEVP_PKEY key_;
103 SSLPrivateKey::Type type_; 104 SSLPrivateKey::Type type_;
104 105
105 DISALLOW_COPY_AND_ASSIGN(SSLPlatformKeyAndroid); 106 DISALLOW_COPY_AND_ASSIGN(SSLPlatformKeyAndroid);
106 }; 107 };
107 108
108 } // namespace 109 scoped_refptr<SSLPrivateKey> WrapOpenSSLPrivateKey(crypto::ScopedEVP_PKEY key) {
109
110 scoped_ptr<SSLPrivateKey> FetchClientCertPrivateKey(
111 X509Certificate* certificate,
112 scoped_refptr<base::SequencedTaskRunner> task_runner) {
113 crypto::ScopedEVP_PKEY key =
114 OpenSSLClientKeyStore::GetInstance()->FetchClientCertPrivateKey(
115 certificate);
116 if (!key) 110 if (!key)
117 return nullptr; 111 return nullptr;
118 112
119 SSLPrivateKey::Type type; 113 SSLPrivateKey::Type type;
120 switch (EVP_PKEY_id(key.get())) { 114 switch (EVP_PKEY_id(key.get())) {
121 case EVP_PKEY_RSA: 115 case EVP_PKEY_RSA:
122 type = SSLPrivateKey::Type::RSA; 116 type = SSLPrivateKey::Type::RSA;
123 break; 117 break;
124 case EVP_PKEY_EC: 118 case EVP_PKEY_EC:
125 type = SSLPrivateKey::Type::ECDSA; 119 type = SSLPrivateKey::Type::ECDSA;
126 break; 120 break;
127 default: 121 default:
128 LOG(ERROR) << "Unknown key type: " << EVP_PKEY_id(key.get()); 122 LOG(ERROR) << "Unknown key type: " << EVP_PKEY_id(key.get());
129 return nullptr; 123 return nullptr;
130 } 124 }
131 return make_scoped_ptr(new ThreadedSSLPrivateKey( 125 return make_scoped_refptr(new ThreadedSSLPrivateKey(
132 make_scoped_ptr(new SSLPlatformKeyAndroid(key.Pass(), type)), 126 make_scoped_ptr(new SSLPlatformKeyAndroid(key.Pass(), type)),
133 task_runner.Pass())); 127 GetSSLPlatformKeyTaskRunner()));
128 }
129
130 } // namespace
131
132 scoped_refptr<SSLPrivateKey> FetchClientCertPrivateKey(
133 X509Certificate* certificate) {
134 crypto::ScopedEVP_PKEY key =
135 OpenSSLClientKeyStore::GetInstance()->FetchClientCertPrivateKey(
136 certificate);
137 return WrapOpenSSLPrivateKey(key.Pass());
134 } 138 }
135 139
136 } // namespace net 140 } // namespace net
OLDNEW
« no previous file with comments | « net/ssl/ssl_platform_key.h ('k') | net/ssl/ssl_platform_key_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698