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

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: Fixing extra tab. 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
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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 } // namespace
109 110
110 scoped_ptr<SSLPrivateKey> FetchClientCertPrivateKey( 111 scoped_refptr<SSLPrivateKey> WrapOpenSSLPrivateKey(crypto::ScopedEVP_PKEY key) {
111 X509Certificate* certificate,
112 scoped_refptr<base::SequencedTaskRunner> task_runner) {
113 crypto::ScopedEVP_PKEY key =
114 OpenSSLClientKeyStore::GetInstance()->FetchClientCertPrivateKey(
115 certificate);
116 if (!key) 112 if (!key)
117 return nullptr; 113 return nullptr;
118 114
119 SSLPrivateKey::Type type; 115 SSLPrivateKey::Type type;
120 switch (EVP_PKEY_id(key.get())) { 116 switch (EVP_PKEY_id(key.get())) {
121 case EVP_PKEY_RSA: 117 case EVP_PKEY_RSA:
122 type = SSLPrivateKey::Type::RSA; 118 type = SSLPrivateKey::Type::RSA;
123 break; 119 break;
124 case EVP_PKEY_EC: 120 case EVP_PKEY_EC:
125 type = SSLPrivateKey::Type::ECDSA; 121 type = SSLPrivateKey::Type::ECDSA;
126 break; 122 break;
127 default: 123 default:
128 LOG(ERROR) << "Unknown key type: " << EVP_PKEY_id(key.get()); 124 LOG(ERROR) << "Unknown key type: " << EVP_PKEY_id(key.get());
129 return nullptr; 125 return nullptr;
130 } 126 }
131 return make_scoped_ptr(new ThreadedSSLPrivateKey( 127 return make_scoped_refptr(new ThreadedSSLPrivateKey(
132 make_scoped_ptr(new SSLPlatformKeyAndroid(key.Pass(), type)), 128 make_scoped_ptr(new SSLPlatformKeyAndroid(key.Pass(), type)),
133 task_runner.Pass())); 129 GetSSLPlatformKeyTaskRunner()));
130 }
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

Powered by Google App Engine
This is Rietveld 408576698