| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-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 #ifndef NET_SOCKET_SSL_CLIENT_SOCKET_MAC_H_ | 5 #ifndef NET_SOCKET_SSL_CLIENT_SOCKET_MAC_H_ |
| 6 #define NET_SOCKET_SSL_CLIENT_SOCKET_MAC_H_ | 6 #define NET_SOCKET_SSL_CLIENT_SOCKET_MAC_H_ |
| 7 | 7 |
| 8 #include <Security/Security.h> | 8 #include <Security/Security.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
| 14 #include "net/base/cert_verify_result.h" |
| 14 #include "net/base/completion_callback.h" | 15 #include "net/base/completion_callback.h" |
| 15 #include "net/base/ssl_config_service.h" | 16 #include "net/base/ssl_config_service.h" |
| 16 #include "net/socket/ssl_client_socket.h" | 17 #include "net/socket/ssl_client_socket.h" |
| 17 | 18 |
| 18 namespace net { | 19 namespace net { |
| 19 | 20 |
| 21 class CertVerifier; |
| 22 |
| 20 // An SSL client socket implemented with Secure Transport. | 23 // An SSL client socket implemented with Secure Transport. |
| 21 class SSLClientSocketMac : public SSLClientSocket { | 24 class SSLClientSocketMac : public SSLClientSocket { |
| 22 public: | 25 public: |
| 23 // Takes ownership of the transport_socket, which may already be connected. | 26 // Takes ownership of the transport_socket, which may already be connected. |
| 24 // The given hostname will be compared with the name(s) in the server's | 27 // The given hostname will be compared with the name(s) in the server's |
| 25 // certificate during the SSL handshake. ssl_config specifies the SSL | 28 // certificate during the SSL handshake. ssl_config specifies the SSL |
| 26 // settings. | 29 // settings. |
| 27 SSLClientSocketMac(ClientSocket* transport_socket, | 30 SSLClientSocketMac(ClientSocket* transport_socket, |
| 28 const std::string& hostname, | 31 const std::string& hostname, |
| 29 const SSLConfig& ssl_config); | 32 const SSLConfig& ssl_config); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 44 virtual int Write(IOBuffer* buf, int buf_len, CompletionCallback* callback); | 47 virtual int Write(IOBuffer* buf, int buf_len, CompletionCallback* callback); |
| 45 | 48 |
| 46 private: | 49 private: |
| 47 void DoCallback(int result); | 50 void DoCallback(int result); |
| 48 void OnIOComplete(int result); | 51 void OnIOComplete(int result); |
| 49 | 52 |
| 50 int DoLoop(int last_io_result); | 53 int DoLoop(int last_io_result); |
| 51 int DoPayloadRead(); | 54 int DoPayloadRead(); |
| 52 int DoPayloadWrite(); | 55 int DoPayloadWrite(); |
| 53 int DoHandshake(); | 56 int DoHandshake(); |
| 57 int DoVerifyCert(); |
| 58 int DoVerifyCertComplete(int result); |
| 54 int DoReadComplete(int result); | 59 int DoReadComplete(int result); |
| 55 void OnWriteComplete(int result); | 60 void OnWriteComplete(int result); |
| 56 | 61 |
| 57 static OSStatus SSLReadCallback(SSLConnectionRef connection, | 62 static OSStatus SSLReadCallback(SSLConnectionRef connection, |
| 58 void* data, | 63 void* data, |
| 59 size_t* data_length); | 64 size_t* data_length); |
| 60 static OSStatus SSLWriteCallback(SSLConnectionRef connection, | 65 static OSStatus SSLWriteCallback(SSLConnectionRef connection, |
| 61 const void* data, | 66 const void* data, |
| 62 size_t* data_length); | 67 size_t* data_length); |
| 63 | 68 |
| 64 CompletionCallbackImpl<SSLClientSocketMac> io_callback_; | 69 CompletionCallbackImpl<SSLClientSocketMac> io_callback_; |
| 65 CompletionCallbackImpl<SSLClientSocketMac> write_callback_; | 70 CompletionCallbackImpl<SSLClientSocketMac> write_callback_; |
| 66 | 71 |
| 67 scoped_ptr<ClientSocket> transport_; | 72 scoped_ptr<ClientSocket> transport_; |
| 68 std::string hostname_; | 73 std::string hostname_; |
| 69 SSLConfig ssl_config_; | 74 SSLConfig ssl_config_; |
| 70 | 75 |
| 71 CompletionCallback* user_callback_; | 76 CompletionCallback* user_callback_; |
| 72 | 77 |
| 73 // Used by both Read and Write functions. | 78 // Used by both Read and Write functions. |
| 74 scoped_refptr<IOBuffer> user_buf_; | 79 scoped_refptr<IOBuffer> user_buf_; |
| 75 int user_buf_len_; | 80 int user_buf_len_; |
| 76 | 81 |
| 77 enum State { | 82 enum State { |
| 78 STATE_NONE, | 83 STATE_NONE, |
| 79 STATE_PAYLOAD_READ, | 84 STATE_PAYLOAD_READ, |
| 80 STATE_PAYLOAD_WRITE, | 85 STATE_PAYLOAD_WRITE, |
| 81 STATE_HANDSHAKE, | 86 STATE_HANDSHAKE, |
| 87 STATE_VERIFY_CERT, |
| 88 STATE_VERIFY_CERT_COMPLETE, |
| 82 STATE_READ_COMPLETE, | 89 STATE_READ_COMPLETE, |
| 83 }; | 90 }; |
| 84 State next_state_; | 91 State next_state_; |
| 85 State next_io_state_; | 92 State next_io_state_; |
| 86 | 93 |
| 87 // Set when handshake finishes. | |
| 88 scoped_refptr<X509Certificate> server_cert_; | 94 scoped_refptr<X509Certificate> server_cert_; |
| 89 int server_cert_status_; | 95 std::vector<scoped_refptr<X509Certificate> > intermediate_certs_; |
| 96 scoped_ptr<CertVerifier> verifier_; |
| 97 CertVerifyResult server_cert_verify_result_; |
| 90 | 98 |
| 91 bool completed_handshake_; | 99 bool completed_handshake_; |
| 92 SSLContextRef ssl_context_; | 100 SSLContextRef ssl_context_; |
| 93 | 101 |
| 94 // These are buffers for holding data during I/O. The "slop" is the amount of | 102 // These are buffers for holding data during I/O. The "slop" is the amount of |
| 95 // space at the ends of the receive buffer that are allocated for holding data | 103 // space at the ends of the receive buffer that are allocated for holding data |
| 96 // but don't (yet). | 104 // but don't (yet). |
| 97 std::vector<char> send_buffer_; | 105 std::vector<char> send_buffer_; |
| 98 int pending_send_error_; | 106 int pending_send_error_; |
| 99 std::vector<char> recv_buffer_; | 107 std::vector<char> recv_buffer_; |
| 100 int recv_buffer_head_slop_; | 108 int recv_buffer_head_slop_; |
| 101 int recv_buffer_tail_slop_; | 109 int recv_buffer_tail_slop_; |
| 102 | 110 |
| 103 // This buffer holds data for Read() operations on the underlying transport | 111 // This buffer holds data for Read() operations on the underlying transport |
| 104 // (ClientSocket::Read()). | 112 // (ClientSocket::Read()). |
| 105 scoped_refptr<IOBuffer> read_io_buf_; | 113 scoped_refptr<IOBuffer> read_io_buf_; |
| 106 }; | 114 }; |
| 107 | 115 |
| 108 } // namespace net | 116 } // namespace net |
| 109 | 117 |
| 110 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_MAC_H_ | 118 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_MAC_H_ |
| OLD | NEW |