OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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_SERVER_SOCKET_NSS_H_ | |
6 #define NET_SOCKET_SSL_SERVER_SOCKET_NSS_H_ | |
7 | |
8 #include <certt.h> | |
9 #include <keyt.h> | |
10 #include <nspr.h> | |
11 #include <nss.h> | |
12 | |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "net/base/completion_callback.h" | |
15 #include "net/base/host_port_pair.h" | |
16 #include "net/base/net_log.h" | |
17 #include "net/base/nss_memio.h" | |
18 #include "net/socket/ssl_server_socket.h" | |
19 #include "net/ssl/ssl_config_service.h" | |
20 | |
21 namespace net { | |
22 | |
23 class SSLServerSocketNSS : public SSLServerSocket { | |
24 public: | |
25 // See comments on CreateSSLServerSocket for details of how these | |
26 // parameters are used. | |
27 SSLServerSocketNSS(scoped_ptr<StreamSocket> socket, | |
28 scoped_refptr<X509Certificate> certificate, | |
29 crypto::RSAPrivateKey* key, | |
30 const SSLConfig& ssl_config); | |
31 ~SSLServerSocketNSS() override; | |
32 | |
33 // SSLServerSocket interface. | |
34 int Handshake(const CompletionCallback& callback) override; | |
35 | |
36 // SSLSocket interface. | |
37 int ExportKeyingMaterial(const base::StringPiece& label, | |
38 bool has_context, | |
39 const base::StringPiece& context, | |
40 unsigned char* out, | |
41 unsigned int outlen) override; | |
42 int GetTLSUniqueChannelBinding(std::string* out) override; | |
43 | |
44 // Socket interface (via StreamSocket). | |
45 int Read(IOBuffer* buf, | |
46 int buf_len, | |
47 const CompletionCallback& callback) override; | |
48 int Write(IOBuffer* buf, | |
49 int buf_len, | |
50 const CompletionCallback& callback) override; | |
51 int SetReceiveBufferSize(int32 size) override; | |
52 int SetSendBufferSize(int32 size) override; | |
53 | |
54 // StreamSocket implementation. | |
55 int Connect(const CompletionCallback& callback) override; | |
56 void Disconnect() override; | |
57 bool IsConnected() const override; | |
58 bool IsConnectedAndIdle() const override; | |
59 int GetPeerAddress(IPEndPoint* address) const override; | |
60 int GetLocalAddress(IPEndPoint* address) const override; | |
61 const BoundNetLog& NetLog() const override; | |
62 void SetSubresourceSpeculation() override; | |
63 void SetOmniboxSpeculation() override; | |
64 bool WasEverUsed() const override; | |
65 bool UsingTCPFastOpen() const override; | |
66 bool WasNpnNegotiated() const override; | |
67 NextProto GetNegotiatedProtocol() const override; | |
68 bool GetSSLInfo(SSLInfo* ssl_info) override; | |
69 | |
70 private: | |
71 enum State { | |
72 STATE_NONE, | |
73 STATE_HANDSHAKE, | |
74 }; | |
75 | |
76 int InitializeSSLOptions(); | |
77 | |
78 void OnSendComplete(int result); | |
79 void OnRecvComplete(int result); | |
80 void OnHandshakeIOComplete(int result); | |
81 | |
82 int BufferSend(); | |
83 void BufferSendComplete(int result); | |
84 int BufferRecv(); | |
85 void BufferRecvComplete(int result); | |
86 bool DoTransportIO(); | |
87 int DoPayloadRead(); | |
88 int DoPayloadWrite(); | |
89 | |
90 int DoHandshakeLoop(int last_io_result); | |
91 int DoReadLoop(int result); | |
92 int DoWriteLoop(int result); | |
93 int DoHandshake(); | |
94 void DoHandshakeCallback(int result); | |
95 void DoReadCallback(int result); | |
96 void DoWriteCallback(int result); | |
97 | |
98 static SECStatus OwnAuthCertHandler(void* arg, | |
99 PRFileDesc* socket, | |
100 PRBool checksig, | |
101 PRBool is_server); | |
102 static void HandshakeCallback(PRFileDesc* socket, void* arg); | |
103 | |
104 int Init(); | |
105 | |
106 // Members used to send and receive buffer. | |
107 bool transport_send_busy_; | |
108 bool transport_recv_busy_; | |
109 | |
110 scoped_refptr<IOBuffer> recv_buffer_; | |
111 | |
112 BoundNetLog net_log_; | |
113 | |
114 CompletionCallback user_handshake_callback_; | |
115 CompletionCallback user_read_callback_; | |
116 CompletionCallback user_write_callback_; | |
117 | |
118 // Used by Read function. | |
119 scoped_refptr<IOBuffer> user_read_buf_; | |
120 int user_read_buf_len_; | |
121 | |
122 // Used by Write function. | |
123 scoped_refptr<IOBuffer> user_write_buf_; | |
124 int user_write_buf_len_; | |
125 | |
126 // The NSS SSL state machine | |
127 PRFileDesc* nss_fd_; | |
128 | |
129 // Buffers for the network end of the SSL state machine | |
130 memio_Private* nss_bufs_; | |
131 | |
132 // StreamSocket for sending and receiving data. | |
133 scoped_ptr<StreamSocket> transport_socket_; | |
134 | |
135 // Options for the SSL socket. | |
136 SSLConfig ssl_config_; | |
137 | |
138 // Certificate for the server. | |
139 scoped_refptr<X509Certificate> cert_; | |
140 | |
141 // Private key used by the server. | |
142 scoped_ptr<crypto::RSAPrivateKey> key_; | |
143 | |
144 State next_handshake_state_; | |
145 bool completed_handshake_; | |
146 | |
147 DISALLOW_COPY_AND_ASSIGN(SSLServerSocketNSS); | |
148 }; | |
149 | |
150 } // namespace net | |
151 | |
152 #endif // NET_SOCKET_SSL_SERVER_SOCKET_NSS_H_ | |
OLD | NEW |