Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2010 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_SOCKET_SSL_CLIENT_SOCKET_OPENSSL_H_ | |
| 6 #define NET_SOCKET_SSL_CLIENT_SOCKET_OPENSSL_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include "base/scoped_ptr.h" | |
| 10 #include "net/base/completion_callback.h" | |
| 11 #include "net/base/io_buffer.h" | |
| 12 #include "net/base/ssl_config_service.h" | |
| 13 #include "net/socket/ssl_client_socket.h" | |
| 14 #include "net/socket/client_socket_handle.h" | |
| 15 | |
| 16 typedef struct bio_st BIO; | |
| 17 typedef struct ssl_ctx_st SSL_CTX; | |
| 18 typedef struct ssl_st SSL; | |
| 19 | |
| 20 namespace net { | |
| 21 | |
| 22 class SSLCertRequestInfo; | |
| 23 class SSLConfig; | |
| 24 class SSLInfo; | |
| 25 | |
| 26 // An SSL client socket implemented with OpenSSL. | |
| 27 class SSLClientSocketOpenSSL : public SSLClientSocket { | |
| 28 public: | |
| 29 // Takes ownership of the transport_socket, which may already be connected. | |
| 30 // The given hostname will be compared with the name(s) in the server's | |
| 31 // certificate during the SSL handshake. ssl_config specifies the SSL | |
| 32 // settings. | |
| 33 SSLClientSocketOpenSSL(ClientSocketHandle* transport_socket, | |
| 34 const std::string& hostname, | |
| 35 const SSLConfig& ssl_config); | |
| 36 ~SSLClientSocketOpenSSL(); | |
| 37 | |
| 38 // SSLClientSocket methods: | |
| 39 virtual void GetSSLInfo(SSLInfo* ssl_info); | |
| 40 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info); | |
| 41 virtual NextProtoStatus GetNextProto(std::string* proto); | |
| 42 | |
| 43 // ClientSocket methods: | |
| 44 virtual int Connect(CompletionCallback* callback); | |
| 45 virtual void Disconnect(); | |
| 46 virtual bool IsConnected() const; | |
| 47 virtual bool IsConnectedAndIdle() const; | |
| 48 virtual int GetPeerAddress(AddressList*) const; | |
| 49 virtual const BoundNetLog& NetLog() const; | |
| 50 virtual void SetSubresourceSpeculation(); | |
| 51 virtual void SetOmniboxSpeculation(); | |
| 52 virtual bool WasEverUsed() const; | |
| 53 | |
| 54 // Socket methods: | |
| 55 virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback); | |
| 56 virtual int Write(IOBuffer* buf, int buf_len, CompletionCallback* callback); | |
| 57 virtual bool SetReceiveBufferSize(int32 size); | |
| 58 virtual bool SetSendBufferSize(int32 size); | |
| 59 | |
| 60 private: | |
| 61 // Initializes OpenSSL SSL options. Returns a net error code. | |
| 62 bool InitializeSSLOptions(); | |
| 63 bool InitOpenSSL(); | |
|
wtc
2010/09/28 18:08:35
Please add a TODO comment to note that InitOpenSSL
joth
2010/09/29 11:58:54
Done.
| |
| 64 bool Init(); | |
| 65 void DoReadCallback(int result); | |
| 66 void DoWriteCallback(int result); | |
| 67 | |
| 68 bool DoTransportIO(); | |
| 69 int DoHandshake(); | |
| 70 void DoConnectCallback(int result); | |
| 71 | |
| 72 void OnHandshakeIOComplete(int result); | |
| 73 void OnSendComplete(int result); | |
| 74 void OnRecvComplete(int result); | |
| 75 | |
| 76 int DoHandshakeLoop(int last_io_result); | |
| 77 int DoReadLoop(int result); | |
| 78 int DoWriteLoop(int result); | |
| 79 int DoPayloadRead(); | |
| 80 int DoPayloadWrite(); | |
| 81 | |
| 82 int BufferSend(); | |
| 83 int BufferRecv(); | |
| 84 void BufferSendComplete(int result); | |
| 85 void BufferRecvComplete(int result); | |
| 86 void TransportWriteComplete(int result); | |
| 87 void TransportReadComplete(int result); | |
| 88 | |
| 89 CompletionCallbackImpl<SSLClientSocketOpenSSL> buffer_send_callback_; | |
| 90 CompletionCallbackImpl<SSLClientSocketOpenSSL> buffer_recv_callback_; | |
| 91 bool transport_send_busy_; | |
| 92 scoped_refptr<DrainableIOBuffer> send_buffer_; | |
| 93 bool transport_recv_busy_; | |
| 94 scoped_refptr<IOBuffer> recv_buffer_; | |
| 95 | |
| 96 CompletionCallback* user_connect_callback_; | |
| 97 CompletionCallback* user_read_callback_; | |
| 98 CompletionCallback* user_write_callback_; | |
| 99 | |
| 100 // Used by Read function. | |
| 101 scoped_refptr<IOBuffer> user_read_buf_; | |
| 102 int user_read_buf_len_; | |
| 103 | |
| 104 // Used by Write function. | |
| 105 scoped_refptr<IOBuffer> user_write_buf_; | |
| 106 int user_write_buf_len_; | |
| 107 | |
| 108 // Stores client authentication information between ClientAuthHandler and | |
| 109 // GetSSLCertRequestInfo calls. | |
| 110 std::vector<scoped_refptr<X509Certificate> > client_certs_; | |
| 111 bool client_auth_cert_needed_; | |
| 112 | |
| 113 // OpenSSL stuff | |
| 114 static SSL_CTX* g_ctx; | |
| 115 SSL* ssl_; | |
| 116 BIO* transport_bio_; | |
| 117 | |
| 118 scoped_ptr<ClientSocketHandle> transport_; | |
| 119 std::string hostname_; | |
| 120 SSLConfig ssl_config_; | |
| 121 | |
| 122 bool completed_handshake_; | |
| 123 | |
| 124 enum State { | |
| 125 STATE_NONE, | |
| 126 STATE_HANDSHAKE, | |
| 127 STATE_VERIFY_CERT, | |
| 128 STATE_VERIFY_CERT_COMPLETE, | |
| 129 }; | |
| 130 State next_handshake_state_; | |
| 131 BoundNetLog net_log_; | |
| 132 }; | |
| 133 | |
| 134 } // namespace net | |
| 135 | |
| 136 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_OPENSSL_H_ | |
| 137 | |
| OLD | NEW |