OLD | NEW |
1 // Copyright (c) 2008-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008-2009 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/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/load_log.h" | |
19 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.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_info.h" | 21 #include "net/base/ssl_info.h" |
22 | 22 |
23 // Welcome to Mac SSL. We've been waiting for you. | 23 // Welcome to Mac SSL. We've been waiting for you. |
24 // | 24 // |
25 // The Mac SSL implementation is, like the Windows and NSS implementations, a | 25 // The Mac SSL implementation is, like the Windows and NSS implementations, a |
26 // giant state machine. This design constraint is due to the asynchronous nature | 26 // giant state machine. This design constraint is due to the asynchronous nature |
27 // of our underlying transport mechanism. We can call down to read/write on the | 27 // of our underlying transport mechanism. We can call down to read/write on the |
28 // network, but what happens is that either it completes immediately or returns | 28 // network, but what happens is that either it completes immediately or returns |
29 // saying that we'll get a callback sometime in the future. In that case, we | 29 // saying that we'll get a callback sometime in the future. In that case, we |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 handshake_interrupted_(false), | 511 handshake_interrupted_(false), |
512 ssl_context_(NULL), | 512 ssl_context_(NULL), |
513 pending_send_error_(OK) { | 513 pending_send_error_(OK) { |
514 } | 514 } |
515 | 515 |
516 SSLClientSocketMac::~SSLClientSocketMac() { | 516 SSLClientSocketMac::~SSLClientSocketMac() { |
517 Disconnect(); | 517 Disconnect(); |
518 } | 518 } |
519 | 519 |
520 int SSLClientSocketMac::Connect(CompletionCallback* callback, | 520 int SSLClientSocketMac::Connect(CompletionCallback* callback, |
521 LoadLog* load_log) { | 521 const BoundNetLog& net_log) { |
522 DCHECK(transport_.get()); | 522 DCHECK(transport_.get()); |
523 DCHECK(next_handshake_state_ == STATE_NONE); | 523 DCHECK(next_handshake_state_ == STATE_NONE); |
524 DCHECK(!user_connect_callback_); | 524 DCHECK(!user_connect_callback_); |
525 | 525 |
526 LoadLog::BeginEvent(load_log, LoadLog::TYPE_SSL_CONNECT); | 526 net_log.BeginEvent(NetLog::TYPE_SSL_CONNECT); |
527 | 527 |
528 int rv = InitializeSSLContext(); | 528 int rv = InitializeSSLContext(); |
529 if (rv != OK) { | 529 if (rv != OK) { |
530 LoadLog::EndEvent(load_log, LoadLog::TYPE_SSL_CONNECT); | 530 net_log.EndEvent(NetLog::TYPE_SSL_CONNECT); |
531 return rv; | 531 return rv; |
532 } | 532 } |
533 | 533 |
534 next_handshake_state_ = STATE_HANDSHAKE_START; | 534 next_handshake_state_ = STATE_HANDSHAKE_START; |
535 rv = DoHandshakeLoop(OK); | 535 rv = DoHandshakeLoop(OK); |
536 if (rv == ERR_IO_PENDING) { | 536 if (rv == ERR_IO_PENDING) { |
537 load_log_ = load_log; | 537 net_log_ = net_log; |
538 user_connect_callback_ = callback; | 538 user_connect_callback_ = callback; |
539 } else { | 539 } else { |
540 LoadLog::EndEvent(load_log, LoadLog::TYPE_SSL_CONNECT); | 540 net_log.EndEvent(NetLog::TYPE_SSL_CONNECT); |
541 } | 541 } |
542 return rv; | 542 return rv; |
543 } | 543 } |
544 | 544 |
545 void SSLClientSocketMac::Disconnect() { | 545 void SSLClientSocketMac::Disconnect() { |
546 completed_handshake_ = false; | 546 completed_handshake_ = false; |
547 | 547 |
548 if (ssl_context_) { | 548 if (ssl_context_) { |
549 SSLClose(ssl_context_); | 549 SSLClose(ssl_context_); |
550 SSLDisposeContext(ssl_context_); | 550 SSLDisposeContext(ssl_context_); |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 user_write_callback_ = NULL; | 809 user_write_callback_ = NULL; |
810 user_write_buf_ = NULL; | 810 user_write_buf_ = NULL; |
811 user_write_buf_len_ = 0; | 811 user_write_buf_len_ = 0; |
812 c->Run(rv); | 812 c->Run(rv); |
813 } | 813 } |
814 | 814 |
815 void SSLClientSocketMac::OnHandshakeIOComplete(int result) { | 815 void SSLClientSocketMac::OnHandshakeIOComplete(int result) { |
816 DCHECK(next_handshake_state_ != STATE_NONE); | 816 DCHECK(next_handshake_state_ != STATE_NONE); |
817 int rv = DoHandshakeLoop(result); | 817 int rv = DoHandshakeLoop(result); |
818 if (rv != ERR_IO_PENDING) { | 818 if (rv != ERR_IO_PENDING) { |
819 LoadLog::EndEvent(load_log_, LoadLog::TYPE_SSL_CONNECT); | 819 net_log_.EndEvent(NetLog::TYPE_SSL_CONNECT); |
820 load_log_ = NULL; | 820 net_log_ = BoundNetLog(); |
821 DoConnectCallback(rv); | 821 DoConnectCallback(rv); |
822 } | 822 } |
823 } | 823 } |
824 | 824 |
825 void SSLClientSocketMac::OnTransportReadComplete(int result) { | 825 void SSLClientSocketMac::OnTransportReadComplete(int result) { |
826 if (result > 0) { | 826 if (result > 0) { |
827 recv_buffer_.insert(recv_buffer_.end(), | 827 recv_buffer_.insert(recv_buffer_.end(), |
828 read_io_buf_->data(), | 828 read_io_buf_->data(), |
829 read_io_buf_->data() + result); | 829 read_io_buf_->data() + result); |
830 } | 830 } |
831 read_io_buf_ = NULL; | 831 read_io_buf_ = NULL; |
832 | 832 |
833 if (next_handshake_state_ != STATE_NONE) { | 833 if (next_handshake_state_ != STATE_NONE) { |
834 int rv = DoHandshakeLoop(result); | 834 int rv = DoHandshakeLoop(result); |
835 if (rv != ERR_IO_PENDING) { | 835 if (rv != ERR_IO_PENDING) { |
836 LoadLog::EndEvent(load_log_, LoadLog::TYPE_SSL_CONNECT); | 836 net_log_.EndEvent(NetLog::TYPE_SSL_CONNECT); |
837 load_log_ = NULL; | 837 net_log_ = BoundNetLog(); |
838 DoConnectCallback(rv); | 838 DoConnectCallback(rv); |
839 } | 839 } |
840 return; | 840 return; |
841 } | 841 } |
842 if (user_read_buf_) { | 842 if (user_read_buf_) { |
843 if (result < 0) { | 843 if (result < 0) { |
844 DoReadCallback(result); | 844 DoReadCallback(result); |
845 return; | 845 return; |
846 } | 846 } |
847 int rv = DoPayloadRead(); | 847 int rv = DoPayloadRead(); |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1172 if (rv < 0 && rv != ERR_IO_PENDING) { | 1172 if (rv < 0 && rv != ERR_IO_PENDING) { |
1173 us->write_io_buf_ = NULL; | 1173 us->write_io_buf_ = NULL; |
1174 return OSStatusFromNetError(rv); | 1174 return OSStatusFromNetError(rv); |
1175 } | 1175 } |
1176 | 1176 |
1177 // always lie to our caller | 1177 // always lie to our caller |
1178 return noErr; | 1178 return noErr; |
1179 } | 1179 } |
1180 | 1180 |
1181 } // namespace net | 1181 } // namespace net |
OLD | NEW |