Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 base { | |
| 23 class RSAPrivateKey; | |
| 24 } // namespace base | |
| 25 | |
| 26 namespace net { | |
| 27 | |
| 28 class IOBuffer; | |
| 29 class X509Certificate; | |
|
wtc
2010/12/17 00:16:26
I believe most of the header inclusions and forwar
Alpha Left Google
2010/12/17 08:30:43
Done.
| |
| 30 | |
| 31 class SSLServerSocketNSS : public SSLServerSocket { | |
| 32 public: | |
| 33 // This object takes ownership of the parameters given in the constructor. | |
|
wtc
2010/12/17 00:16:26
This is not true for |key|; this object copies |ke
Alpha Left Google
2010/12/17 08:30:43
Done.
| |
| 34 // |socket| is already connected. | |
| 35 // |cert| is the certificate to be used by the server. | |
| 36 // |key| is the private key used by the server. | |
| 37 SSLServerSocketNSS(Socket* socket, | |
|
wtc
2010/12/17 00:16:26
The constructor should take a "const SSLConfig& ss
Alpha Left Google
2010/12/17 08:30:43
Done.
| |
| 38 scoped_refptr<X509Certificate> cert, | |
| 39 base::RSAPrivateKey* key); | |
| 40 virtual ~SSLServerSocketNSS() {} | |
| 41 | |
| 42 // SSLServerSocket implementation. | |
| 43 virtual int Accept(CompletionCallback* callback); | |
| 44 virtual int Read(IOBuffer* buf, int buf_len, | |
| 45 CompletionCallback* callback); | |
| 46 virtual int Write(IOBuffer* buf, int buf_len, | |
| 47 CompletionCallback* callback); | |
| 48 virtual bool SetReceiveBufferSize(int32 size) { return false; } | |
| 49 virtual bool SetSendBufferSize(int32 size) { return false; } | |
| 50 | |
| 51 private: | |
| 52 virtual int Init(); | |
| 53 | |
| 54 int InitializeSSLOptions(); | |
| 55 | |
| 56 void OnSendComplete(int result); | |
| 57 void OnRecvComplete(int result); | |
| 58 void OnHandshakeIOComplete(int result); | |
| 59 | |
| 60 int BufferSend(); | |
| 61 void BufferSendComplete(int result); | |
| 62 int BufferRecv(); | |
| 63 void BufferRecvComplete(int result); | |
| 64 bool DoTransportIO(); | |
| 65 int DoPayloadWrite(); | |
| 66 int DoPayloadRead(); | |
| 67 | |
| 68 int DoHandshakeLoop(int last_io_result); | |
| 69 int DoReadLoop(int result); | |
| 70 int DoWriteLoop(int result); | |
| 71 int DoHandshake(); | |
| 72 void DoAcceptCallback(int result); | |
| 73 void DoReadCallback(int result); | |
| 74 void DoWriteCallback(int result); | |
| 75 | |
| 76 static SECStatus OwnAuthCertHandler(void* arg, | |
|
wtc
2010/12/17 00:16:26
OwnAuthCertHandler is needed only if your server w
Alpha Left Google
2010/12/17 08:30:43
Leaving this as a TODO in .cc because in the futur
| |
| 77 PRFileDesc* socket, | |
| 78 PRBool checksig, | |
| 79 PRBool is_server); | |
| 80 static SECStatus PlatformClientAuthHandler( | |
|
wtc
2010/12/17 00:16:26
Remove PlatformClientAuthHandler and ClientAuthHan
Alpha Left Google
2010/12/17 08:30:43
Done.
| |
| 81 void* arg, | |
| 82 PRFileDesc* socket, | |
| 83 CERTDistNames* ca_names, | |
| 84 CERTCertList** result_certs, | |
| 85 void** result_private_key); | |
| 86 static SECStatus ClientAuthHandler( | |
| 87 void* arg, | |
| 88 PRFileDesc* socket, | |
| 89 CERTDistNames* ca_names, | |
| 90 CERTCertificate** result_certificate, | |
| 91 SECKEYPrivateKey** result_private_key); | |
| 92 static void HandshakeCallback(PRFileDesc* socket, void* arg); | |
| 93 | |
| 94 // Members used to send and receive buffer. | |
| 95 CompletionCallbackImpl<SSLServerSocketNSS> buffer_send_callback_; | |
| 96 CompletionCallbackImpl<SSLServerSocketNSS> buffer_recv_callback_; | |
| 97 bool transport_send_busy_; | |
| 98 bool transport_recv_busy_; | |
| 99 | |
| 100 scoped_refptr<IOBuffer> recv_buffer_; | |
| 101 | |
| 102 BoundNetLog net_log_; | |
| 103 | |
| 104 // Configuration for the SSL server. | |
| 105 SSLConfig ssl_config_; | |
| 106 | |
| 107 CompletionCallback* user_accept_callback_; | |
| 108 CompletionCallback* user_read_callback_; | |
| 109 CompletionCallback* user_write_callback_; | |
| 110 | |
| 111 // Used by Read function. | |
| 112 scoped_refptr<IOBuffer> user_read_buf_; | |
| 113 int user_read_buf_len_; | |
| 114 | |
| 115 // Used by Write function. | |
| 116 scoped_refptr<IOBuffer> user_write_buf_; | |
| 117 int user_write_buf_len_; | |
| 118 | |
| 119 // The NSS SSL state machine | |
| 120 PRFileDesc* nss_fd_; | |
| 121 | |
| 122 // Buffers for the network end of the SSL state machine | |
| 123 memio_Private* nss_bufs_; | |
| 124 | |
| 125 // Socket for sending and receiving data. | |
| 126 scoped_ptr<Socket> socket_; | |
|
wtc
2010/12/17 00:16:26
Please name this member transport_ or transport_so
Alpha Left Google
2010/12/17 08:30:43
Done.
| |
| 127 | |
| 128 // Certificate for the server. | |
| 129 scoped_refptr<X509Certificate> cert_; | |
| 130 | |
| 131 // Private key used by the server for encryption. | |
|
wtc
2010/12/17 00:16:26
Nit: delete "for encryption". (It's used for key
Alpha Left Google
2010/12/17 08:30:43
Done.
| |
| 132 scoped_ptr<base::RSAPrivateKey> key_; | |
| 133 | |
| 134 enum State { | |
|
wtc
2010/12/17 00:16:26
If there is only one state, I wonder if we still n
Alpha Left Google
2010/12/17 08:30:43
Trying to keep this similar to the client code, ma
| |
| 135 STATE_NONE, | |
| 136 STATE_HANDSHAKE, | |
| 137 }; | |
| 138 State next_handshake_state_; | |
| 139 bool completed_handshake_; | |
| 140 | |
| 141 DISALLOW_COPY_AND_ASSIGN(SSLServerSocketNSS); | |
| 142 }; | |
| 143 | |
| 144 } // namespace net | |
| 145 | |
| 146 #endif // NET_SOCKET_SSL_SERVER_SOCKET_NSS_H_ | |
| OLD | NEW |