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

Side by Side Diff: net/ssl/ssl_platform_key_mac.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/ecdsa.h> 7 #include <openssl/ecdsa.h>
8 #include <openssl/obj.h> 8 #include <openssl/obj.h>
9 #include <openssl/rsa.h> 9 #include <openssl/rsa.h>
10 10
(...skipping 18 matching lines...) Expand all
29 #include "crypto/scoped_openssl_types.h" 29 #include "crypto/scoped_openssl_types.h"
30 #include "net/base/net_errors.h" 30 #include "net/base/net_errors.h"
31 #include "net/cert/x509_certificate.h" 31 #include "net/cert/x509_certificate.h"
32 #include "net/ssl/ssl_private_key.h" 32 #include "net/ssl/ssl_private_key.h"
33 #include "net/ssl/threaded_ssl_private_key.h" 33 #include "net/ssl/threaded_ssl_private_key.h"
34 34
35 namespace net { 35 namespace net {
36 36
37 namespace { 37 namespace {
38 38
39 base::LazyInstance<SSLPlatformKeyTaskRunner>::Leaky g_platform_key_task_runner =
40 LAZY_INSTANCE_INITIALIZER;
41
39 class ScopedCSSM_CC_HANDLE { 42 class ScopedCSSM_CC_HANDLE {
40 public: 43 public:
41 ScopedCSSM_CC_HANDLE() : handle_(0) {} 44 ScopedCSSM_CC_HANDLE() : handle_(0) {}
42 explicit ScopedCSSM_CC_HANDLE(CSSM_CC_HANDLE handle) : handle_(handle) {} 45 explicit ScopedCSSM_CC_HANDLE(CSSM_CC_HANDLE handle) : handle_(handle) {}
43 46
44 ~ScopedCSSM_CC_HANDLE() { reset(); } 47 ~ScopedCSSM_CC_HANDLE() { reset(); }
45 48
46 CSSM_CC_HANDLE get() const { return handle_; } 49 CSSM_CC_HANDLE get() const { return handle_; }
47 50
48 void reset() { 51 void reset() {
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 208
206 private: 209 private:
207 base::ScopedCFTypeRef<SecKeyRef> key_; 210 base::ScopedCFTypeRef<SecKeyRef> key_;
208 const CSSM_KEY* cssm_key_; 211 const CSSM_KEY* cssm_key_;
209 212
210 DISALLOW_COPY_AND_ASSIGN(SSLPlatformKeyMac); 213 DISALLOW_COPY_AND_ASSIGN(SSLPlatformKeyMac);
211 }; 214 };
212 215
213 } // namespace 216 } // namespace
214 217
215 scoped_ptr<SSLPrivateKey> FetchClientCertPrivateKey( 218 scoped_refptr<SSLPrivateKey> FetchClientCertPrivateKey(
216 X509Certificate* certificate, 219 X509Certificate* certificate) {
217 scoped_refptr<base::SequencedTaskRunner> task_runner) { 220 if (!certificate) {
davidben 2015/09/25 20:10:12 Any reason not to have the caller handle null? Thi
svaldez 2015/09/28 16:54:53 Then we'd have to check both at the caller that th
davidben 2015/10/13 20:32:15 In general, APIs shouldn't silently try to handle
svaldez 2015/10/14 15:06:18 Done.
221 return nullptr;
222 }
223
218 // Look up the private key. 224 // Look up the private key.
219 base::ScopedCFTypeRef<SecKeyRef> private_key( 225 base::ScopedCFTypeRef<SecKeyRef> private_key(
220 FetchSecKeyRefForCertificate(certificate)); 226 FetchSecKeyRefForCertificate(certificate));
221 if (!private_key) 227 if (!private_key)
222 return nullptr; 228 return nullptr;
223 229
224 const CSSM_KEY* cssm_key; 230 const CSSM_KEY* cssm_key;
225 OSStatus status = SecKeyGetCSSMKey(private_key.get(), &cssm_key); 231 OSStatus status = SecKeyGetCSSMKey(private_key.get(), &cssm_key);
226 if (status != noErr) 232 if (status != noErr)
227 return nullptr; 233 return nullptr;
228 234
229 if (cssm_key->KeyHeader.AlgorithmId != CSSM_ALGID_RSA && 235 if (cssm_key->KeyHeader.AlgorithmId != CSSM_ALGID_RSA &&
230 cssm_key->KeyHeader.AlgorithmId != CSSM_ALGID_ECDSA) { 236 cssm_key->KeyHeader.AlgorithmId != CSSM_ALGID_ECDSA) {
231 LOG(ERROR) << "Unknown key type: " << cssm_key->KeyHeader.AlgorithmId; 237 LOG(ERROR) << "Unknown key type: " << cssm_key->KeyHeader.AlgorithmId;
232 return nullptr; 238 return nullptr;
233 } 239 }
234 return make_scoped_ptr(new ThreadedSSLPrivateKey( 240 return make_scoped_refptr(new ThreadedSSLPrivateKey(
235 make_scoped_ptr(new SSLPlatformKeyMac(private_key.get(), cssm_key)), 241 make_scoped_ptr(new SSLPlatformKeyMac(private_key.get(), cssm_key)),
236 task_runner.Pass())); 242 g_platform_key_task_runner.Get().task_runner().Pass()));
237 } 243 }
238 244
239 } // namespace net 245 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698