Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_SERVER_SOCKET_NSS_H_ | 5 #ifndef NET_SOCKET_SSL_SERVER_SOCKET_NSS_H_ |
| 6 #define NET_SOCKET_SSL_SERVER_SOCKET_NSS_H_ | 6 #define NET_SOCKET_SSL_SERVER_SOCKET_NSS_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <certt.h> | 9 #include <certt.h> |
| 10 #include <keyt.h> | 10 #include <keyt.h> |
| 11 #include <nspr.h> | 11 #include <nspr.h> |
| 12 #include <nss.h> | 12 #include <nss.h> |
| 13 | 13 |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "net/base/completion_callback.h" | 15 #include "net/base/completion_callback.h" |
| 16 #include "net/base/host_port_pair.h" | 16 #include "net/base/host_port_pair.h" |
| 17 #include "net/base/net_log.h" | 17 #include "net/base/net_log.h" |
| 18 #include "net/base/nss_memio.h" | 18 #include "net/base/nss_memio.h" |
| 19 #include "net/base/ssl_config_service.h" | 19 #include "net/base/ssl_config_service.h" |
| 20 #include "net/socket/ssl_server_socket.h" | 20 #include "net/socket/ssl_server_socket.h" |
| 21 | 21 |
| 22 namespace net { | 22 namespace net { |
| 23 | 23 |
| 24 class SSLServerSocketNSS : public SSLServerSocket { | 24 class SSLServerSocketNSS : public StreamSocket { |
|
wtc
2011/06/02 23:12:58
Change this back to SSLServerSocket.
Wez
2011/06/03 17:47:07
Done.
| |
| 25 public: | 25 public: |
| 26 // This object takes ownership of the following parameters: | 26 // See comments on CreateSSLServerSocket for details of how these |
| 27 // |socket| - A socket that is already connected. | 27 // parameters are used. |
| 28 // |cert| - The certificate to be used by the server. | 28 SSLServerSocketNSS(StreamSocket* socket, |
| 29 // | 29 scoped_refptr<X509Certificate> certificate, |
| 30 // The following parameters are copied in the constructor. | |
| 31 // |ssl_config| - Options for SSL socket. | |
| 32 // |key| - The private key used by the server. | |
| 33 SSLServerSocketNSS(Socket* transport_socket, | |
| 34 scoped_refptr<X509Certificate> cert, | |
| 35 crypto::RSAPrivateKey* key, | 30 crypto::RSAPrivateKey* key, |
| 36 const SSLConfig& ssl_config); | 31 const SSLConfig& ssl_config); |
| 37 virtual ~SSLServerSocketNSS(); | 32 virtual ~SSLServerSocketNSS(); |
| 38 | 33 |
| 39 // SSLServerSocket implementation. | 34 // Socket interface (via StreamSocket). |
| 40 virtual int Accept(CompletionCallback* callback); | |
| 41 virtual int Read(IOBuffer* buf, int buf_len, | 35 virtual int Read(IOBuffer* buf, int buf_len, |
| 42 CompletionCallback* callback); | 36 CompletionCallback* callback); |
| 43 virtual int Write(IOBuffer* buf, int buf_len, | 37 virtual int Write(IOBuffer* buf, int buf_len, |
| 44 CompletionCallback* callback); | 38 CompletionCallback* callback); |
| 45 virtual bool SetReceiveBufferSize(int32 size); | 39 virtual bool SetReceiveBufferSize(int32 size); |
| 46 virtual bool SetSendBufferSize(int32 size); | 40 virtual bool SetSendBufferSize(int32 size); |
| 47 | 41 |
| 42 // StreamSocket interface. | |
| 43 virtual int Connect(CompletionCallback* callback); | |
| 44 virtual void Disconnect(); | |
| 45 virtual bool IsConnected() const; | |
| 46 virtual bool IsConnectedAndIdle() const; | |
| 47 | |
| 48 // StreamSocket calls passed straight to the underlying StreamSocket. | |
|
wtc
2011/06/02 23:12:58
I think this comment can be deleted, or be moved t
Wez
2011/06/03 17:47:07
Done.
| |
| 49 virtual int GetPeerAddress(AddressList* address) const; | |
| 50 virtual int GetLocalAddress(IPEndPoint* address) const; | |
| 51 virtual const BoundNetLog& NetLog() const; | |
| 52 virtual void SetSubresourceSpeculation(); | |
| 53 virtual void SetOmniboxSpeculation(); | |
| 54 virtual bool WasEverUsed() const; | |
| 55 virtual bool UsingTCPFastOpen() const; | |
| 56 | |
| 48 private: | 57 private: |
| 49 enum State { | 58 enum State { |
| 50 STATE_NONE, | 59 STATE_NONE, |
| 51 STATE_HANDSHAKE, | 60 STATE_HANDSHAKE, |
| 52 }; | 61 }; |
| 53 | 62 |
| 54 int InitializeSSLOptions(); | 63 int InitializeSSLOptions(); |
| 55 | 64 |
| 56 void OnSendComplete(int result); | 65 void OnSendComplete(int result); |
| 57 void OnRecvComplete(int result); | 66 void OnRecvComplete(int result); |
| 58 void OnHandshakeIOComplete(int result); | 67 void OnHandshakeIOComplete(int result); |
| 59 | 68 |
| 60 int BufferSend(); | 69 int BufferSend(); |
| 61 void BufferSendComplete(int result); | 70 void BufferSendComplete(int result); |
| 62 int BufferRecv(); | 71 int BufferRecv(); |
| 63 void BufferRecvComplete(int result); | 72 void BufferRecvComplete(int result); |
| 64 bool DoTransportIO(); | 73 bool DoTransportIO(); |
| 65 int DoPayloadRead(); | 74 int DoPayloadRead(); |
| 66 int DoPayloadWrite(); | 75 int DoPayloadWrite(); |
| 67 | 76 |
| 68 int DoHandshakeLoop(int last_io_result); | 77 int DoHandshakeLoop(int last_io_result); |
| 69 int DoReadLoop(int result); | 78 int DoReadLoop(int result); |
| 70 int DoWriteLoop(int result); | 79 int DoWriteLoop(int result); |
| 71 int DoHandshake(); | 80 int DoHandshake(); |
| 72 void DoAcceptCallback(int result); | 81 void DoConnectCallback(int result); |
| 73 void DoReadCallback(int result); | 82 void DoReadCallback(int result); |
| 74 void DoWriteCallback(int result); | 83 void DoWriteCallback(int result); |
| 75 | 84 |
| 76 static SECStatus OwnAuthCertHandler(void* arg, | 85 static SECStatus OwnAuthCertHandler(void* arg, |
| 77 PRFileDesc* socket, | 86 PRFileDesc* socket, |
| 78 PRBool checksig, | 87 PRBool checksig, |
| 79 PRBool is_server); | 88 PRBool is_server); |
| 80 static void HandshakeCallback(PRFileDesc* socket, void* arg); | 89 static void HandshakeCallback(PRFileDesc* socket, void* arg); |
| 81 | 90 |
| 82 virtual int Init(); | 91 virtual int Init(); |
| 83 | 92 |
| 84 // Members used to send and receive buffer. | 93 // Members used to send and receive buffer. |
| 85 CompletionCallbackImpl<SSLServerSocketNSS> buffer_send_callback_; | 94 CompletionCallbackImpl<SSLServerSocketNSS> buffer_send_callback_; |
| 86 CompletionCallbackImpl<SSLServerSocketNSS> buffer_recv_callback_; | 95 CompletionCallbackImpl<SSLServerSocketNSS> buffer_recv_callback_; |
| 87 bool transport_send_busy_; | 96 bool transport_send_busy_; |
| 88 bool transport_recv_busy_; | 97 bool transport_recv_busy_; |
| 89 | 98 |
| 90 scoped_refptr<IOBuffer> recv_buffer_; | 99 scoped_refptr<IOBuffer> recv_buffer_; |
| 91 | 100 |
| 92 BoundNetLog net_log_; | 101 BoundNetLog net_log_; |
| 93 | 102 |
| 94 CompletionCallback* user_accept_callback_; | 103 CompletionCallback* user_connect_callback_; |
| 95 CompletionCallback* user_read_callback_; | 104 CompletionCallback* user_read_callback_; |
| 96 CompletionCallback* user_write_callback_; | 105 CompletionCallback* user_write_callback_; |
| 97 | 106 |
| 98 // Used by Read function. | 107 // Used by Read function. |
| 99 scoped_refptr<IOBuffer> user_read_buf_; | 108 scoped_refptr<IOBuffer> user_read_buf_; |
| 100 int user_read_buf_len_; | 109 int user_read_buf_len_; |
| 101 | 110 |
| 102 // Used by Write function. | 111 // Used by Write function. |
| 103 scoped_refptr<IOBuffer> user_write_buf_; | 112 scoped_refptr<IOBuffer> user_write_buf_; |
| 104 int user_write_buf_len_; | 113 int user_write_buf_len_; |
| 105 | 114 |
| 106 // The NSS SSL state machine | 115 // The NSS SSL state machine |
| 107 PRFileDesc* nss_fd_; | 116 PRFileDesc* nss_fd_; |
| 108 | 117 |
| 109 // Buffers for the network end of the SSL state machine | 118 // Buffers for the network end of the SSL state machine |
| 110 memio_Private* nss_bufs_; | 119 memio_Private* nss_bufs_; |
| 111 | 120 |
| 112 // Socket for sending and receiving data. | 121 // StreamSocket for sending and receiving data. |
| 113 scoped_ptr<Socket> transport_socket_; | 122 scoped_ptr<StreamSocket> transport_socket_; |
| 114 | 123 |
| 115 // Options for the SSL socket. | 124 // Options for the SSL socket. |
| 116 // TODO(hclam): This memeber is currently not used. Should make use of this | |
| 117 // member to configure the socket. | |
| 118 SSLConfig ssl_config_; | 125 SSLConfig ssl_config_; |
| 119 | 126 |
| 120 // Certificate for the server. | 127 // Certificate for the server. |
| 121 scoped_refptr<X509Certificate> cert_; | 128 scoped_refptr<X509Certificate> cert_; |
| 122 | 129 |
| 123 // Private key used by the server. | 130 // Private key used by the server. |
| 124 scoped_ptr<crypto::RSAPrivateKey> key_; | 131 scoped_ptr<crypto::RSAPrivateKey> key_; |
| 125 | 132 |
| 126 State next_handshake_state_; | 133 State next_handshake_state_; |
| 127 bool completed_handshake_; | 134 bool completed_handshake_; |
| 128 | 135 |
| 129 DISALLOW_COPY_AND_ASSIGN(SSLServerSocketNSS); | 136 DISALLOW_COPY_AND_ASSIGN(SSLServerSocketNSS); |
| 130 }; | 137 }; |
| 131 | 138 |
| 132 } // namespace net | 139 } // namespace net |
| 133 | 140 |
| 134 #endif // NET_SOCKET_SSL_SERVER_SOCKET_NSS_H_ | 141 #endif // NET_SOCKET_SSL_SERVER_SOCKET_NSS_H_ |
| OLD | NEW |