| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef NET_BASE_SSL_CLIENT_SOCKET_MAC_H_ | |
| 6 #define NET_BASE_SSL_CLIENT_SOCKET_MAC_H_ | |
| 7 | |
| 8 #include <Security/Security.h> | |
| 9 | |
| 10 #include <string> | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "base/scoped_ptr.h" | |
| 14 #include "net/base/completion_callback.h" | |
| 15 #include "net/base/ssl_client_socket.h" | |
| 16 #include "net/base/ssl_config_service.h" | |
| 17 | |
| 18 namespace net { | |
| 19 | |
| 20 // An SSL client socket implemented with Secure Transport. | |
| 21 class SSLClientSocketMac : public SSLClientSocket { | |
| 22 public: | |
| 23 // 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 | |
| 25 // certificate during the SSL handshake. ssl_config specifies the SSL | |
| 26 // settings. | |
| 27 SSLClientSocketMac(ClientSocket* transport_socket, | |
| 28 const std::string& hostname, | |
| 29 const SSLConfig& ssl_config); | |
| 30 ~SSLClientSocketMac(); | |
| 31 | |
| 32 // SSLClientSocket methods: | |
| 33 virtual void GetSSLInfo(SSLInfo* ssl_info); | |
| 34 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info); | |
| 35 | |
| 36 // ClientSocket methods: | |
| 37 virtual int Connect(CompletionCallback* callback); | |
| 38 virtual void Disconnect(); | |
| 39 virtual bool IsConnected() const; | |
| 40 virtual bool IsConnectedAndIdle() const; | |
| 41 | |
| 42 // Socket methods: | |
| 43 virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback); | |
| 44 virtual int Write(IOBuffer* buf, int buf_len, CompletionCallback* callback); | |
| 45 | |
| 46 private: | |
| 47 void DoCallback(int result); | |
| 48 void OnIOComplete(int result); | |
| 49 | |
| 50 int DoLoop(int last_io_result); | |
| 51 int DoPayloadRead(); | |
| 52 int DoPayloadWrite(); | |
| 53 int DoHandshake(); | |
| 54 int DoReadComplete(int result); | |
| 55 void OnWriteComplete(int result); | |
| 56 | |
| 57 static OSStatus SSLReadCallback(SSLConnectionRef connection, | |
| 58 void* data, | |
| 59 size_t* data_length); | |
| 60 static OSStatus SSLWriteCallback(SSLConnectionRef connection, | |
| 61 const void* data, | |
| 62 size_t* data_length); | |
| 63 | |
| 64 CompletionCallbackImpl<SSLClientSocketMac> io_callback_; | |
| 65 CompletionCallbackImpl<SSLClientSocketMac> write_callback_; | |
| 66 | |
| 67 scoped_ptr<ClientSocket> transport_; | |
| 68 std::string hostname_; | |
| 69 SSLConfig ssl_config_; | |
| 70 | |
| 71 CompletionCallback* user_callback_; | |
| 72 | |
| 73 // Used by both Read and Write functions. | |
| 74 scoped_refptr<IOBuffer> user_buf_; | |
| 75 int user_buf_len_; | |
| 76 | |
| 77 enum State { | |
| 78 STATE_NONE, | |
| 79 STATE_PAYLOAD_READ, | |
| 80 STATE_PAYLOAD_WRITE, | |
| 81 STATE_HANDSHAKE, | |
| 82 STATE_READ_COMPLETE, | |
| 83 }; | |
| 84 State next_state_; | |
| 85 State next_io_state_; | |
| 86 | |
| 87 int server_cert_status_; | |
| 88 | |
| 89 bool completed_handshake_; | |
| 90 SSLContextRef ssl_context_; | |
| 91 | |
| 92 // These are buffers for holding data during I/O. The "slop" is the amount of | |
| 93 // space at the ends of the receive buffer that are allocated for holding data | |
| 94 // but don't (yet). | |
| 95 std::vector<char> send_buffer_; | |
| 96 int pending_send_error_; | |
| 97 std::vector<char> recv_buffer_; | |
| 98 int recv_buffer_head_slop_; | |
| 99 int recv_buffer_tail_slop_; | |
| 100 | |
| 101 // This buffer holds data for Read() operations on the underlying transport | |
| 102 // (ClientSocket::Read()). | |
| 103 scoped_refptr<IOBuffer> read_io_buf_; | |
| 104 }; | |
| 105 | |
| 106 } // namespace net | |
| 107 | |
| 108 #endif // NET_BASE_SSL_CLIENT_SOCKET_MAC_H_ | |
| OLD | NEW |