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

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: Passing this CL to RyanChung for further work. 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
« no previous file with comments | « net/socket/ssl_client_socket_nss.h ('k') | net/socket/ssl_client_socket_openssl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 bool WasEverUsed() const; 511 bool WasEverUsed() const;
512 512
513 // Called on the network task runner. 513 // Called on the network task runner.
514 // Causes the associated SSL/TLS session ID to be added to NSS's session 514 // Causes the associated SSL/TLS session ID to be added to NSS's session
515 // cache, but only if the connection has not been False Started. 515 // cache, but only if the connection has not been False Started.
516 // 516 //
517 // This should only be called after the server's certificate has been 517 // This should only be called after the server's certificate has been
518 // verified, and may not be called within an NSS callback. 518 // verified, and may not be called within an NSS callback.
519 void CacheSessionIfNecessary(); 519 void CacheSessionIfNecessary();
520 520
521 // Only for unit testing.
522 // This should only be called before Connect().
523 void ForceClientCertificateAndKeyForTest(
524 scoped_refptr<X509Certificate> client_cert,
525 scoped_ptr<crypto::RSAPrivateKey> client_private_key);
526
521 private: 527 private:
522 friend class base::RefCountedThreadSafe<Core>; 528 friend class base::RefCountedThreadSafe<Core>;
523 ~Core(); 529 ~Core();
524 530
525 enum State { 531 enum State {
526 STATE_NONE, 532 STATE_NONE,
527 STATE_HANDSHAKE, 533 STATE_HANDSHAKE,
528 STATE_GET_DOMAIN_BOUND_CERT_COMPLETE, 534 STATE_GET_DOMAIN_BOUND_CERT_COMPLETE,
529 }; 535 };
530 536
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 // Dereferenced only on the network task runner, but bound to tasks destined 778 // Dereferenced only on the network task runner, but bound to tasks destined
773 // for the network task runner from the NSS task runner. 779 // for the network task runner from the NSS task runner.
774 base::WeakPtr<BoundNetLog> weak_net_log_; 780 base::WeakPtr<BoundNetLog> weak_net_log_;
775 781
776 // Written on the network task runner by the |channel_id_service_|, 782 // Written on the network task runner by the |channel_id_service_|,
777 // prior to invoking OnHandshakeIOComplete. 783 // prior to invoking OnHandshakeIOComplete.
778 // Read on the NSS task runner when once OnHandshakeIOComplete is invoked 784 // Read on the NSS task runner when once OnHandshakeIOComplete is invoked
779 // on the NSS task runner. 785 // on the NSS task runner.
780 scoped_ptr<crypto::ECPrivateKey> channel_id_key_; 786 scoped_ptr<crypto::ECPrivateKey> channel_id_key_;
781 787
788 // Used only for unit testing.
789 scoped_ptr<crypto::RSAPrivateKey> client_private_key_;
790
782 DISALLOW_COPY_AND_ASSIGN(Core); 791 DISALLOW_COPY_AND_ASSIGN(Core);
783 }; 792 };
784 793
785 SSLClientSocketNSS::Core::Core( 794 SSLClientSocketNSS::Core::Core(
786 base::SequencedTaskRunner* network_task_runner, 795 base::SequencedTaskRunner* network_task_runner,
787 base::SequencedTaskRunner* nss_task_runner, 796 base::SequencedTaskRunner* nss_task_runner,
788 ClientSocketHandle* transport, 797 ClientSocketHandle* transport,
789 const HostPortPair& host_and_port, 798 const HostPortPair& host_and_port,
790 const SSLConfig& ssl_config, 799 const SSLConfig& ssl_config,
791 BoundNetLog* net_log, 800 BoundNetLog* net_log,
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
1189 1198
1190 // Regular client certificate requested. 1199 // Regular client certificate requested.
1191 core->client_auth_cert_needed_ = !core->ssl_config_.send_client_cert; 1200 core->client_auth_cert_needed_ = !core->ssl_config_.send_client_cert;
1192 void* wincx = SSL_RevealPinArg(socket); 1201 void* wincx = SSL_RevealPinArg(socket);
1193 1202
1194 if (core->ssl_config_.send_client_cert) { 1203 if (core->ssl_config_.send_client_cert) {
1195 // Second pass: a client certificate should have been selected. 1204 // Second pass: a client certificate should have been selected.
1196 if (core->ssl_config_.client_cert.get()) { 1205 if (core->ssl_config_.client_cert.get()) {
1197 CERTCertificate* cert = 1206 CERTCertificate* cert =
1198 CERT_DupCertificate(core->ssl_config_.client_cert->os_cert_handle()); 1207 CERT_DupCertificate(core->ssl_config_.client_cert->os_cert_handle());
1199 SECKEYPrivateKey* privkey = PK11_FindKeyByAnyCert(cert, wincx); 1208 SECKEYPrivateKey* privkey = NULL;
1209 if (core->client_private_key_.get()) {
1210 privkey = SECKEY_CopyPrivateKey(core->client_private_key_->key());
1211 } else {
1212 privkey = PK11_FindKeyByAnyCert(cert, wincx);
1213 }
1200 if (privkey) { 1214 if (privkey) {
1201 // TODO(jsorianopastor): We should wait for server certificate 1215 // TODO(jsorianopastor): We should wait for server certificate
1202 // verification before sending our credentials. See 1216 // verification before sending our credentials. See
1203 // http://crbug.com/13934. 1217 // http://crbug.com/13934.
1204 *result_certificate = cert; 1218 *result_certificate = cert;
1205 *result_private_key = privkey; 1219 *result_private_key = privkey;
1206 // A cert_count of -1 means the number of certificates is unknown. 1220 // A cert_count of -1 means the number of certificates is unknown.
1207 // NSS will construct the certificate chain. 1221 // NSS will construct the certificate chain.
1208 core->AddCertProvidedEvent(-1); 1222 core->AddCertProvidedEvent(-1);
1209 1223
(...skipping 1136 matching lines...) Expand 10 before | Expand all | Expand 10 after
2346 FROM_HERE, base::Bind(&AddLogEvent, weak_net_log_, 2360 FROM_HERE, base::Bind(&AddLogEvent, weak_net_log_,
2347 NetLog::TYPE_SSL_CHANNEL_ID_PROVIDED)); 2361 NetLog::TYPE_SSL_CHANNEL_ID_PROVIDED));
2348 nss_handshake_state_.channel_id_sent = true; 2362 nss_handshake_state_.channel_id_sent = true;
2349 // Update the network task runner's view of the handshake state now that 2363 // Update the network task runner's view of the handshake state now that
2350 // channel id has been sent. 2364 // channel id has been sent.
2351 PostOrRunCallback( 2365 PostOrRunCallback(
2352 FROM_HERE, base::Bind(&Core::OnHandshakeStateUpdated, this, 2366 FROM_HERE, base::Bind(&Core::OnHandshakeStateUpdated, this,
2353 nss_handshake_state_)); 2367 nss_handshake_state_));
2354 } 2368 }
2355 2369
2370 void SSLClientSocketNSS::Core::ForceClientCertificateAndKeyForTest(
2371 scoped_refptr<X509Certificate> client_cert,
2372 scoped_ptr<crypto::RSAPrivateKey> client_private_key) {
2373 ssl_config_.send_client_cert = true;
2374 ssl_config_.client_cert = client_cert;
2375 client_private_key_ = client_private_key.Pass();
2376 }
2377
2356 SSLClientSocketNSS::SSLClientSocketNSS( 2378 SSLClientSocketNSS::SSLClientSocketNSS(
2357 scoped_ptr<ClientSocketHandle> transport_socket, 2379 scoped_ptr<ClientSocketHandle> transport_socket,
2358 const HostPortPair& host_and_port, 2380 const HostPortPair& host_and_port,
2359 const SSLConfig& ssl_config, 2381 const SSLConfig& ssl_config,
2360 const SSLClientSocketContext& context) 2382 const SSLClientSocketContext& context)
2361 : transport_(transport_socket.Pass()), 2383 : transport_(transport_socket.Pass()),
2362 host_and_port_(host_and_port), 2384 host_and_port_(host_and_port),
2363 ssl_config_(ssl_config), 2385 ssl_config_(ssl_config),
2364 cert_verifier_(context.cert_verifier), 2386 cert_verifier_(context.cert_verifier),
2365 cert_transparency_verifier_(context.cert_transparency_verifier), 2387 cert_transparency_verifier_(context.cert_transparency_verifier),
(...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after
3178 return; 3200 return;
3179 } 3201 }
3180 3202
3181 NextProto fallback_proto = next_protos->back(); 3203 NextProto fallback_proto = next_protos->back();
3182 for (size_t i = next_protos->size() - 1; i > 0; --i) { 3204 for (size_t i = next_protos->size() - 1; i > 0; --i) {
3183 (*next_protos)[i] = (*next_protos)[i - 1]; 3205 (*next_protos)[i] = (*next_protos)[i - 1];
3184 } 3206 }
3185 (*next_protos)[0] = fallback_proto; 3207 (*next_protos)[0] = fallback_proto;
3186 } 3208 }
3187 3209
3210 void SSLClientSocketNSS::ForceClientCertificateAndKeyForTest(
3211 scoped_refptr<X509Certificate> client_cert,
3212 scoped_ptr<crypto::RSAPrivateKey> client_private_key) {
3213 core_->ForceClientCertificateAndKeyForTest(client_cert,
3214 client_private_key.Pass());
3215 }
3216
3188 ChannelIDService* SSLClientSocketNSS::GetChannelIDService() const { 3217 ChannelIDService* SSLClientSocketNSS::GetChannelIDService() const {
3189 return channel_id_service_; 3218 return channel_id_service_;
3190 } 3219 }
3191 3220
3192 SSLFailureState SSLClientSocketNSS::GetSSLFailureState() const { 3221 SSLFailureState SSLClientSocketNSS::GetSSLFailureState() const {
3193 if (completed_handshake_) 3222 if (completed_handshake_)
3194 return SSL_FAILURE_NONE; 3223 return SSL_FAILURE_NONE;
3195 return SSL_FAILURE_UNKNOWN; 3224 return SSL_FAILURE_UNKNOWN;
3196 } 3225 }
3197 3226
3198 } // namespace net 3227 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/ssl_client_socket_nss.h ('k') | net/socket/ssl_client_socket_openssl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698