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 SSLServerSocket { |
| 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 virtual int GetPeerAddress(AddressList* address) const; | |
| 48 virtual int GetLocalAddress(IPEndPoint* address) const; | |
| 49 virtual const BoundNetLog& NetLog() const; | |
| 50 virtual void SetSubresourceSpeculation(); | |
| 51 virtual void SetOmniboxSpeculation(); | |
| 52 virtual bool WasEverUsed() const; | |
| 53 virtual bool UsingTCPFastOpen() const; | |
| 54 | |
| 48 private: | 55 private: |
| 49 enum State { | 56 enum State { |
| 50 STATE_NONE, | 57 STATE_NONE, |
| 51 STATE_HANDSHAKE, | 58 STATE_HANDSHAKE, |
| 52 }; | 59 }; |
| 53 | 60 |
| 54 int InitializeSSLOptions(); | 61 int InitializeSSLOptions(); |
| 55 | 62 |
| 56 void OnSendComplete(int result); | 63 void OnSendComplete(int result); |
| 57 void OnRecvComplete(int result); | 64 void OnRecvComplete(int result); |
| 58 void OnHandshakeIOComplete(int result); | 65 void OnHandshakeIOComplete(int result); |
| 59 | 66 |
| 60 int BufferSend(); | 67 int BufferSend(); |
| 61 void BufferSendComplete(int result); | 68 void BufferSendComplete(int result); |
| 62 int BufferRecv(); | 69 int BufferRecv(); |
| 63 void BufferRecvComplete(int result); | 70 void BufferRecvComplete(int result); |
| 64 bool DoTransportIO(); | 71 bool DoTransportIO(); |
| 65 int DoPayloadRead(); | 72 int DoPayloadRead(); |
| 66 int DoPayloadWrite(); | 73 int DoPayloadWrite(); |
| 67 | 74 |
| 68 int DoHandshakeLoop(int last_io_result); | 75 int DoHandshakeLoop(int last_io_result); |
| 69 int DoReadLoop(int result); | 76 int DoReadLoop(int result); |
| 70 int DoWriteLoop(int result); | 77 int DoWriteLoop(int result); |
| 71 int DoHandshake(); | 78 int DoHandshake(); |
| 72 void DoAcceptCallback(int result); | 79 void DoConnectCallback(int result); |
| 73 void DoReadCallback(int result); | 80 void DoReadCallback(int result); |
| 74 void DoWriteCallback(int result); | 81 void DoWriteCallback(int result); |
| 75 | 82 |
| 76 static SECStatus OwnAuthCertHandler(void* arg, | 83 static SECStatus OwnAuthCertHandler(void* arg, |
| 77 PRFileDesc* socket, | 84 PRFileDesc* socket, |
| 78 PRBool checksig, | 85 PRBool checksig, |
| 79 PRBool is_server); | 86 PRBool is_server); |
| 80 static void HandshakeCallback(PRFileDesc* socket, void* arg); | 87 static void HandshakeCallback(PRFileDesc* socket, void* arg); |
| 81 | 88 |
| 82 virtual int Init(); | 89 virtual int Init(); |
| 83 | 90 |
| 84 // Members used to send and receive buffer. | 91 // Members used to send and receive buffer. |
| 85 CompletionCallbackImpl<SSLServerSocketNSS> buffer_send_callback_; | 92 CompletionCallbackImpl<SSLServerSocketNSS> buffer_send_callback_; |
| 86 CompletionCallbackImpl<SSLServerSocketNSS> buffer_recv_callback_; | 93 CompletionCallbackImpl<SSLServerSocketNSS> buffer_recv_callback_; |
| 87 bool transport_send_busy_; | 94 bool transport_send_busy_; |
| 88 bool transport_recv_busy_; | 95 bool transport_recv_busy_; |
| 89 | 96 |
| 90 scoped_refptr<IOBuffer> recv_buffer_; | 97 scoped_refptr<IOBuffer> recv_buffer_; |
| 91 | 98 |
| 92 BoundNetLog net_log_; | 99 BoundNetLog net_log_; |
| 93 | 100 |
| 94 CompletionCallback* user_accept_callback_; | 101 CompletionCallback* user_connect_callback_; |
| 95 CompletionCallback* user_read_callback_; | 102 CompletionCallback* user_read_callback_; |
| 96 CompletionCallback* user_write_callback_; | 103 CompletionCallback* user_write_callback_; |
| 97 | 104 |
| 98 // Used by Read function. | 105 // Used by Read function. |
| 99 scoped_refptr<IOBuffer> user_read_buf_; | 106 scoped_refptr<IOBuffer> user_read_buf_; |
| 100 int user_read_buf_len_; | 107 int user_read_buf_len_; |
| 101 | 108 |
| 102 // Used by Write function. | 109 // Used by Write function. |
| 103 scoped_refptr<IOBuffer> user_write_buf_; | 110 scoped_refptr<IOBuffer> user_write_buf_; |
| 104 int user_write_buf_len_; | 111 int user_write_buf_len_; |
| 105 | 112 |
| 106 // The NSS SSL state machine | 113 // The NSS SSL state machine |
| 107 PRFileDesc* nss_fd_; | 114 PRFileDesc* nss_fd_; |
| 108 | 115 |
| 109 // Buffers for the network end of the SSL state machine | 116 // Buffers for the network end of the SSL state machine |
| 110 memio_Private* nss_bufs_; | 117 memio_Private* nss_bufs_; |
| 111 | 118 |
| 112 // Socket for sending and receiving data. | 119 // StreamSocket for sending and receiving data. |
| 113 scoped_ptr<Socket> transport_socket_; | 120 scoped_ptr<StreamSocket> transport_socket_; |
|
Mike Belshe
2011/06/03 18:34:59
Is this a SSLServerSocket or a StreamSocket? I re
Wez
2011/06/07 00:25:28
This is the underlying StreamSocket, over which SS
| |
| 114 | 121 |
| 115 // Options for the SSL socket. | 122 // 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_; | 123 SSLConfig ssl_config_; |
| 119 | 124 |
| 120 // Certificate for the server. | 125 // Certificate for the server. |
| 121 scoped_refptr<X509Certificate> cert_; | 126 scoped_refptr<X509Certificate> cert_; |
| 122 | 127 |
| 123 // Private key used by the server. | 128 // Private key used by the server. |
| 124 scoped_ptr<crypto::RSAPrivateKey> key_; | 129 scoped_ptr<crypto::RSAPrivateKey> key_; |
| 125 | 130 |
| 126 State next_handshake_state_; | 131 State next_handshake_state_; |
| 127 bool completed_handshake_; | 132 bool completed_handshake_; |
| 128 | 133 |
| 129 DISALLOW_COPY_AND_ASSIGN(SSLServerSocketNSS); | 134 DISALLOW_COPY_AND_ASSIGN(SSLServerSocketNSS); |
| 130 }; | 135 }; |
| 131 | 136 |
| 132 } // namespace net | 137 } // namespace net |
| 133 | 138 |
| 134 #endif // NET_SOCKET_SSL_SERVER_SOCKET_NSS_H_ | 139 #endif // NET_SOCKET_SSL_SERVER_SOCKET_NSS_H_ |
| OLD | NEW |