1 // Copyright 2017 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "net/ssl/client_cert_identity_mac.h" 6 7 #include <Security/SecIdentity.h> 8 9 #include "base/apple/osstatus_logging.h" 10 #include "net/ssl/ssl_platform_key_mac.h" 11 #include "net/ssl/ssl_private_key.h" 12 13 namespace net { 14 ClientCertIdentityMac(scoped_refptr<net::X509Certificate> cert,base::apple::ScopedCFTypeRef<SecIdentityRef> sec_identity)15ClientCertIdentityMac::ClientCertIdentityMac( 16 scoped_refptr<net::X509Certificate> cert, 17 base::apple::ScopedCFTypeRef<SecIdentityRef> sec_identity) 18 : ClientCertIdentity(std::move(cert)), identity_(std::move(sec_identity)) {} 19 20 ClientCertIdentityMac::~ClientCertIdentityMac() = default; 21 AcquirePrivateKey(base::OnceCallback<void (scoped_refptr<SSLPrivateKey>)> private_key_callback)22void ClientCertIdentityMac::AcquirePrivateKey( 23 base::OnceCallback<void(scoped_refptr<SSLPrivateKey>)> 24 private_key_callback) { 25 // This only adds a ref to and returns the private key from `identity_`, so it 26 // doesn't need to run on a worker thread. 27 base::apple::ScopedCFTypeRef<SecKeyRef> key; 28 OSStatus status = 29 SecIdentityCopyPrivateKey(identity_.get(), key.InitializeInto()); 30 if (status != noErr) { 31 OSSTATUS_LOG(WARNING, status); 32 std::move(private_key_callback).Run(nullptr); 33 return; 34 } 35 36 std::move(private_key_callback) 37 .Run(CreateSSLPrivateKeyForSecKey(certificate(), key.get())); 38 } 39 40 } // namespace net 41