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.
5 #ifndef NET_SOCKET_SSL_SERVER_SOCKET_NSS_H_
6 #define NET_SOCKET_SSL_SERVER_SOCKET_NSS_H_
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"
23 class SSLServerSocketNSS
: public SSLServerSocket
{
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
;
33 // SSLServerSocket interface.
34 int Handshake(const CompletionCallback
& callback
) override
;
36 // SSLSocket interface.
37 int ExportKeyingMaterial(const base::StringPiece
& label
,
39 const base::StringPiece
& context
,
41 unsigned int outlen
) override
;
42 int GetTLSUniqueChannelBinding(std::string
* out
) override
;
44 // Socket interface (via StreamSocket).
45 int Read(IOBuffer
* buf
,
47 const CompletionCallback
& callback
) override
;
48 int Write(IOBuffer
* buf
,
50 const CompletionCallback
& callback
) override
;
51 int SetReceiveBufferSize(int32 size
) override
;
52 int SetSendBufferSize(int32 size
) override
;
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
;
76 int InitializeSSLOptions();
78 void OnSendComplete(int result
);
79 void OnRecvComplete(int result
);
80 void OnHandshakeIOComplete(int result
);
83 void BufferSendComplete(int result
);
85 void BufferRecvComplete(int result
);
90 int DoHandshakeLoop(int last_io_result
);
91 int DoReadLoop(int result
);
92 int DoWriteLoop(int result
);
94 void DoHandshakeCallback(int result
);
95 void DoReadCallback(int result
);
96 void DoWriteCallback(int result
);
98 static SECStatus
OwnAuthCertHandler(void* arg
,
102 static void HandshakeCallback(PRFileDesc
* socket
, void* arg
);
106 // Members used to send and receive buffer.
107 bool transport_send_busy_
;
108 bool transport_recv_busy_
;
110 scoped_refptr
<IOBuffer
> recv_buffer_
;
112 BoundNetLog net_log_
;
114 CompletionCallback user_handshake_callback_
;
115 CompletionCallback user_read_callback_
;
116 CompletionCallback user_write_callback_
;
118 // Used by Read function.
119 scoped_refptr
<IOBuffer
> user_read_buf_
;
120 int user_read_buf_len_
;
122 // Used by Write function.
123 scoped_refptr
<IOBuffer
> user_write_buf_
;
124 int user_write_buf_len_
;
126 // The NSS SSL state machine
129 // Buffers for the network end of the SSL state machine
130 memio_Private
* nss_bufs_
;
132 // StreamSocket for sending and receiving data.
133 scoped_ptr
<StreamSocket
> transport_socket_
;
135 // Options for the SSL socket.
136 SSLConfig ssl_config_
;
138 // Certificate for the server.
139 scoped_refptr
<X509Certificate
> cert_
;
141 // Private key used by the server.
142 scoped_ptr
<crypto::RSAPrivateKey
> key_
;
144 State next_handshake_state_
;
145 bool completed_handshake_
;
147 DISALLOW_COPY_AND_ASSIGN(SSLServerSocketNSS
);
152 #endif // NET_SOCKET_SSL_SERVER_SOCKET_NSS_H_