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

Side by Side Diff: net/socket/ssl_client_socket_nss.cc

Issue 994743003: Support for client certs in ssl_server_socket. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // This file includes code SSLClientSocketNSS::DoVerifyCertComplete() derived 5 // This file includes code SSLClientSocketNSS::DoVerifyCertComplete() derived
6 // from AuthCertificateCallback() in 6 // from AuthCertificateCallback() in
7 // mozilla/security/manager/ssl/src/nsNSSCallbacks.cpp. 7 // mozilla/security/manager/ssl/src/nsNSSCallbacks.cpp.
8 8
9 /* ***** BEGIN LICENSE BLOCK ***** 9 /* ***** BEGIN LICENSE BLOCK *****
10 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 10 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 bool WasEverUsed() const; 637 bool WasEverUsed() const;
638 638
639 // Called on the network task runner. 639 // Called on the network task runner.
640 // Causes the associated SSL/TLS session ID to be added to NSS's session 640 // Causes the associated SSL/TLS session ID to be added to NSS's session
641 // cache, but only if the connection has not been False Started. 641 // cache, but only if the connection has not been False Started.
642 // 642 //
643 // This should only be called after the server's certificate has been 643 // This should only be called after the server's certificate has been
644 // verified, and may not be called within an NSS callback. 644 // verified, and may not be called within an NSS callback.
645 void CacheSessionIfNecessary(); 645 void CacheSessionIfNecessary();
646 646
647 // Only for unit testing.
648 // This should only be called before Connect().
649 void ForceClientCertificateAndKeyForTest(
650 scoped_refptr<X509Certificate> client_cert,
651 scoped_ptr<crypto::RSAPrivateKey> client_private_key);
652
647 private: 653 private:
648 friend class base::RefCountedThreadSafe<Core>; 654 friend class base::RefCountedThreadSafe<Core>;
649 ~Core(); 655 ~Core();
650 656
651 enum State { 657 enum State {
652 STATE_NONE, 658 STATE_NONE,
653 STATE_HANDSHAKE, 659 STATE_HANDSHAKE,
654 STATE_GET_DOMAIN_BOUND_CERT_COMPLETE, 660 STATE_GET_DOMAIN_BOUND_CERT_COMPLETE,
655 }; 661 };
656 662
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 // for the network task runner from the NSS task runner. 918 // for the network task runner from the NSS task runner.
913 base::WeakPtr<BoundNetLog> weak_net_log_; 919 base::WeakPtr<BoundNetLog> weak_net_log_;
914 920
915 // Written on the network task runner by the |channel_id_service_|, 921 // Written on the network task runner by the |channel_id_service_|,
916 // prior to invoking OnHandshakeIOComplete. 922 // prior to invoking OnHandshakeIOComplete.
917 // Read on the NSS task runner when once OnHandshakeIOComplete is invoked 923 // Read on the NSS task runner when once OnHandshakeIOComplete is invoked
918 // on the NSS task runner. 924 // on the NSS task runner.
919 std::string domain_bound_private_key_; 925 std::string domain_bound_private_key_;
920 std::string domain_bound_cert_; 926 std::string domain_bound_cert_;
921 927
928 // Used only for unit testing.
929 scoped_ptr<crypto::RSAPrivateKey> client_private_key_;
930
922 DISALLOW_COPY_AND_ASSIGN(Core); 931 DISALLOW_COPY_AND_ASSIGN(Core);
923 }; 932 };
924 933
925 SSLClientSocketNSS::Core::Core( 934 SSLClientSocketNSS::Core::Core(
926 base::SequencedTaskRunner* network_task_runner, 935 base::SequencedTaskRunner* network_task_runner,
927 base::SequencedTaskRunner* nss_task_runner, 936 base::SequencedTaskRunner* nss_task_runner,
928 ClientSocketHandle* transport, 937 ClientSocketHandle* transport,
929 const HostPortPair& host_and_port, 938 const HostPortPair& host_and_port,
930 const SSLConfig& ssl_config, 939 const SSLConfig& ssl_config,
931 BoundNetLog* net_log, 940 BoundNetLog* net_log,
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after
1545 1554
1546 // Regular client certificate requested. 1555 // Regular client certificate requested.
1547 core->client_auth_cert_needed_ = !core->ssl_config_.send_client_cert; 1556 core->client_auth_cert_needed_ = !core->ssl_config_.send_client_cert;
1548 void* wincx = SSL_RevealPinArg(socket); 1557 void* wincx = SSL_RevealPinArg(socket);
1549 1558
1550 if (core->ssl_config_.send_client_cert) { 1559 if (core->ssl_config_.send_client_cert) {
1551 // Second pass: a client certificate should have been selected. 1560 // Second pass: a client certificate should have been selected.
1552 if (core->ssl_config_.client_cert.get()) { 1561 if (core->ssl_config_.client_cert.get()) {
1553 CERTCertificate* cert = 1562 CERTCertificate* cert =
1554 CERT_DupCertificate(core->ssl_config_.client_cert->os_cert_handle()); 1563 CERT_DupCertificate(core->ssl_config_.client_cert->os_cert_handle());
1555 SECKEYPrivateKey* privkey = PK11_FindKeyByAnyCert(cert, wincx); 1564 SECKEYPrivateKey* privkey = NULL;
1565 if (core->client_private_key_.get()) {
1566 privkey = SECKEY_CopyPrivateKey(core->client_private_key_->key());
1567 } else {
1568 privkey = PK11_FindKeyByAnyCert(cert, wincx);
1569 }
1556 if (privkey) { 1570 if (privkey) {
1557 // TODO(jsorianopastor): We should wait for server certificate 1571 // TODO(jsorianopastor): We should wait for server certificate
1558 // verification before sending our credentials. See 1572 // verification before sending our credentials. See
1559 // http://crbug.com/13934. 1573 // http://crbug.com/13934.
1560 *result_certificate = cert; 1574 *result_certificate = cert;
1561 *result_private_key = privkey; 1575 *result_private_key = privkey;
1562 // A cert_count of -1 means the number of certificates is unknown. 1576 // A cert_count of -1 means the number of certificates is unknown.
1563 // NSS will construct the certificate chain. 1577 // NSS will construct the certificate chain.
1564 core->AddCertProvidedEvent(-1); 1578 core->AddCertProvidedEvent(-1);
1565 1579
(...skipping 1253 matching lines...) Expand 10 before | Expand all | Expand 10 after
2819 FROM_HERE, base::Bind(&AddLogEvent, weak_net_log_, 2833 FROM_HERE, base::Bind(&AddLogEvent, weak_net_log_,
2820 NetLog::TYPE_SSL_CHANNEL_ID_PROVIDED)); 2834 NetLog::TYPE_SSL_CHANNEL_ID_PROVIDED));
2821 nss_handshake_state_.channel_id_sent = true; 2835 nss_handshake_state_.channel_id_sent = true;
2822 // Update the network task runner's view of the handshake state now that 2836 // Update the network task runner's view of the handshake state now that
2823 // channel id has been sent. 2837 // channel id has been sent.
2824 PostOrRunCallback( 2838 PostOrRunCallback(
2825 FROM_HERE, base::Bind(&Core::OnHandshakeStateUpdated, this, 2839 FROM_HERE, base::Bind(&Core::OnHandshakeStateUpdated, this,
2826 nss_handshake_state_)); 2840 nss_handshake_state_));
2827 } 2841 }
2828 2842
2843 void SSLClientSocketNSS::Core::ForceClientCertificateAndKeyForTest(
2844 scoped_refptr<X509Certificate> client_cert,
2845 scoped_ptr<crypto::RSAPrivateKey> client_private_key) {
2846 ssl_config_.send_client_cert = true;
2847 ssl_config_.client_cert = client_cert;
2848 client_private_key_ = client_private_key.Pass();
2849 }
2850
2829 SSLClientSocketNSS::SSLClientSocketNSS( 2851 SSLClientSocketNSS::SSLClientSocketNSS(
2830 base::SequencedTaskRunner* nss_task_runner, 2852 base::SequencedTaskRunner* nss_task_runner,
2831 scoped_ptr<ClientSocketHandle> transport_socket, 2853 scoped_ptr<ClientSocketHandle> transport_socket,
2832 const HostPortPair& host_and_port, 2854 const HostPortPair& host_and_port,
2833 const SSLConfig& ssl_config, 2855 const SSLConfig& ssl_config,
2834 const SSLClientSocketContext& context) 2856 const SSLClientSocketContext& context)
2835 : nss_task_runner_(nss_task_runner), 2857 : nss_task_runner_(nss_task_runner),
2836 transport_(transport_socket.Pass()), 2858 transport_(transport_socket.Pass()),
2837 host_and_port_(host_and_port), 2859 host_and_port_(host_and_port),
2838 ssl_config_(ssl_config), 2860 ssl_config_(ssl_config),
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after
3634 SignedCertificateTimestampAndStatus(*iter, 3656 SignedCertificateTimestampAndStatus(*iter,
3635 ct::SCT_STATUS_LOG_UNKNOWN)); 3657 ct::SCT_STATUS_LOG_UNKNOWN));
3636 } 3658 }
3637 } 3659 }
3638 3660
3639 scoped_refptr<X509Certificate> 3661 scoped_refptr<X509Certificate>
3640 SSLClientSocketNSS::GetUnverifiedServerCertificateChain() const { 3662 SSLClientSocketNSS::GetUnverifiedServerCertificateChain() const {
3641 return core_->state().server_cert.get(); 3663 return core_->state().server_cert.get();
3642 } 3664 }
3643 3665
3666 void SSLClientSocketNSS::ForceClientCertificateAndKeyForTest(
3667 scoped_refptr<X509Certificate> client_cert,
3668 scoped_ptr<crypto::RSAPrivateKey> client_private_key) {
3669 core_->ForceClientCertificateAndKeyForTest(client_cert,
3670 client_private_key.Pass());
3671 }
3672
3644 ChannelIDService* SSLClientSocketNSS::GetChannelIDService() const { 3673 ChannelIDService* SSLClientSocketNSS::GetChannelIDService() const {
3645 return channel_id_service_; 3674 return channel_id_service_;
3646 } 3675 }
3647 3676
3648 } // namespace net 3677 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698