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

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

Issue 5746003: Defines SSLServerSocket and implements SSLServerSocketNSS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 10 years 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
(Empty)
1 // Copyright (c) 2006-2009 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 #pragma once
8
9 #include <certt.h>
10 #include <keyt.h>
11 #include <nspr.h>
12 #include <nss.h>
13
14 #include "base/scoped_ptr.h"
15 #include "net/base/completion_callback.h"
16 #include "net/base/host_port_pair.h"
17 #include "net/base/net_log.h"
18 #include "net/base/nss_memio.h"
19 #include "net/base/ssl_config_service.h"
20 #include "net/socket/ssl_server_socket.h"
21
22 namespace net {
23
24 class SSLServerSocketNSS : public SSLServerSocket {
25 public:
26 // This object takes ownership of the following parameters:
27 // |socket| - A socket that is already connected.
28 // |cert| - The certificate to be used by the server.
29 //
30 // The following parameter are copied in the constructor.
agl 2010/12/17 18:30:50 s/parameter/parameters/
Alpha Left Google 2010/12/17 20:31:12 Done.
31 // |ssl_config| - Options for SSL socket.
32 // |key| - The private key used by the server.
33 SSLServerSocketNSS(Socket* socket,
wtc 2010/12/17 18:08:04 Nit: socket => transport_socket
Alpha Left Google 2010/12/17 20:31:12 Done.
34 const SSLConfig& ssl_config,
35 scoped_refptr<X509Certificate> cert,
36 base::RSAPrivateKey* key);
37 virtual ~SSLServerSocketNSS() {}
38
39 // SSLServerSocket implementation.
40 virtual int Accept(CompletionCallback* callback);
41 virtual int Read(IOBuffer* buf, int buf_len,
42 CompletionCallback* callback);
43 virtual int Write(IOBuffer* buf, int buf_len,
44 CompletionCallback* callback);
45 virtual bool SetReceiveBufferSize(int32 size) { return false; }
46 virtual bool SetSendBufferSize(int32 size) { return false; }
47
48 private:
49 virtual int Init();
50
51 int InitializeSSLOptions();
52
53 void OnSendComplete(int result);
54 void OnRecvComplete(int result);
55 void OnHandshakeIOComplete(int result);
56
57 int BufferSend();
58 void BufferSendComplete(int result);
59 int BufferRecv();
60 void BufferRecvComplete(int result);
61 bool DoTransportIO();
62 int DoPayloadWrite();
63 int DoPayloadRead();
64
65 int DoHandshakeLoop(int last_io_result);
66 int DoReadLoop(int result);
67 int DoWriteLoop(int result);
68 int DoHandshake();
69 void DoAcceptCallback(int result);
70 void DoReadCallback(int result);
71 void DoWriteCallback(int result);
72
73 static SECStatus OwnAuthCertHandler(void* arg,
74 PRFileDesc* socket,
75 PRBool checksig,
76 PRBool is_server);
77 static void HandshakeCallback(PRFileDesc* socket, void* arg);
78
79 // Members used to send and receive buffer.
80 CompletionCallbackImpl<SSLServerSocketNSS> buffer_send_callback_;
81 CompletionCallbackImpl<SSLServerSocketNSS> buffer_recv_callback_;
82 bool transport_send_busy_;
83 bool transport_recv_busy_;
84
85 scoped_refptr<IOBuffer> recv_buffer_;
86
87 BoundNetLog net_log_;
88
89 CompletionCallback* user_accept_callback_;
90 CompletionCallback* user_read_callback_;
91 CompletionCallback* user_write_callback_;
92
93 // Used by Read function.
94 scoped_refptr<IOBuffer> user_read_buf_;
95 int user_read_buf_len_;
96
97 // Used by Write function.
98 scoped_refptr<IOBuffer> user_write_buf_;
99 int user_write_buf_len_;
100
101 // The NSS SSL state machine
102 PRFileDesc* nss_fd_;
103
104 // Buffers for the network end of the SSL state machine
105 memio_Private* nss_bufs_;
106
107 // Socket for sending and receiving data.
108 scoped_ptr<Socket> transport_socket_;
109
110 // Options for the SSL socket.
111 // TODO(hclam): This memeber is currently not used. Should make use of this
112 // member to configure the socket.
113 SSLConfig ssl_config_;
114
115 // Certificate for the server.
116 scoped_refptr<X509Certificate> cert_;
117
118 // Private key used by the server.
119 scoped_ptr<base::RSAPrivateKey> key_;
120
121 enum State {
122 STATE_NONE,
123 STATE_HANDSHAKE,
124 };
125 State next_handshake_state_;
126 bool completed_handshake_;
127
128 DISALLOW_COPY_AND_ASSIGN(SSLServerSocketNSS);
129 };
130
131 } // namespace net
132
133 #endif // NET_SOCKET_SSL_SERVER_SOCKET_NSS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698