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

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

Issue 12220104: Wire up SSL client authentication for OpenSSL/Android through the net/ stack (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 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 // OpenSSL binding for SSLClientSocket. The class layout and general principle 5 // OpenSSL binding for SSLClientSocket. The class layout and general principle
6 // of operation is derived from SSLClientSocketNSS. 6 // of operation is derived from SSLClientSocketNSS.
7 7
8 #include "net/socket/ssl_client_socket_openssl.h" 8 #include "net/socket/ssl_client_socket_openssl.h"
9 9
10 #include <openssl/ssl.h> 10 #include <openssl/ssl.h>
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 reinterpret_cast<const char*>(str), 583 reinterpret_cast<const char*>(str),
584 static_cast<size_t>(length))); 584 static_cast<size_t>(length)));
585 OPENSSL_free(str); 585 OPENSSL_free(str);
586 } 586 }
587 587
588 return -1; // Suspends handshake. 588 return -1; // Suspends handshake.
589 } 589 }
590 590
591 // Second pass: a client certificate should have been selected. 591 // Second pass: a client certificate should have been selected.
592 if (ssl_config_.client_cert) { 592 if (ssl_config_.client_cert) {
593 EVP_PKEY* privkey = OpenSSLPrivateKeyStore::GetInstance()->FetchPrivateKey( 593 // A note about ownership: FetchClientCertPrivateKey() increments
594 X509_PUBKEY_get(X509_get_X509_PUBKEY( 594 // the reference count of the EVP_PKEY. Ownership of this reference
595 ssl_config_.client_cert->os_cert_handle()))); 595 // is passed directly to OpenSSL, which will release the reference
596 if (privkey) { 596 // using EVP_PKEY_free() when the SSL object is destroyed.
597 OpenSSLPrivateKeyStore::ScopedEVP_PKEY privkey;
598 if (OpenSSLPrivateKeyStore::GetInstance()->FetchClientCertPrivateKey(
599 ssl_config_.client_cert.get(), &privkey)) {
597 // TODO(joth): (copied from NSS) We should wait for server certificate 600 // TODO(joth): (copied from NSS) We should wait for server certificate
598 // verification before sending our credentials. See http://crbug.com/13934 601 // verification before sending our credentials. See http://crbug.com/13934
599 *x509 = X509Certificate::DupOSCertHandle( 602 *x509 = X509Certificate::DupOSCertHandle(
600 ssl_config_.client_cert->os_cert_handle()); 603 ssl_config_.client_cert->os_cert_handle());
601 *pkey = privkey; 604 *pkey = privkey.release();
602 return 1; 605 return 1;
603 } 606 }
604 LOG(WARNING) << "Client cert found without private key"; 607 LOG(WARNING) << "Client cert found without private key";
605 } 608 }
606 609
607 // Send no client certificate. 610 // Send no client certificate.
608 return 0; 611 return 0;
609 } 612 }
610 613
611 // SSLClientSocket methods 614 // SSLClientSocket methods
612 615
613 bool SSLClientSocketOpenSSL::GetSSLInfo(SSLInfo* ssl_info) { 616 bool SSLClientSocketOpenSSL::GetSSLInfo(SSLInfo* ssl_info) {
614 ssl_info->Reset(); 617 ssl_info->Reset();
618
619 ssl_info->client_cert_sent =
620 ssl_config_.send_client_cert && ssl_config_.client_cert;
Ryan Sleevi 2013/02/25 19:51:07 Why did you move this here? This seems to violate
digit1 2013/02/26 11:03:13 Because this would always return a false value in
621
615 if (!server_cert_) 622 if (!server_cert_)
616 return false; 623 return false;
617 624
618 ssl_info->cert = server_cert_verify_result_.verified_cert; 625 ssl_info->cert = server_cert_verify_result_.verified_cert;
619 ssl_info->cert_status = server_cert_verify_result_.cert_status; 626 ssl_info->cert_status = server_cert_verify_result_.cert_status;
620 ssl_info->is_issued_by_known_root = 627 ssl_info->is_issued_by_known_root =
621 server_cert_verify_result_.is_issued_by_known_root; 628 server_cert_verify_result_.is_issued_by_known_root;
622 ssl_info->public_key_hashes = 629 ssl_info->public_key_hashes =
623 server_cert_verify_result_.public_key_hashes; 630 server_cert_verify_result_.public_key_hashes;
624 ssl_info->client_cert_sent =
625 ssl_config_.send_client_cert && ssl_config_.client_cert;
626 ssl_info->channel_id_sent = WasChannelIDSent(); 631 ssl_info->channel_id_sent = WasChannelIDSent();
627 632
628 const SSL_CIPHER* cipher = SSL_get_current_cipher(ssl_); 633 const SSL_CIPHER* cipher = SSL_get_current_cipher(ssl_);
629 CHECK(cipher); 634 CHECK(cipher);
630 ssl_info->security_bits = SSL_CIPHER_get_bits(cipher, NULL); 635 ssl_info->security_bits = SSL_CIPHER_get_bits(cipher, NULL);
631 const COMP_METHOD* compression = SSL_get_current_compression(ssl_); 636 const COMP_METHOD* compression = SSL_get_current_compression(ssl_);
632 637
633 ssl_info->connection_status = EncodeSSLConnectionStatus( 638 ssl_info->connection_status = EncodeSSLConnectionStatus(
634 SSL_CIPHER_get_id(cipher), 639 SSL_CIPHER_get_id(cipher),
635 compression ? compression->type : 0, 640 compression ? compression->type : 0,
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after
1416 net_log_.AddByteTransferEvent(NetLog::TYPE_SSL_SOCKET_BYTES_SENT, rv, 1421 net_log_.AddByteTransferEvent(NetLog::TYPE_SSL_SOCKET_BYTES_SENT, rv,
1417 user_write_buf_->data()); 1422 user_write_buf_->data());
1418 return rv; 1423 return rv;
1419 } 1424 }
1420 1425
1421 int err = SSL_get_error(ssl_, rv); 1426 int err = SSL_get_error(ssl_, rv);
1422 return MapOpenSSLError(err, err_tracer); 1427 return MapOpenSSLError(err, err_tracer);
1423 } 1428 }
1424 1429
1425 } // namespace net 1430 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698