Update V8 to version 4.7.47.
[chromium-blink-merge.git] / net / socket / ssl_server_socket_nss.h
blobd1bcec690676bdf84324d5728830ec6a203198ad
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_
8 #include <certt.h>
9 #include <keyt.h>
10 #include <nspr.h>
11 #include <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/nss_memio.h"
17 #include "net/log/net_log.h"
18 #include "net/socket/ssl_server_socket.h"
19 #include "net/ssl/ssl_config_service.h"
21 namespace net {
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;
33 // SSLServerSocket interface.
34 int Handshake(const CompletionCallback& callback) override;
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;
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;
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 void GetConnectionAttempts(ConnectionAttempts* out) const override;
70 void ClearConnectionAttempts() override {}
71 void AddConnectionAttempts(const ConnectionAttempts& attempts) override {}
73 private:
74 enum State {
75 STATE_NONE,
76 STATE_HANDSHAKE,
79 int InitializeSSLOptions();
81 void OnSendComplete(int result);
82 void OnRecvComplete(int result);
83 void OnHandshakeIOComplete(int result);
85 int BufferSend();
86 void BufferSendComplete(int result);
87 int BufferRecv();
88 void BufferRecvComplete(int result);
89 bool DoTransportIO();
90 int DoPayloadRead();
91 int DoPayloadWrite();
93 int DoHandshakeLoop(int last_io_result);
94 int DoReadLoop(int result);
95 int DoWriteLoop(int result);
96 int DoHandshake();
97 void DoHandshakeCallback(int result);
98 void DoReadCallback(int result);
99 void DoWriteCallback(int result);
101 static SECStatus OwnAuthCertHandler(void* arg,
102 PRFileDesc* socket,
103 PRBool checksig,
104 PRBool is_server);
105 static void HandshakeCallback(PRFileDesc* socket, void* arg);
107 int Init();
109 // Members used to send and receive buffer.
110 bool transport_send_busy_;
111 bool transport_recv_busy_;
113 scoped_refptr<IOBuffer> recv_buffer_;
115 BoundNetLog net_log_;
117 CompletionCallback user_handshake_callback_;
118 CompletionCallback user_read_callback_;
119 CompletionCallback user_write_callback_;
121 // Used by Read function.
122 scoped_refptr<IOBuffer> user_read_buf_;
123 int user_read_buf_len_;
125 // Used by Write function.
126 scoped_refptr<IOBuffer> user_write_buf_;
127 int user_write_buf_len_;
129 // The NSS SSL state machine
130 PRFileDesc* nss_fd_;
132 // Buffers for the network end of the SSL state machine
133 memio_Private* nss_bufs_;
135 // StreamSocket for sending and receiving data.
136 scoped_ptr<StreamSocket> transport_socket_;
138 // Options for the SSL socket.
139 SSLConfig ssl_config_;
141 // Certificate for the server.
142 scoped_refptr<X509Certificate> cert_;
144 // Private key used by the server.
145 scoped_ptr<crypto::RSAPrivateKey> key_;
147 State next_handshake_state_;
148 bool completed_handshake_;
150 DISALLOW_COPY_AND_ASSIGN(SSLServerSocketNSS);
153 } // namespace net
155 #endif // NET_SOCKET_SSL_SERVER_SOCKET_NSS_H_