| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 const HostPortPair& host_and_port, | 524 const HostPortPair& host_and_port, |
| 525 const SSLConfig& ssl_config, | 525 const SSLConfig& ssl_config, |
| 526 const SSLClientSocketContext& context) | 526 const SSLClientSocketContext& context) |
| 527 : transport_read_callback_(this, | 527 : transport_read_callback_(this, |
| 528 &SSLClientSocketMac::OnTransportReadComplete), | 528 &SSLClientSocketMac::OnTransportReadComplete), |
| 529 transport_write_callback_(this, | 529 transport_write_callback_(this, |
| 530 &SSLClientSocketMac::OnTransportWriteComplete), | 530 &SSLClientSocketMac::OnTransportWriteComplete), |
| 531 transport_(transport_socket), | 531 transport_(transport_socket), |
| 532 host_and_port_(host_and_port), | 532 host_and_port_(host_and_port), |
| 533 ssl_config_(ssl_config), | 533 ssl_config_(ssl_config), |
| 534 user_connect_callback_(NULL), | 534 old_user_connect_callback_(NULL), |
| 535 user_read_callback_(NULL), | 535 user_read_callback_(NULL), |
| 536 user_write_callback_(NULL), | 536 user_write_callback_(NULL), |
| 537 user_read_buf_len_(0), | 537 user_read_buf_len_(0), |
| 538 user_write_buf_len_(0), | 538 user_write_buf_len_(0), |
| 539 next_handshake_state_(STATE_NONE), | 539 next_handshake_state_(STATE_NONE), |
| 540 cert_verifier_(context.cert_verifier), | 540 cert_verifier_(context.cert_verifier), |
| 541 renegotiating_(false), | 541 renegotiating_(false), |
| 542 client_cert_requested_(false), | 542 client_cert_requested_(false), |
| 543 ssl_context_(NULL), | 543 ssl_context_(NULL), |
| 544 bytes_read_after_renegotiation_(0), | 544 bytes_read_after_renegotiation_(0), |
| 545 pending_send_error_(OK), | 545 pending_send_error_(OK), |
| 546 net_log_(transport_socket->socket()->NetLog()) { | 546 net_log_(transport_socket->socket()->NetLog()) { |
| 547 // Sort the list of ciphers to disable, since disabling ciphers on Mac | 547 // Sort the list of ciphers to disable, since disabling ciphers on Mac |
| 548 // requires subtracting from a list of enabled ciphers while maintaining | 548 // requires subtracting from a list of enabled ciphers while maintaining |
| 549 // ordering, as opposed to merely needing to iterate them as with NSS. | 549 // ordering, as opposed to merely needing to iterate them as with NSS. |
| 550 sort(ssl_config_.disabled_cipher_suites.begin(), | 550 sort(ssl_config_.disabled_cipher_suites.begin(), |
| 551 ssl_config_.disabled_cipher_suites.end()); | 551 ssl_config_.disabled_cipher_suites.end()); |
| 552 } | 552 } |
| 553 | 553 |
| 554 SSLClientSocketMac::~SSLClientSocketMac() { | 554 SSLClientSocketMac::~SSLClientSocketMac() { |
| 555 Disconnect(); | 555 Disconnect(); |
| 556 } | 556 } |
| 557 | 557 |
| 558 int SSLClientSocketMac::Connect(OldCompletionCallback* callback) { | 558 int SSLClientSocketMac::Connect(OldCompletionCallback* callback) { |
| 559 DCHECK(transport_.get()); | 559 DCHECK(transport_.get()); |
| 560 DCHECK(next_handshake_state_ == STATE_NONE); | 560 DCHECK(next_handshake_state_ == STATE_NONE); |
| 561 DCHECK(!user_connect_callback_); | 561 DCHECK(!old_user_connect_callback_ && user_connect_callback_.is_null()); |
| 562 | 562 |
| 563 net_log_.BeginEvent(NetLog::TYPE_SSL_CONNECT, NULL); | 563 net_log_.BeginEvent(NetLog::TYPE_SSL_CONNECT, NULL); |
| 564 | 564 |
| 565 int rv = InitializeSSLContext(); |
| 566 if (rv != OK) { |
| 567 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); |
| 568 return rv; |
| 569 } |
| 570 |
| 571 next_handshake_state_ = STATE_HANDSHAKE; |
| 572 rv = DoHandshakeLoop(OK); |
| 573 if (rv == ERR_IO_PENDING) { |
| 574 old_user_connect_callback_ = callback; |
| 575 } else { |
| 576 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); |
| 577 } |
| 578 return rv; |
| 579 } |
| 580 int SSLClientSocketMac::Connect(const CompletionCallback& callback) { |
| 581 DCHECK(transport_.get()); |
| 582 DCHECK(next_handshake_state_ == STATE_NONE); |
| 583 DCHECK(!old_user_connect_callback_ && user_connect_callback_.is_null()); |
| 584 |
| 585 net_log_.BeginEvent(NetLog::TYPE_SSL_CONNECT, NULL); |
| 586 |
| 565 int rv = InitializeSSLContext(); | 587 int rv = InitializeSSLContext(); |
| 566 if (rv != OK) { | 588 if (rv != OK) { |
| 567 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); | 589 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); |
| 568 return rv; | 590 return rv; |
| 569 } | 591 } |
| 570 | 592 |
| 571 next_handshake_state_ = STATE_HANDSHAKE; | 593 next_handshake_state_ = STATE_HANDSHAKE; |
| 572 rv = DoHandshakeLoop(OK); | 594 rv = DoHandshakeLoop(OK); |
| 573 if (rv == ERR_IO_PENDING) { | 595 if (rv == ERR_IO_PENDING) { |
| 574 user_connect_callback_ = callback; | 596 user_connect_callback_ = callback; |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 // own copy. | 909 // own copy. |
| 888 status = SSLSetPeerID(ssl_context_, peer_id.data(), peer_id.length()); | 910 status = SSLSetPeerID(ssl_context_, peer_id.data(), peer_id.length()); |
| 889 if (status) | 911 if (status) |
| 890 return NetErrorFromOSStatus(status); | 912 return NetErrorFromOSStatus(status); |
| 891 | 913 |
| 892 return OK; | 914 return OK; |
| 893 } | 915 } |
| 894 | 916 |
| 895 void SSLClientSocketMac::DoConnectCallback(int rv) { | 917 void SSLClientSocketMac::DoConnectCallback(int rv) { |
| 896 DCHECK(rv != ERR_IO_PENDING); | 918 DCHECK(rv != ERR_IO_PENDING); |
| 897 DCHECK(user_connect_callback_); | 919 DCHECK(old_user_connect_callback_ || !user_connect_callback_.is_null()); |
| 898 | 920 |
| 899 OldCompletionCallback* c = user_connect_callback_; | 921 if (old_user_connect_callback_) { |
| 900 user_connect_callback_ = NULL; | 922 OldCompletionCallback* c = old_user_connect_callback_; |
| 901 c->Run(rv > OK ? OK : rv); | 923 old_user_connect_callback_ = NULL; |
| 924 c->Run(rv > OK ? OK : rv); |
| 925 } else { |
| 926 CompletionCallback c = user_connect_callback_; |
| 927 user_connect_callback_.Reset(); |
| 928 c.Run(rv > OK ? OK : rv); |
| 929 } |
| 902 } | 930 } |
| 903 | 931 |
| 904 void SSLClientSocketMac::DoReadCallback(int rv) { | 932 void SSLClientSocketMac::DoReadCallback(int rv) { |
| 905 DCHECK(rv != ERR_IO_PENDING); | 933 DCHECK(rv != ERR_IO_PENDING); |
| 906 DCHECK(user_read_callback_); | 934 DCHECK(user_read_callback_); |
| 907 | 935 |
| 908 // Since Run may result in Read being called, clear user_read_callback_ up | 936 // Since Run may result in Read being called, clear user_read_callback_ up |
| 909 // front. | 937 // front. |
| 910 OldCompletionCallback* c = user_read_callback_; | 938 OldCompletionCallback* c = user_read_callback_; |
| 911 user_read_callback_ = NULL; | 939 user_read_callback_ = NULL; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 927 c->Run(rv); | 955 c->Run(rv); |
| 928 } | 956 } |
| 929 | 957 |
| 930 void SSLClientSocketMac::OnHandshakeIOComplete(int result) { | 958 void SSLClientSocketMac::OnHandshakeIOComplete(int result) { |
| 931 int rv = DoHandshakeLoop(result); | 959 int rv = DoHandshakeLoop(result); |
| 932 if (rv != ERR_IO_PENDING) { | 960 if (rv != ERR_IO_PENDING) { |
| 933 // If there is no connect callback available to call, we are | 961 // If there is no connect callback available to call, we are |
| 934 // renegotiating (which occurs because we are in the middle of a Read | 962 // renegotiating (which occurs because we are in the middle of a Read |
| 935 // when the renegotiation process starts). So we complete the Read | 963 // when the renegotiation process starts). So we complete the Read |
| 936 // here. | 964 // here. |
| 937 if (!user_connect_callback_) { | 965 if (!old_user_connect_callback_ && user_connect_callback_.is_null()) { |
| 938 DoReadCallback(rv); | 966 DoReadCallback(rv); |
| 939 return; | 967 return; |
| 940 } | 968 } |
| 941 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); | 969 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); |
| 942 DoConnectCallback(rv); | 970 DoConnectCallback(rv); |
| 943 } | 971 } |
| 944 } | 972 } |
| 945 | 973 |
| 946 void SSLClientSocketMac::OnTransportReadComplete(int result) { | 974 void SSLClientSocketMac::OnTransportReadComplete(int result) { |
| 947 if (result > 0) { | 975 if (result > 0) { |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1265 // The user had a read in progress, which was interrupted by the | 1293 // The user had a read in progress, which was interrupted by the |
| 1266 // renegotiation. Return the application data that was processed after the | 1294 // renegotiation. Return the application data that was processed after the |
| 1267 // handshake completed. | 1295 // handshake completed. |
| 1268 next_handshake_state_ = STATE_COMPLETED_HANDSHAKE; | 1296 next_handshake_state_ = STATE_COMPLETED_HANDSHAKE; |
| 1269 if (result != OK) | 1297 if (result != OK) |
| 1270 return result; | 1298 return result; |
| 1271 return bytes_read_after_renegotiation_; | 1299 return bytes_read_after_renegotiation_; |
| 1272 } | 1300 } |
| 1273 | 1301 |
| 1274 void SSLClientSocketMac::DidCompleteRenegotiation() { | 1302 void SSLClientSocketMac::DidCompleteRenegotiation() { |
| 1275 DCHECK(!user_connect_callback_); | 1303 DCHECK(!old_user_connect_callback_ && user_connect_callback_.is_null()); |
| 1276 renegotiating_ = false; | 1304 renegotiating_ = false; |
| 1277 next_handshake_state_ = STATE_COMPLETED_RENEGOTIATION; | 1305 next_handshake_state_ = STATE_COMPLETED_RENEGOTIATION; |
| 1278 } | 1306 } |
| 1279 | 1307 |
| 1280 int SSLClientSocketMac::DidCompleteHandshake() { | 1308 int SSLClientSocketMac::DidCompleteHandshake() { |
| 1281 DCHECK(!server_cert_ || renegotiating_); | 1309 DCHECK(!server_cert_ || renegotiating_); |
| 1282 VLOG(1) << "Handshake completed, next verify cert"; | 1310 VLOG(1) << "Handshake completed, next verify cert"; |
| 1283 | 1311 |
| 1284 scoped_refptr<X509Certificate> new_server_cert( | 1312 scoped_refptr<X509Certificate> new_server_cert( |
| 1285 GetServerCert(ssl_context_)); | 1313 GetServerCert(ssl_context_)); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1427 if (rv < 0 && rv != ERR_IO_PENDING) { | 1455 if (rv < 0 && rv != ERR_IO_PENDING) { |
| 1428 us->write_io_buf_ = NULL; | 1456 us->write_io_buf_ = NULL; |
| 1429 return OSStatusFromNetError(rv); | 1457 return OSStatusFromNetError(rv); |
| 1430 } | 1458 } |
| 1431 | 1459 |
| 1432 // always lie to our caller | 1460 // always lie to our caller |
| 1433 return noErr; | 1461 return noErr; |
| 1434 } | 1462 } |
| 1435 | 1463 |
| 1436 } // namespace net | 1464 } // namespace net |
| OLD | NEW |