| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_SOCKET_SSL_SERVER_SOCKET_NSS_H_ | 5 #ifndef NET_SOCKET_SSL_SERVER_SOCKET_OPENSSL_H_ |
| 6 #define NET_SOCKET_SSL_SERVER_SOCKET_NSS_H_ | 6 #define NET_SOCKET_SSL_SERVER_SOCKET_OPENSSL_H_ |
| 7 | |
| 8 #include <certt.h> | |
| 9 #include <keyt.h> | |
| 10 #include <nspr.h> | |
| 11 #include <nss.h> | |
| 12 | 7 |
| 13 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 14 #include "net/base/completion_callback.h" | 9 #include "net/base/completion_callback.h" |
| 15 #include "net/base/host_port_pair.h" | 10 #include "net/base/io_buffer.h" |
| 16 #include "net/base/net_log.h" | 11 #include "net/base/net_log.h" |
| 17 #include "net/base/nss_memio.h" | |
| 18 #include "net/socket/ssl_server_socket.h" | 12 #include "net/socket/ssl_server_socket.h" |
| 19 #include "net/ssl/ssl_config_service.h" | 13 #include "net/ssl/ssl_config_service.h" |
| 20 | 14 |
| 15 // Avoid including misc OpenSSL headers, i.e.: |
| 16 // <openssl/bio.h> |
| 17 typedef struct bio_st BIO; |
| 18 // <openssl/ssl.h> |
| 19 typedef struct ssl_st SSL; |
| 20 |
| 21 namespace net { | 21 namespace net { |
| 22 | 22 |
| 23 class SSLServerSocketNSS : public SSLServerSocket { | 23 class SSLInfo; |
| 24 |
| 25 class SSLServerSocketOpenSSL : public SSLServerSocket { |
| 24 public: | 26 public: |
| 25 // See comments on CreateSSLServerSocket for details of how these | 27 // See comments on CreateSSLServerSocket for details of how these |
| 26 // parameters are used. | 28 // parameters are used. |
| 27 SSLServerSocketNSS(scoped_ptr<StreamSocket> socket, | 29 SSLServerSocketOpenSSL(scoped_ptr<StreamSocket> socket, |
| 28 scoped_refptr<X509Certificate> certificate, | 30 scoped_refptr<X509Certificate> certificate, |
| 29 crypto::RSAPrivateKey* key, | 31 crypto::RSAPrivateKey* key, |
| 30 const SSLConfig& ssl_config); | 32 const SSLConfig& ssl_config); |
| 31 virtual ~SSLServerSocketNSS(); | 33 virtual ~SSLServerSocketOpenSSL(); |
| 32 | 34 |
| 33 // SSLServerSocket interface. | 35 // SSLServerSocket interface. |
| 34 virtual int Handshake(const CompletionCallback& callback) OVERRIDE; | 36 virtual int Handshake(const CompletionCallback& callback) OVERRIDE; |
| 35 | 37 |
| 36 // SSLSocket interface. | 38 // SSLSocket interface. |
| 37 virtual int ExportKeyingMaterial(const base::StringPiece& label, | 39 virtual int ExportKeyingMaterial(const base::StringPiece& label, |
| 38 bool has_context, | 40 bool has_context, |
| 39 const base::StringPiece& context, | 41 const base::StringPiece& context, |
| 40 unsigned char* out, | 42 unsigned char* out, |
| 41 unsigned int outlen) OVERRIDE; | 43 unsigned int outlen) OVERRIDE; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 64 virtual bool WasNpnNegotiated() const OVERRIDE; | 66 virtual bool WasNpnNegotiated() const OVERRIDE; |
| 65 virtual NextProto GetNegotiatedProtocol() const OVERRIDE; | 67 virtual NextProto GetNegotiatedProtocol() const OVERRIDE; |
| 66 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE; | 68 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE; |
| 67 | 69 |
| 68 private: | 70 private: |
| 69 enum State { | 71 enum State { |
| 70 STATE_NONE, | 72 STATE_NONE, |
| 71 STATE_HANDSHAKE, | 73 STATE_HANDSHAKE, |
| 72 }; | 74 }; |
| 73 | 75 |
| 74 int InitializeSSLOptions(); | |
| 75 | |
| 76 void OnSendComplete(int result); | 76 void OnSendComplete(int result); |
| 77 void OnRecvComplete(int result); | 77 void OnRecvComplete(int result); |
| 78 void OnHandshakeIOComplete(int result); | 78 void OnHandshakeIOComplete(int result); |
| 79 | 79 |
| 80 int BufferSend(); | 80 int BufferSend(); |
| 81 void BufferSendComplete(int result); | 81 void BufferSendComplete(int result); |
| 82 void TransportWriteComplete(int result); |
| 82 int BufferRecv(); | 83 int BufferRecv(); |
| 83 void BufferRecvComplete(int result); | 84 void BufferRecvComplete(int result); |
| 85 int TransportReadComplete(int result); |
| 84 bool DoTransportIO(); | 86 bool DoTransportIO(); |
| 85 int DoPayloadRead(); | 87 int DoPayloadRead(); |
| 86 int DoPayloadWrite(); | 88 int DoPayloadWrite(); |
| 87 | 89 |
| 88 int DoHandshakeLoop(int last_io_result); | 90 int DoHandshakeLoop(int last_io_result); |
| 89 int DoReadLoop(int result); | 91 int DoReadLoop(int result); |
| 90 int DoWriteLoop(int result); | 92 int DoWriteLoop(int result); |
| 91 int DoHandshake(); | 93 int DoHandshake(); |
| 92 void DoHandshakeCallback(int result); | 94 void DoHandshakeCallback(int result); |
| 93 void DoReadCallback(int result); | 95 void DoReadCallback(int result); |
| 94 void DoWriteCallback(int result); | 96 void DoWriteCallback(int result); |
| 95 | 97 |
| 96 static SECStatus OwnAuthCertHandler(void* arg, | 98 virtual bool Init(); |
| 97 PRFileDesc* socket, | |
| 98 PRBool checksig, | |
| 99 PRBool is_server); | |
| 100 static void HandshakeCallback(PRFileDesc* socket, void* arg); | |
| 101 | |
| 102 virtual int Init(); | |
| 103 | 99 |
| 104 // Members used to send and receive buffer. | 100 // Members used to send and receive buffer. |
| 105 bool transport_send_busy_; | 101 bool transport_send_busy_; |
| 106 bool transport_recv_busy_; | 102 bool transport_recv_busy_; |
| 103 bool transport_recv_eof_; |
| 107 | 104 |
| 105 scoped_refptr<DrainableIOBuffer> send_buffer_; |
| 108 scoped_refptr<IOBuffer> recv_buffer_; | 106 scoped_refptr<IOBuffer> recv_buffer_; |
| 109 | 107 |
| 110 BoundNetLog net_log_; | 108 BoundNetLog net_log_; |
| 111 | 109 |
| 112 CompletionCallback user_handshake_callback_; | 110 CompletionCallback user_handshake_callback_; |
| 113 CompletionCallback user_read_callback_; | 111 CompletionCallback user_read_callback_; |
| 114 CompletionCallback user_write_callback_; | 112 CompletionCallback user_write_callback_; |
| 115 | 113 |
| 116 // Used by Read function. | 114 // Used by Read function. |
| 117 scoped_refptr<IOBuffer> user_read_buf_; | 115 scoped_refptr<IOBuffer> user_read_buf_; |
| 118 int user_read_buf_len_; | 116 int user_read_buf_len_; |
| 119 | 117 |
| 120 // Used by Write function. | 118 // Used by Write function. |
| 121 scoped_refptr<IOBuffer> user_write_buf_; | 119 scoped_refptr<IOBuffer> user_write_buf_; |
| 122 int user_write_buf_len_; | 120 int user_write_buf_len_; |
| 123 | 121 |
| 124 // The NSS SSL state machine | 122 // Used by TransportWriteComplete() and TransportReadComplete() to signify an |
| 125 PRFileDesc* nss_fd_; | 123 // error writing to the transport socket. A value of OK indicates no error. |
| 124 int transport_write_error_; |
| 126 | 125 |
| 127 // Buffers for the network end of the SSL state machine | 126 // OpenSSL stuff |
| 128 memio_Private* nss_bufs_; | 127 SSL* ssl_; |
| 128 BIO* transport_bio_; |
| 129 | 129 |
| 130 // StreamSocket for sending and receiving data. | 130 // StreamSocket for sending and receiving data. |
| 131 scoped_ptr<StreamSocket> transport_socket_; | 131 scoped_ptr<StreamSocket> transport_socket_; |
| 132 | 132 |
| 133 // Options for the SSL socket. | 133 // Options for the SSL socket. |
| 134 SSLConfig ssl_config_; | 134 SSLConfig ssl_config_; |
| 135 | 135 |
| 136 // Certificate for the server. | 136 // Certificate for the server. |
| 137 scoped_refptr<X509Certificate> cert_; | 137 scoped_refptr<X509Certificate> cert_; |
| 138 | 138 |
| 139 // Private key used by the server. | 139 // Private key used by the server. |
| 140 scoped_ptr<crypto::RSAPrivateKey> key_; | 140 scoped_ptr<crypto::RSAPrivateKey> key_; |
| 141 | 141 |
| 142 State next_handshake_state_; | 142 State next_handshake_state_; |
| 143 bool completed_handshake_; | 143 bool completed_handshake_; |
| 144 | 144 |
| 145 DISALLOW_COPY_AND_ASSIGN(SSLServerSocketNSS); | 145 DISALLOW_COPY_AND_ASSIGN(SSLServerSocketOpenSSL); |
| 146 }; | 146 }; |
| 147 | 147 |
| 148 } // namespace net | 148 } // namespace net |
| 149 | 149 |
| 150 #endif // NET_SOCKET_SSL_SERVER_SOCKET_NSS_H_ | 150 #endif // NET_SOCKET_SSL_SERVER_SOCKET_OPENSSL_H_ |
| OLD | NEW |