Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(301)

Side by Side Diff: net/socket/ssl_server_socket_nss.h

Issue 7054010: Update SSLServerSocket to provide the net::StreamSocket interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix net_unittests and rename things consistently to "handshake". Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 // SSLServerSocket interface.
40 virtual int Accept(CompletionCallback* callback); 35 virtual int Handshake(CompletionCallback* callback);
36
37 // Socket interface (via StreamSocket).
41 virtual int Read(IOBuffer* buf, int buf_len, 38 virtual int Read(IOBuffer* buf, int buf_len,
42 CompletionCallback* callback); 39 CompletionCallback* callback);
43 virtual int Write(IOBuffer* buf, int buf_len, 40 virtual int Write(IOBuffer* buf, int buf_len,
44 CompletionCallback* callback); 41 CompletionCallback* callback);
45 virtual bool SetReceiveBufferSize(int32 size); 42 virtual bool SetReceiveBufferSize(int32 size);
46 virtual bool SetSendBufferSize(int32 size); 43 virtual bool SetSendBufferSize(int32 size);
47 44
45 // StreamSocket interface.
46 virtual int Connect(CompletionCallback* callback);
47 virtual void Disconnect();
48 virtual bool IsConnected() const;
49 virtual bool IsConnectedAndIdle() const;
50 virtual int GetPeerAddress(AddressList* address) const;
51 virtual int GetLocalAddress(IPEndPoint* address) const;
52 virtual const BoundNetLog& NetLog() const;
53 virtual void SetSubresourceSpeculation();
54 virtual void SetOmniboxSpeculation();
55 virtual bool WasEverUsed() const;
56 virtual bool UsingTCPFastOpen() const;
57
48 private: 58 private:
49 enum State { 59 enum State {
50 STATE_NONE, 60 STATE_NONE,
51 STATE_HANDSHAKE, 61 STATE_HANDSHAKE,
52 }; 62 };
53 63
54 int InitializeSSLOptions(); 64 int InitializeSSLOptions();
55 65
56 void OnSendComplete(int result); 66 void OnSendComplete(int result);
57 void OnRecvComplete(int result); 67 void OnRecvComplete(int result);
58 void OnHandshakeIOComplete(int result); 68 void OnHandshakeIOComplete(int result);
59 69
60 int BufferSend(); 70 int BufferSend();
61 void BufferSendComplete(int result); 71 void BufferSendComplete(int result);
62 int BufferRecv(); 72 int BufferRecv();
63 void BufferRecvComplete(int result); 73 void BufferRecvComplete(int result);
64 bool DoTransportIO(); 74 bool DoTransportIO();
65 int DoPayloadRead(); 75 int DoPayloadRead();
66 int DoPayloadWrite(); 76 int DoPayloadWrite();
67 77
68 int DoHandshakeLoop(int last_io_result); 78 int DoHandshakeLoop(int last_io_result);
69 int DoReadLoop(int result); 79 int DoReadLoop(int result);
70 int DoWriteLoop(int result); 80 int DoWriteLoop(int result);
71 int DoHandshake(); 81 int DoHandshake();
72 void DoAcceptCallback(int result); 82 void DoHandshakeCallback(int result);
73 void DoReadCallback(int result); 83 void DoReadCallback(int result);
74 void DoWriteCallback(int result); 84 void DoWriteCallback(int result);
75 85
76 static SECStatus OwnAuthCertHandler(void* arg, 86 static SECStatus OwnAuthCertHandler(void* arg,
77 PRFileDesc* socket, 87 PRFileDesc* socket,
78 PRBool checksig, 88 PRBool checksig,
79 PRBool is_server); 89 PRBool is_server);
80 static void HandshakeCallback(PRFileDesc* socket, void* arg); 90 static void HandshakeCallback(PRFileDesc* socket, void* arg);
81 91
82 virtual int Init(); 92 virtual int Init();
83 93
84 // Members used to send and receive buffer. 94 // Members used to send and receive buffer.
85 CompletionCallbackImpl<SSLServerSocketNSS> buffer_send_callback_; 95 CompletionCallbackImpl<SSLServerSocketNSS> buffer_send_callback_;
86 CompletionCallbackImpl<SSLServerSocketNSS> buffer_recv_callback_; 96 CompletionCallbackImpl<SSLServerSocketNSS> buffer_recv_callback_;
87 bool transport_send_busy_; 97 bool transport_send_busy_;
88 bool transport_recv_busy_; 98 bool transport_recv_busy_;
89 99
90 scoped_refptr<IOBuffer> recv_buffer_; 100 scoped_refptr<IOBuffer> recv_buffer_;
91 101
92 BoundNetLog net_log_; 102 BoundNetLog net_log_;
93 103
94 CompletionCallback* user_accept_callback_; 104 CompletionCallback* user_handshake_callback_;
95 CompletionCallback* user_read_callback_; 105 CompletionCallback* user_read_callback_;
96 CompletionCallback* user_write_callback_; 106 CompletionCallback* user_write_callback_;
97 107
98 // Used by Read function. 108 // Used by Read function.
99 scoped_refptr<IOBuffer> user_read_buf_; 109 scoped_refptr<IOBuffer> user_read_buf_;
100 int user_read_buf_len_; 110 int user_read_buf_len_;
101 111
102 // Used by Write function. 112 // Used by Write function.
103 scoped_refptr<IOBuffer> user_write_buf_; 113 scoped_refptr<IOBuffer> user_write_buf_;
104 int user_write_buf_len_; 114 int user_write_buf_len_;
105 115
106 // The NSS SSL state machine 116 // The NSS SSL state machine
107 PRFileDesc* nss_fd_; 117 PRFileDesc* nss_fd_;
108 118
109 // Buffers for the network end of the SSL state machine 119 // Buffers for the network end of the SSL state machine
110 memio_Private* nss_bufs_; 120 memio_Private* nss_bufs_;
111 121
112 // Socket for sending and receiving data. 122 // StreamSocket for sending and receiving data.
113 scoped_ptr<Socket> transport_socket_; 123 scoped_ptr<StreamSocket> transport_socket_;
114 124
115 // Options for the SSL socket. 125 // 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_; 126 SSLConfig ssl_config_;
119 127
120 // Certificate for the server. 128 // Certificate for the server.
121 scoped_refptr<X509Certificate> cert_; 129 scoped_refptr<X509Certificate> cert_;
122 130
123 // Private key used by the server. 131 // Private key used by the server.
124 scoped_ptr<crypto::RSAPrivateKey> key_; 132 scoped_ptr<crypto::RSAPrivateKey> key_;
125 133
126 State next_handshake_state_; 134 State next_handshake_state_;
127 bool completed_handshake_; 135 bool completed_handshake_;
128 136
129 DISALLOW_COPY_AND_ASSIGN(SSLServerSocketNSS); 137 DISALLOW_COPY_AND_ASSIGN(SSLServerSocketNSS);
130 }; 138 };
131 139
132 } // namespace net 140 } // namespace net
133 141
134 #endif // NET_SOCKET_SSL_SERVER_SOCKET_NSS_H_ 142 #endif // NET_SOCKET_SSL_SERVER_SOCKET_NSS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698