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_WIN_H_ | 5 #ifndef NET_SOCKET_SSL_CLIENT_SOCKET_WIN_H_ |
6 #define NET_SOCKET_SSL_CLIENT_SOCKET_WIN_H_ | 6 #define NET_SOCKET_SSL_CLIENT_SOCKET_WIN_H_ |
7 | 7 |
8 #define SECURITY_WIN32 // Needs to be defined before including security.h | 8 #define SECURITY_WIN32 // Needs to be defined before including security.h |
9 | 9 |
10 #include <windows.h> | 10 #include <windows.h> |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 virtual bool IsConnectedAndIdle() const; | 46 virtual bool IsConnectedAndIdle() const; |
47 | 47 |
48 // Socket methods: | 48 // Socket methods: |
49 virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback); | 49 virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback); |
50 virtual int Write(IOBuffer* buf, int buf_len, CompletionCallback* callback); | 50 virtual int Write(IOBuffer* buf, int buf_len, CompletionCallback* callback); |
51 | 51 |
52 virtual bool SetReceiveBufferSize(int32 size); | 52 virtual bool SetReceiveBufferSize(int32 size); |
53 virtual bool SetSendBufferSize(int32 size); | 53 virtual bool SetSendBufferSize(int32 size); |
54 | 54 |
55 private: | 55 private: |
56 void DoCallback(int result); | 56 bool completed_handshake() const { |
57 void OnIOComplete(int result); | 57 return next_state_ == STATE_COMPLETED_HANDSHAKE; |
| 58 } |
| 59 |
| 60 void OnHandshakeIOComplete(int result); |
| 61 void OnReadComplete(int result); |
| 62 void OnWriteComplete(int result); |
58 | 63 |
59 int DoLoop(int last_io_result); | 64 int DoLoop(int last_io_result); |
60 int DoHandshakeRead(); | 65 int DoHandshakeRead(); |
61 int DoHandshakeReadComplete(int result); | 66 int DoHandshakeReadComplete(int result); |
62 int DoHandshakeWrite(); | 67 int DoHandshakeWrite(); |
63 int DoHandshakeWriteComplete(int result); | 68 int DoHandshakeWriteComplete(int result); |
64 int DoVerifyCert(); | 69 int DoVerifyCert(); |
65 int DoVerifyCertComplete(int result); | 70 int DoVerifyCertComplete(int result); |
| 71 |
66 int DoPayloadRead(); | 72 int DoPayloadRead(); |
67 int DoPayloadReadComplete(int result); | 73 int DoPayloadReadComplete(int result); |
| 74 int DoPayloadDecrypt(); |
68 int DoPayloadEncrypt(); | 75 int DoPayloadEncrypt(); |
69 int DoPayloadWrite(); | 76 int DoPayloadWrite(); |
70 int DoPayloadWriteComplete(int result); | 77 int DoPayloadWriteComplete(int result); |
| 78 int DoCompletedRenegotiation(int result); |
71 | 79 |
72 int DidCallInitializeSecurityContext(); | 80 int DidCallInitializeSecurityContext(); |
73 int DidCompleteHandshake(); | 81 int DidCompleteHandshake(); |
74 void DidCompleteRenegotiation(int result); | 82 void DidCompleteRenegotiation(); |
75 void LogConnectionTypeMetrics() const; | 83 void LogConnectionTypeMetrics() const; |
76 void SetNextStateForRead(); | |
77 void FreeSendBuffer(); | 84 void FreeSendBuffer(); |
78 | 85 |
79 CompletionCallbackImpl<SSLClientSocketWin> io_callback_; | 86 // Internal callbacks as async operations complete. |
| 87 CompletionCallbackImpl<SSLClientSocketWin> handshake_io_callback_; |
| 88 CompletionCallbackImpl<SSLClientSocketWin> read_callback_; |
| 89 CompletionCallbackImpl<SSLClientSocketWin> write_callback_; |
| 90 |
80 scoped_ptr<ClientSocket> transport_; | 91 scoped_ptr<ClientSocket> transport_; |
81 std::string hostname_; | 92 std::string hostname_; |
82 SSLConfig ssl_config_; | 93 SSLConfig ssl_config_; |
83 | 94 |
84 CompletionCallback* user_callback_; | 95 // User function to callback when the Connect() completes. |
| 96 CompletionCallback* user_connect_callback_; |
85 | 97 |
86 // Used by both Read and Write functions. | 98 // User function to callback when a Read() completes. |
87 scoped_refptr<IOBuffer> user_buf_; | 99 CompletionCallback* user_read_callback_; |
88 int user_buf_len_; | 100 scoped_refptr<IOBuffer> user_read_buf_; |
| 101 int user_read_buf_len_; |
| 102 |
| 103 // User function to callback when a Write() completes. |
| 104 CompletionCallback* user_write_callback_; |
| 105 scoped_refptr<IOBuffer> user_write_buf_; |
| 106 int user_write_buf_len_; |
89 | 107 |
90 // Used to Read and Write using transport_. | 108 // Used to Read and Write using transport_. |
91 scoped_refptr<IOBuffer> transport_buf_; | 109 scoped_refptr<IOBuffer> transport_read_buf_; |
| 110 scoped_refptr<IOBuffer> transport_write_buf_; |
92 | 111 |
93 enum State { | 112 enum State { |
94 STATE_NONE, | 113 STATE_NONE, |
95 STATE_HANDSHAKE_READ, | 114 STATE_HANDSHAKE_READ, |
96 STATE_HANDSHAKE_READ_COMPLETE, | 115 STATE_HANDSHAKE_READ_COMPLETE, |
97 STATE_HANDSHAKE_WRITE, | 116 STATE_HANDSHAKE_WRITE, |
98 STATE_HANDSHAKE_WRITE_COMPLETE, | 117 STATE_HANDSHAKE_WRITE_COMPLETE, |
99 STATE_VERIFY_CERT, | 118 STATE_VERIFY_CERT, |
100 STATE_VERIFY_CERT_COMPLETE, | 119 STATE_VERIFY_CERT_COMPLETE, |
101 STATE_PAYLOAD_ENCRYPT, | 120 STATE_COMPLETED_RENEGOTIATION, |
102 STATE_PAYLOAD_WRITE, | 121 STATE_COMPLETED_HANDSHAKE |
103 STATE_PAYLOAD_WRITE_COMPLETE, | 122 // After the handshake, the socket remains |
104 STATE_PAYLOAD_READ, | 123 // in the STATE_COMPLETED_HANDSHAKE state, |
105 STATE_PAYLOAD_READ_COMPLETE, | 124 // unless a renegotiate handshake occurs. |
106 }; | 125 }; |
107 State next_state_; | 126 State next_state_; |
108 | 127 |
109 SecPkgContext_StreamSizes stream_sizes_; | 128 SecPkgContext_StreamSizes stream_sizes_; |
110 scoped_refptr<X509Certificate> server_cert_; | 129 scoped_refptr<X509Certificate> server_cert_; |
111 scoped_ptr<CertVerifier> verifier_; | 130 scoped_ptr<CertVerifier> verifier_; |
112 CertVerifyResult server_cert_verify_result_; | 131 CertVerifyResult server_cert_verify_result_; |
113 | 132 |
114 CredHandle* creds_; | 133 CredHandle* creds_; |
115 CtxtHandle ctxt_; | 134 CtxtHandle ctxt_; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 // | 166 // |
148 // The reason we need this flag is that OK means not only "0 bytes of data | 167 // The reason we need this flag is that OK means not only "0 bytes of data |
149 // were read" but also EOF. We set ignore_ok_result_ to true when we need | 168 // were read" but also EOF. We set ignore_ok_result_ to true when we need |
150 // to continue processing previously read data without reading more data. | 169 // to continue processing previously read data without reading more data. |
151 // We have to pass a 'result' of OK to the DoLoop method, and don't want it | 170 // We have to pass a 'result' of OK to the DoLoop method, and don't want it |
152 // to be interpreted as EOF. | 171 // to be interpreted as EOF. |
153 bool ignore_ok_result_; | 172 bool ignore_ok_result_; |
154 | 173 |
155 // Renegotiation is in progress. | 174 // Renegotiation is in progress. |
156 bool renegotiating_; | 175 bool renegotiating_; |
| 176 |
| 177 // True when the decrypter needs more data in order to decrypt. |
| 178 bool need_more_data_; |
157 }; | 179 }; |
158 | 180 |
159 } // namespace net | 181 } // namespace net |
160 | 182 |
161 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_WIN_H_ | 183 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_WIN_H_ |
OLD | NEW |