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> |
11 | 11 |
12 #include "base/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/io_buffer.h" | 17 #include "net/base/io_buffer.h" |
18 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
19 #include "net/base/net_log.h" | 19 #include "net/base/net_log.h" |
20 #include "net/base/ssl_cert_request_info.h" | 20 #include "net/base/ssl_cert_request_info.h" |
21 #include "net/base/ssl_connection_status_flags.h" | 21 #include "net/base/ssl_connection_status_flags.h" |
22 #include "net/base/ssl_info.h" | 22 #include "net/base/ssl_info.h" |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 // Returns the server's certificate. The caller must release a reference | 406 // Returns the server's certificate. The caller must release a reference |
407 // to the return value when done. Returns NULL on failure. | 407 // to the return value when done. Returns NULL on failure. |
408 X509Certificate* GetServerCert(SSLContextRef ssl_context) { | 408 X509Certificate* GetServerCert(SSLContextRef ssl_context) { |
409 CFArrayRef certs; | 409 CFArrayRef certs; |
410 OSStatus status = SSLCopyPeerCertificates(ssl_context, &certs); | 410 OSStatus status = SSLCopyPeerCertificates(ssl_context, &certs); |
411 // SSLCopyPeerCertificates may succeed but return a null |certs| | 411 // SSLCopyPeerCertificates may succeed but return a null |certs| |
412 // (if we're using an anonymous cipher suite or if we call it | 412 // (if we're using an anonymous cipher suite or if we call it |
413 // before the certificate message has arrived and been parsed). | 413 // before the certificate message has arrived and been parsed). |
414 if (status != noErr || !certs) | 414 if (status != noErr || !certs) |
415 return NULL; | 415 return NULL; |
416 scoped_cftyperef<CFArrayRef> scoped_certs(certs); | 416 base::mac::ScopedCFTypeRef<CFArrayRef> scoped_certs(certs); |
417 | 417 |
418 DCHECK_GT(CFArrayGetCount(certs), 0); | 418 DCHECK_GT(CFArrayGetCount(certs), 0); |
419 | 419 |
420 // Add each of the intermediate certificates in the server's chain to the | 420 // Add each of the intermediate certificates in the server's chain to the |
421 // server's X509Certificate object. This makes them available to | 421 // server's X509Certificate object. This makes them available to |
422 // X509Certificate::Verify() for chain building. | 422 // X509Certificate::Verify() for chain building. |
423 std::vector<SecCertificateRef> intermediate_ca_certs; | 423 std::vector<SecCertificateRef> intermediate_ca_certs; |
424 CFIndex certs_length = CFArrayGetCount(certs); | 424 CFIndex certs_length = CFArrayGetCount(certs); |
425 for (CFIndex i = 1; i < certs_length; ++i) { | 425 for (CFIndex i = 1; i < certs_length; ++i) { |
426 SecCertificateRef cert_ref = reinterpret_cast<SecCertificateRef>( | 426 SecCertificateRef cert_ref = reinterpret_cast<SecCertificateRef>( |
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 // The initial handshake has completed. | 1035 // The initial handshake has completed. |
1036 next_handshake_state_ = STATE_COMPLETED_HANDSHAKE; | 1036 next_handshake_state_ = STATE_COMPLETED_HANDSHAKE; |
1037 | 1037 |
1038 return result; | 1038 return result; |
1039 } | 1039 } |
1040 | 1040 |
1041 int SSLClientSocketMac::SetClientCert() { | 1041 int SSLClientSocketMac::SetClientCert() { |
1042 if (!ssl_config_.send_client_cert || !ssl_config_.client_cert) | 1042 if (!ssl_config_.send_client_cert || !ssl_config_.client_cert) |
1043 return noErr; | 1043 return noErr; |
1044 | 1044 |
1045 scoped_cftyperef<CFArrayRef> cert_refs( | 1045 base::mac::ScopedCFTypeRef<CFArrayRef> cert_refs( |
1046 ssl_config_.client_cert->CreateClientCertificateChain()); | 1046 ssl_config_.client_cert->CreateClientCertificateChain()); |
1047 VLOG(1) << "SSLSetCertificate(" << CFArrayGetCount(cert_refs) << " certs)"; | 1047 VLOG(1) << "SSLSetCertificate(" << CFArrayGetCount(cert_refs) << " certs)"; |
1048 OSStatus result = SSLSetCertificate(ssl_context_, cert_refs); | 1048 OSStatus result = SSLSetCertificate(ssl_context_, cert_refs); |
1049 if (result) | 1049 if (result) |
1050 LOG(ERROR) << "SSLSetCertificate returned OSStatus " << result; | 1050 LOG(ERROR) << "SSLSetCertificate returned OSStatus " << result; |
1051 return result; | 1051 return result; |
1052 } | 1052 } |
1053 | 1053 |
1054 int SSLClientSocketMac::DoPayloadRead() { | 1054 int SSLClientSocketMac::DoPayloadRead() { |
1055 size_t processed = 0; | 1055 size_t processed = 0; |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1261 if (rv < 0 && rv != ERR_IO_PENDING) { | 1261 if (rv < 0 && rv != ERR_IO_PENDING) { |
1262 us->write_io_buf_ = NULL; | 1262 us->write_io_buf_ = NULL; |
1263 return OSStatusFromNetError(rv); | 1263 return OSStatusFromNetError(rv); |
1264 } | 1264 } |
1265 | 1265 |
1266 // always lie to our caller | 1266 // always lie to our caller |
1267 return noErr; | 1267 return noErr; |
1268 } | 1268 } |
1269 | 1269 |
1270 } // namespace net | 1270 } // namespace net |
OLD | NEW |