| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/socket/ssl_client_socket_mac.h" | 5 #include "net/socket/ssl_client_socket_mac.h" |
| 6 | 6 |
| 7 #include <CoreServices/CoreServices.h> | 7 #include <CoreServices/CoreServices.h> |
| 8 #include <netdb.h> | 8 #include <netdb.h> |
| 9 #include <sys/socket.h> | 9 #include <sys/socket.h> |
| 10 #include <sys/types.h> | 10 #include <sys/types.h> |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 if (ShouldEnableCipherSuite(supported_ciphers[i])) | 492 if (ShouldEnableCipherSuite(supported_ciphers[i])) |
| 493 ciphers_.push_back(supported_ciphers[i]); | 493 ciphers_.push_back(supported_ciphers[i]); |
| 494 } | 494 } |
| 495 } | 495 } |
| 496 | 496 |
| 497 } // namespace | 497 } // namespace |
| 498 | 498 |
| 499 //----------------------------------------------------------------------------- | 499 //----------------------------------------------------------------------------- |
| 500 | 500 |
| 501 SSLClientSocketMac::SSLClientSocketMac(ClientSocketHandle* transport_socket, | 501 SSLClientSocketMac::SSLClientSocketMac(ClientSocketHandle* transport_socket, |
| 502 const std::string& hostname, | 502 const HostPortPair& host_port_pair, |
| 503 const SSLConfig& ssl_config) | 503 const SSLConfig& ssl_config) |
| 504 : handshake_io_callback_(this, &SSLClientSocketMac::OnHandshakeIOComplete), | 504 : handshake_io_callback_(this, &SSLClientSocketMac::OnHandshakeIOComplete), |
| 505 transport_read_callback_(this, | 505 transport_read_callback_(this, |
| 506 &SSLClientSocketMac::OnTransportReadComplete), | 506 &SSLClientSocketMac::OnTransportReadComplete), |
| 507 transport_write_callback_(this, | 507 transport_write_callback_(this, |
| 508 &SSLClientSocketMac::OnTransportWriteComplete), | 508 &SSLClientSocketMac::OnTransportWriteComplete), |
| 509 transport_(transport_socket), | 509 transport_(transport_socket), |
| 510 hostname_(hostname), | 510 host_port_pair_(host_port_pair), |
| 511 ssl_config_(ssl_config), | 511 ssl_config_(ssl_config), |
| 512 user_connect_callback_(NULL), | 512 user_connect_callback_(NULL), |
| 513 user_read_callback_(NULL), | 513 user_read_callback_(NULL), |
| 514 user_write_callback_(NULL), | 514 user_write_callback_(NULL), |
| 515 user_read_buf_len_(0), | 515 user_read_buf_len_(0), |
| 516 user_write_buf_len_(0), | 516 user_write_buf_len_(0), |
| 517 next_handshake_state_(STATE_NONE), | 517 next_handshake_state_(STATE_NONE), |
| 518 completed_handshake_(false), | 518 completed_handshake_(false), |
| 519 handshake_interrupted_(false), | 519 handshake_interrupted_(false), |
| 520 client_cert_requested_(false), | 520 client_cert_requested_(false), |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 CertPrincipal p; | 682 CertPrincipal p; |
| 683 if (p.ParseDistinguishedName(CFDataGetBytePtr(issuer), | 683 if (p.ParseDistinguishedName(CFDataGetBytePtr(issuer), |
| 684 CFDataGetLength(issuer))) { | 684 CFDataGetLength(issuer))) { |
| 685 valid_issuers.push_back(p); | 685 valid_issuers.push_back(p); |
| 686 } | 686 } |
| 687 } | 687 } |
| 688 CFRelease(valid_issuer_names); | 688 CFRelease(valid_issuer_names); |
| 689 } | 689 } |
| 690 | 690 |
| 691 // Now get the available client certs whose issuers are allowed by the server. | 691 // Now get the available client certs whose issuers are allowed by the server. |
| 692 cert_request_info->host_and_port = hostname_; | 692 cert_request_info->host_and_port = host_port_pair_.ToString(); |
| 693 cert_request_info->client_certs.clear(); | 693 cert_request_info->client_certs.clear(); |
| 694 X509Certificate::GetSSLClientCertificates(hostname_, | 694 X509Certificate::GetSSLClientCertificates(host_port_pair_.host(), |
| 695 valid_issuers, | 695 valid_issuers, |
| 696 &cert_request_info->client_certs); | 696 &cert_request_info->client_certs); |
| 697 SSL_LOG << "Asking user to choose between " | 697 SSL_LOG << "Asking user to choose between " |
| 698 << cert_request_info->client_certs.size() << " client certs..."; | 698 << cert_request_info->client_certs.size() << " client certs..."; |
| 699 } | 699 } |
| 700 | 700 |
| 701 SSLClientSocket::NextProtoStatus | 701 SSLClientSocket::NextProtoStatus |
| 702 SSLClientSocketMac::GetNextProto(std::string* proto) { | 702 SSLClientSocketMac::GetNextProto(std::string* proto) { |
| 703 proto->clear(); | 703 proto->clear(); |
| 704 return kNextProtoUnsupported; | 704 return kNextProtoUnsupported; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 767 | 767 |
| 768 status = SSLSetIOFuncs(ssl_context_, SSLReadCallback, SSLWriteCallback); | 768 status = SSLSetIOFuncs(ssl_context_, SSLReadCallback, SSLWriteCallback); |
| 769 if (status) | 769 if (status) |
| 770 return NetErrorFromOSStatus(status); | 770 return NetErrorFromOSStatus(status); |
| 771 | 771 |
| 772 status = SSLSetConnection(ssl_context_, this); | 772 status = SSLSetConnection(ssl_context_, this); |
| 773 if (status) | 773 if (status) |
| 774 return NetErrorFromOSStatus(status); | 774 return NetErrorFromOSStatus(status); |
| 775 | 775 |
| 776 // Passing the domain name enables the server_name TLS extension (SNI). | 776 // Passing the domain name enables the server_name TLS extension (SNI). |
| 777 const std::string& hostname = host_port_pair_.host(); |
| 777 status = SSLSetPeerDomainName(ssl_context_, | 778 status = SSLSetPeerDomainName(ssl_context_, |
| 778 hostname_.data(), | 779 hostname.data(), |
| 779 hostname_.length()); | 780 hostname.length()); |
| 780 if (status) | 781 if (status) |
| 781 return NetErrorFromOSStatus(status); | 782 return NetErrorFromOSStatus(status); |
| 782 | 783 |
| 783 // Disable certificate verification within Secure Transport; we'll | 784 // Disable certificate verification within Secure Transport; we'll |
| 784 // be handling that ourselves. | 785 // be handling that ourselves. |
| 785 status = SSLSetEnableCertVerify(ssl_context_, false); | 786 status = SSLSetEnableCertVerify(ssl_context_, false); |
| 786 if (status) | 787 if (status) |
| 787 return NetErrorFromOSStatus(status); | 788 return NetErrorFromOSStatus(status); |
| 788 | 789 |
| 789 if (ssl_config_.send_client_cert) { | 790 if (ssl_config_.send_client_cert) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 812 // Concatenate the hostname and peer address to use as the peer ID. To | 813 // Concatenate the hostname and peer address to use as the peer ID. To |
| 813 // resume a session, we must connect to the same server on the same port | 814 // resume a session, we must connect to the same server on the same port |
| 814 // using the same hostname (i.e., localhost and 127.0.0.1 are considered | 815 // using the same hostname (i.e., localhost and 127.0.0.1 are considered |
| 815 // different peers, which puts us through certificate validation again | 816 // different peers, which puts us through certificate validation again |
| 816 // and catches hostname/certificate name mismatches. | 817 // and catches hostname/certificate name mismatches. |
| 817 AddressList address; | 818 AddressList address; |
| 818 int rv = transport_->socket()->GetPeerAddress(&address); | 819 int rv = transport_->socket()->GetPeerAddress(&address); |
| 819 if (rv != OK) | 820 if (rv != OK) |
| 820 return rv; | 821 return rv; |
| 821 const struct addrinfo* ai = address.head(); | 822 const struct addrinfo* ai = address.head(); |
| 822 std::string peer_id(hostname_); | 823 std::string peer_id(host_port_pair_.ToString()); |
| 823 peer_id += std::string(reinterpret_cast<char*>(ai->ai_addr), | 824 peer_id += std::string(reinterpret_cast<char*>(ai->ai_addr), |
| 824 ai->ai_addrlen); | 825 ai->ai_addrlen); |
| 825 | 826 |
| 826 // SSLSetPeerID() treats peer_id as a binary blob, and makes its | 827 // SSLSetPeerID() treats peer_id as a binary blob, and makes its |
| 827 // own copy. | 828 // own copy. |
| 828 status = SSLSetPeerID(ssl_context_, peer_id.data(), peer_id.length()); | 829 status = SSLSetPeerID(ssl_context_, peer_id.data(), peer_id.length()); |
| 829 if (status) | 830 if (status) |
| 830 return NetErrorFromOSStatus(status); | 831 return NetErrorFromOSStatus(status); |
| 831 } else if (status != unimpErr) { // it's OK if the API isn't available | 832 } else if (status != unimpErr) { // it's OK if the API isn't available |
| 832 return NetErrorFromOSStatus(status); | 833 return NetErrorFromOSStatus(status); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1024 if (!server_cert_) | 1025 if (!server_cert_) |
| 1025 return ERR_UNEXPECTED; | 1026 return ERR_UNEXPECTED; |
| 1026 | 1027 |
| 1027 SSL_LOG << "DoVerifyCert..."; | 1028 SSL_LOG << "DoVerifyCert..."; |
| 1028 int flags = 0; | 1029 int flags = 0; |
| 1029 if (ssl_config_.rev_checking_enabled) | 1030 if (ssl_config_.rev_checking_enabled) |
| 1030 flags |= X509Certificate::VERIFY_REV_CHECKING_ENABLED; | 1031 flags |= X509Certificate::VERIFY_REV_CHECKING_ENABLED; |
| 1031 if (ssl_config_.verify_ev_cert) | 1032 if (ssl_config_.verify_ev_cert) |
| 1032 flags |= X509Certificate::VERIFY_EV_CERT; | 1033 flags |= X509Certificate::VERIFY_EV_CERT; |
| 1033 verifier_.reset(new CertVerifier); | 1034 verifier_.reset(new CertVerifier); |
| 1034 return verifier_->Verify(server_cert_, hostname_, flags, | 1035 return verifier_->Verify(server_cert_, host_port_pair_.host(), flags, |
| 1035 &server_cert_verify_result_, | 1036 &server_cert_verify_result_, |
| 1036 &handshake_io_callback_); | 1037 &handshake_io_callback_); |
| 1037 } | 1038 } |
| 1038 | 1039 |
| 1039 int SSLClientSocketMac::DoVerifyCertComplete(int result) { | 1040 int SSLClientSocketMac::DoVerifyCertComplete(int result) { |
| 1040 DCHECK(verifier_.get()); | 1041 DCHECK(verifier_.get()); |
| 1041 verifier_.reset(); | 1042 verifier_.reset(); |
| 1042 | 1043 |
| 1043 SSL_LOG << "...DoVerifyCertComplete (result=" << result << ")"; | 1044 SSL_LOG << "...DoVerifyCertComplete (result=" << result << ")"; |
| 1044 if (IsCertificateError(result) && ssl_config_.IsAllowedBadCert(server_cert_)) | 1045 if (IsCertificateError(result) && ssl_config_.IsAllowedBadCert(server_cert_)) |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1302 if (rv < 0 && rv != ERR_IO_PENDING) { | 1303 if (rv < 0 && rv != ERR_IO_PENDING) { |
| 1303 us->write_io_buf_ = NULL; | 1304 us->write_io_buf_ = NULL; |
| 1304 return OSStatusFromNetError(rv); | 1305 return OSStatusFromNetError(rv); |
| 1305 } | 1306 } |
| 1306 | 1307 |
| 1307 // always lie to our caller | 1308 // always lie to our caller |
| 1308 return noErr; | 1309 return noErr; |
| 1309 } | 1310 } |
| 1310 | 1311 |
| 1311 } // namespace net | 1312 } // namespace net |
| OLD | NEW |