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

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

Issue 4339001: Correctly handle SSL Client Authentication requests when connecting... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 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 | Annotate | Revision Log
OLDNEW
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>
11 11
12 #include "base/mac/scoped_cftyperef.h" 12 #include "base/mac/scoped_cftyperef.h"
13 #include "base/singleton.h" 13 #include "base/singleton.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "net/base/address_list.h" 15 #include "net/base/address_list.h"
16 #include "net/base/cert_verifier.h" 16 #include "net/base/cert_verifier.h"
17 #include "net/base/host_port_pair.h"
17 #include "net/base/io_buffer.h" 18 #include "net/base/io_buffer.h"
18 #include "net/base/net_errors.h" 19 #include "net/base/net_errors.h"
19 #include "net/base/net_log.h" 20 #include "net/base/net_log.h"
20 #include "net/base/ssl_cert_request_info.h" 21 #include "net/base/ssl_cert_request_info.h"
21 #include "net/base/ssl_connection_status_flags.h" 22 #include "net/base/ssl_connection_status_flags.h"
22 #include "net/base/ssl_info.h" 23 #include "net/base/ssl_info.h"
23 #include "net/socket/client_socket_handle.h" 24 #include "net/socket/client_socket_handle.h"
24 25
25 // Welcome to Mac SSL. We've been waiting for you. 26 // Welcome to Mac SSL. We've been waiting for you.
26 // 27 //
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 ciphers_.push_back(supported_ciphers[i]); 494 ciphers_.push_back(supported_ciphers[i]);
494 } 495 }
495 } 496 }
496 497
497 } // namespace 498 } // namespace
498 499
499 //----------------------------------------------------------------------------- 500 //-----------------------------------------------------------------------------
500 501
501 SSLClientSocketMac::SSLClientSocketMac(ClientSocketHandle* transport_socket, 502 SSLClientSocketMac::SSLClientSocketMac(ClientSocketHandle* transport_socket,
502 const std::string& hostname, 503 const std::string& hostname,
504 uint16 port,
503 const SSLConfig& ssl_config) 505 const SSLConfig& ssl_config)
504 : handshake_io_callback_(this, &SSLClientSocketMac::OnHandshakeIOComplete), 506 : handshake_io_callback_(this, &SSLClientSocketMac::OnHandshakeIOComplete),
505 transport_read_callback_(this, 507 transport_read_callback_(this,
506 &SSLClientSocketMac::OnTransportReadComplete), 508 &SSLClientSocketMac::OnTransportReadComplete),
507 transport_write_callback_(this, 509 transport_write_callback_(this,
508 &SSLClientSocketMac::OnTransportWriteComplete), 510 &SSLClientSocketMac::OnTransportWriteComplete),
509 transport_(transport_socket), 511 transport_(transport_socket),
510 hostname_(hostname), 512 hostname_(hostname),
513 port_(port),
511 ssl_config_(ssl_config), 514 ssl_config_(ssl_config),
512 user_connect_callback_(NULL), 515 user_connect_callback_(NULL),
513 user_read_callback_(NULL), 516 user_read_callback_(NULL),
514 user_write_callback_(NULL), 517 user_write_callback_(NULL),
515 user_read_buf_len_(0), 518 user_read_buf_len_(0),
516 user_write_buf_len_(0), 519 user_write_buf_len_(0),
517 next_handshake_state_(STATE_NONE), 520 next_handshake_state_(STATE_NONE),
518 renegotiating_(false), 521 renegotiating_(false),
519 client_cert_requested_(false), 522 client_cert_requested_(false),
520 ssl_context_(NULL), 523 ssl_context_(NULL),
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 CertPrincipal p; 716 CertPrincipal p;
714 if (p.ParseDistinguishedName(CFDataGetBytePtr(issuer), 717 if (p.ParseDistinguishedName(CFDataGetBytePtr(issuer),
715 CFDataGetLength(issuer))) { 718 CFDataGetLength(issuer))) {
716 valid_issuers.push_back(p); 719 valid_issuers.push_back(p);
717 } 720 }
718 } 721 }
719 CFRelease(valid_issuer_names); 722 CFRelease(valid_issuer_names);
720 } 723 }
721 724
722 // Now get the available client certs whose issuers are allowed by the server. 725 // Now get the available client certs whose issuers are allowed by the server.
723 cert_request_info->host_and_port = hostname_; 726 cert_request_info->host_and_port = HostPortPair(hostname_, port_).ToString();
724 cert_request_info->client_certs.clear(); 727 cert_request_info->client_certs.clear();
725 X509Certificate::GetSSLClientCertificates(hostname_, 728 X509Certificate::GetSSLClientCertificates(hostname_,
wtc 2010/11/11 01:11:35 Please add a TODO comment to note that we should c
Ryan Hamilton 2010/11/11 18:57:00 Done.
726 valid_issuers, 729 valid_issuers,
727 &cert_request_info->client_certs); 730 &cert_request_info->client_certs);
728 VLOG(1) << "Asking user to choose between " 731 VLOG(1) << "Asking user to choose between "
729 << cert_request_info->client_certs.size() << " client certs..."; 732 << cert_request_info->client_certs.size() << " client certs...";
730 } 733 }
731 734
732 SSLClientSocket::NextProtoStatus 735 SSLClientSocket::NextProtoStatus
733 SSLClientSocketMac::GetNextProto(std::string* proto) { 736 SSLClientSocketMac::GetNextProto(std::string* proto) {
734 proto->clear(); 737 proto->clear();
735 return kNextProtoUnsupported; 738 return kNextProtoUnsupported;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 // Concatenate the hostname and peer address to use as the peer ID. To 802 // Concatenate the hostname and peer address to use as the peer ID. To
800 // resume a session, we must connect to the same server on the same port 803 // resume a session, we must connect to the same server on the same port
801 // using the same hostname (i.e., localhost and 127.0.0.1 are considered 804 // using the same hostname (i.e., localhost and 127.0.0.1 are considered
802 // different peers, which puts us through certificate validation again 805 // different peers, which puts us through certificate validation again
803 // and catches hostname/certificate name mismatches. 806 // and catches hostname/certificate name mismatches.
804 AddressList address; 807 AddressList address;
805 int rv = transport_->socket()->GetPeerAddress(&address); 808 int rv = transport_->socket()->GetPeerAddress(&address);
806 if (rv != OK) 809 if (rv != OK)
807 return rv; 810 return rv;
808 const struct addrinfo* ai = address.head(); 811 const struct addrinfo* ai = address.head();
809 std::string peer_id(hostname_); 812 std::string peer_id(hostname_);
wtc 2010/11/11 01:11:35 IMPORTANT: we should include 'port_' in peer_id.
Ryan Hamilton 2010/11/11 18:57:00 Appending port_ into peer_id is pretty trivial, bu
wtc 2010/11/12 00:12:55 No, you don't need to change the consumers of peer
810 peer_id += std::string(reinterpret_cast<char*>(ai->ai_addr), 813 peer_id += std::string(reinterpret_cast<char*>(ai->ai_addr),
811 ai->ai_addrlen); 814 ai->ai_addrlen);
812 815
813 // SSLSetPeerID() treats peer_id as a binary blob, and makes its 816 // SSLSetPeerID() treats peer_id as a binary blob, and makes its
814 // own copy. 817 // own copy.
815 status = SSLSetPeerID(ssl_context_, peer_id.data(), peer_id.length()); 818 status = SSLSetPeerID(ssl_context_, peer_id.data(), peer_id.length());
816 if (status) 819 if (status)
817 return NetErrorFromOSStatus(status); 820 return NetErrorFromOSStatus(status);
818 821
819 return OK; 822 return OK;
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 if (rv < 0 && rv != ERR_IO_PENDING) { 1276 if (rv < 0 && rv != ERR_IO_PENDING) {
1274 us->write_io_buf_ = NULL; 1277 us->write_io_buf_ = NULL;
1275 return OSStatusFromNetError(rv); 1278 return OSStatusFromNetError(rv);
1276 } 1279 }
1277 1280
1278 // always lie to our caller 1281 // always lie to our caller
1279 return noErr; 1282 return noErr;
1280 } 1283 }
1281 1284
1282 } // namespace net 1285 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698