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

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

Issue 1304143010: Plumbing SSLPrivateKey Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years, 2 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
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"
16 #include "net/ssl/ssl_private_key.h" 15 #include "net/ssl/ssl_private_key.h"
17 #include "net/ssl/threaded_ssl_private_key.h" 16 #include "net/ssl/threaded_ssl_private_key.h"
18 17
19 namespace net { 18 namespace net {
20 19
21 namespace { 20 namespace {
22 21
22 base::LazyInstance<SSLPlatformKeyTaskRunner>::Leaky g_platform_key_task_runner =
23 LAZY_INSTANCE_INITIALIZER;
24
23 class SSLPlatformKeyAndroid : public ThreadedSSLPrivateKey::Delegate { 25 class SSLPlatformKeyAndroid : public ThreadedSSLPrivateKey::Delegate {
24 public: 26 public:
25 SSLPlatformKeyAndroid(crypto::ScopedEVP_PKEY key, SSLPrivateKey::Type type) 27 SSLPlatformKeyAndroid(crypto::ScopedEVP_PKEY key, SSLPrivateKey::Type type)
26 : key_(key.Pass()), type_(type) {} 28 : key_(key.Pass()), type_(type) {}
27 29
28 ~SSLPlatformKeyAndroid() override {} 30 ~SSLPlatformKeyAndroid() override {}
29 31
30 SSLPrivateKey::Type GetType() override { return type_; } 32 SSLPrivateKey::Type GetType() override { return type_; }
31 33
32 bool SupportsHash(SSLPrivateKey::Hash hash) override { return true; } 34 bool SupportsHash(SSLPrivateKey::Hash hash) override { return true; }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 96
95 private: 97 private:
96 crypto::ScopedEVP_PKEY key_; 98 crypto::ScopedEVP_PKEY key_;
97 SSLPrivateKey::Type type_; 99 SSLPrivateKey::Type type_;
98 100
99 DISALLOW_COPY_AND_ASSIGN(SSLPlatformKeyAndroid); 101 DISALLOW_COPY_AND_ASSIGN(SSLPlatformKeyAndroid);
100 }; 102 };
101 103
102 } // namespace 104 } // namespace
103 105
104 scoped_ptr<SSLPrivateKey> FetchClientCertPrivateKey( 106 scoped_refptr<SSLPrivateKey> WrapPrivateKey(crypto::ScopedEVP_PKEY key) {
105 X509Certificate* certificate,
106 scoped_refptr<base::SequencedTaskRunner> task_runner) {
107 crypto::ScopedEVP_PKEY key =
108 OpenSSLClientKeyStore::GetInstance()->FetchClientCertPrivateKey(
109 certificate);
110 if (!key) 107 if (!key)
111 return nullptr; 108 return nullptr;
112 109
113 SSLPrivateKey::Type type; 110 SSLPrivateKey::Type type;
114 switch (EVP_PKEY_id(key.get())) { 111 switch (EVP_PKEY_id(key.get())) {
115 case EVP_PKEY_RSA: 112 case EVP_PKEY_RSA:
116 type = SSLPrivateKey::Type::RSA; 113 type = SSLPrivateKey::Type::RSA;
117 break; 114 break;
118 case EVP_PKEY_EC: 115 case EVP_PKEY_EC:
119 type = SSLPrivateKey::Type::ECDSA; 116 type = SSLPrivateKey::Type::ECDSA;
120 break; 117 break;
121 default: 118 default:
122 LOG(ERROR) << "Unknown key type: " << EVP_PKEY_id(key.get()); 119 LOG(ERROR) << "Unknown key type: " << EVP_PKEY_id(key.get());
123 return nullptr; 120 return nullptr;
124 } 121 }
125 return make_scoped_ptr(new ThreadedSSLPrivateKey( 122 return make_scoped_refptr(new ThreadedSSLPrivateKey(
126 make_scoped_ptr(new SSLPlatformKeyAndroid(key.Pass(), type)), 123 make_scoped_ptr(new SSLPlatformKeyAndroid(key.Pass(), type)),
127 task_runner.Pass())); 124 g_platform_key_task_runner.Get().task_runner().Pass()));
128 } 125 }
129 126
130 } // namespace net 127 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698