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

Side by Side Diff: net/ssl/ssl_platform_key_nss.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 <keyhi.h> 7 #include <keyhi.h>
8 #include <pk11pub.h> 8 #include <pk11pub.h>
9 #include <prerror.h> 9 #include <prerror.h>
10 10
11 #include <openssl/bn.h> 11 #include <openssl/bn.h>
12 #include <openssl/ecdsa.h> 12 #include <openssl/ecdsa.h>
13 #include <openssl/rsa.h> 13 #include <openssl/rsa.h>
14 14
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/sequenced_task_runner.h" 17 #include "base/sequenced_task_runner.h"
18 #include "base/stl_util.h" 18 #include "base/stl_util.h"
19 #include "crypto/scoped_nss_types.h" 19 #include "crypto/scoped_nss_types.h"
20 #include "crypto/scoped_openssl_types.h" 20 #include "crypto/scoped_openssl_types.h"
21 #include "net/cert/x509_certificate.h" 21 #include "net/cert/x509_certificate.h"
22 #include "net/ssl/client_key_store.h" 22 #include "net/ssl/client_key_store.h"
23 #include "net/ssl/ssl_platform_key_task_runner.h"
23 #include "net/ssl/ssl_private_key.h" 24 #include "net/ssl/ssl_private_key.h"
24 #include "net/ssl/threaded_ssl_private_key.h" 25 #include "net/ssl/threaded_ssl_private_key.h"
25 26
26 namespace net { 27 namespace net {
27 28
28 namespace { 29 namespace {
29 30
30 void LogPRError() { 31 void LogPRError() {
31 PRErrorCode err = PR_GetError(); 32 PRErrorCode err = PR_GetError();
32 const char* err_name = PR_ErrorToName(err); 33 const char* err_name = PR_ErrorToName(err);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 154
154 private: 155 private:
155 SSLPrivateKey::Type type_; 156 SSLPrivateKey::Type type_;
156 crypto::ScopedSECKEYPrivateKey key_; 157 crypto::ScopedSECKEYPrivateKey key_;
157 158
158 DISALLOW_COPY_AND_ASSIGN(SSLPlatformKeyNSS); 159 DISALLOW_COPY_AND_ASSIGN(SSLPlatformKeyNSS);
159 }; 160 };
160 161
161 } // namespace 162 } // namespace
162 163
163 scoped_ptr<SSLPrivateKey> FetchClientCertPrivateKey( 164 scoped_refptr<SSLPrivateKey> FetchClientCertPrivateKey(
164 X509Certificate* certificate, 165 X509Certificate* certificate) {
165 scoped_refptr<base::SequencedTaskRunner> task_runner) { 166 if (!certificate->os_cert_handle())
167 return nullptr;
davidben 2015/11/04 00:17:38 See resource_loader_unittest.cc comment.
svaldez 2015/11/04 16:55:52 Done.
166 crypto::ScopedSECKEYPrivateKey key( 168 crypto::ScopedSECKEYPrivateKey key(
167 PK11_FindKeyByAnyCert(certificate->os_cert_handle(), nullptr)); 169 PK11_FindKeyByAnyCert(certificate->os_cert_handle(), nullptr));
168 if (!key) { 170 if (!key) {
169 return ClientKeyStore::GetInstance()->FetchClientCertPrivateKey( 171 return ClientKeyStore::GetInstance()->FetchClientCertPrivateKey(
170 *certificate); 172 *certificate);
171 } 173 }
172 174
173 KeyType nss_type = SECKEY_GetPrivateKeyType(key.get()); 175 KeyType nss_type = SECKEY_GetPrivateKeyType(key.get());
174 SSLPrivateKey::Type type; 176 SSLPrivateKey::Type type;
175 switch (nss_type) { 177 switch (nss_type) {
176 case rsaKey: 178 case rsaKey:
177 type = SSLPrivateKey::Type::RSA; 179 type = SSLPrivateKey::Type::RSA;
178 break; 180 break;
179 case ecKey: 181 case ecKey:
180 type = SSLPrivateKey::Type::ECDSA; 182 type = SSLPrivateKey::Type::ECDSA;
181 break; 183 break;
182 default: 184 default:
183 LOG(ERROR) << "Unknown key type: " << nss_type; 185 LOG(ERROR) << "Unknown key type: " << nss_type;
184 return nullptr; 186 return nullptr;
185 } 187 }
186 return make_scoped_ptr(new ThreadedSSLPrivateKey( 188 return make_scoped_refptr(new ThreadedSSLPrivateKey(
187 make_scoped_ptr(new SSLPlatformKeyNSS(type, key.Pass())), 189 make_scoped_ptr(new SSLPlatformKeyNSS(type, key.Pass())),
188 task_runner.Pass())); 190 GetSSLPlatformKeyTaskRunner()));
189 } 191 }
190 192
191 } // namespace net 193 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698