| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_NSS_H_ |
| 6 #define NET_SOCKET_SSL_SERVER_SOCKET_NSS_H_ | 6 #define NET_SOCKET_SSL_SERVER_SOCKET_NSS_H_ |
| 7 | 7 |
| 8 #include <certt.h> | 8 #include <certt.h> |
| 9 #include <keyt.h> | 9 #include <keyt.h> |
| 10 #include <nspr.h> | 10 #include <nspr.h> |
| 11 #include <nss.h> | 11 #include <nss.h> |
| 12 #include <stdint.h> | 12 #include <stdint.h> |
| 13 | 13 |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "net/base/completion_callback.h" | 16 #include "net/base/completion_callback.h" |
| 17 #include "net/base/host_port_pair.h" | 17 #include "net/base/host_port_pair.h" |
| 18 #include "net/base/nss_memio.h" | 18 #include "net/base/nss_memio.h" |
| 19 #include "net/log/net_log.h" | 19 #include "net/log/net_log.h" |
| 20 #include "net/socket/ssl_server_socket.h" | 20 #include "net/socket/ssl_server_socket.h" |
| 21 #include "net/ssl/ssl_server_config.h" | 21 #include "net/ssl/ssl_server_config.h" |
| 22 | 22 |
| 23 namespace net { | 23 namespace net { |
| 24 | 24 |
| 25 class SSLServerSocketNSS : public SSLServerSocket { | 25 class SSLServerContextNSS : public SSLServerContext { |
| 26 public: | 26 public: |
| 27 // See comments on CreateSSLServerSocket for details of how these | 27 SSLServerContextNSS(X509Certificate* certificate, |
| 28 // parameters are used. | 28 const crypto::RSAPrivateKey& key, |
| 29 SSLServerSocketNSS(scoped_ptr<StreamSocket> socket, | 29 const SSLServerConfig& ssl_server_config); |
| 30 scoped_refptr<X509Certificate> certificate, | 30 ~SSLServerContextNSS() override; |
| 31 const crypto::RSAPrivateKey& key, | |
| 32 const SSLServerConfig& ssl_server_config); | |
| 33 ~SSLServerSocketNSS() override; | |
| 34 | 31 |
| 35 // SSLServerSocket interface. | 32 scoped_ptr<SSLServerSocket> CreateSSLServerSocket( |
| 36 int Handshake(const CompletionCallback& callback) override; | 33 scoped_ptr<StreamSocket> socket) override; |
| 37 | |
| 38 // SSLSocket interface. | |
| 39 int ExportKeyingMaterial(const base::StringPiece& label, | |
| 40 bool has_context, | |
| 41 const base::StringPiece& context, | |
| 42 unsigned char* out, | |
| 43 unsigned int outlen) override; | |
| 44 int GetTLSUniqueChannelBinding(std::string* out) override; | |
| 45 | |
| 46 // Socket interface (via StreamSocket). | |
| 47 int Read(IOBuffer* buf, | |
| 48 int buf_len, | |
| 49 const CompletionCallback& callback) override; | |
| 50 int Write(IOBuffer* buf, | |
| 51 int buf_len, | |
| 52 const CompletionCallback& callback) override; | |
| 53 int SetReceiveBufferSize(int32_t size) override; | |
| 54 int SetSendBufferSize(int32_t size) override; | |
| 55 | |
| 56 // StreamSocket implementation. | |
| 57 int Connect(const CompletionCallback& callback) override; | |
| 58 void Disconnect() override; | |
| 59 bool IsConnected() const override; | |
| 60 bool IsConnectedAndIdle() const override; | |
| 61 int GetPeerAddress(IPEndPoint* address) const override; | |
| 62 int GetLocalAddress(IPEndPoint* address) const override; | |
| 63 const BoundNetLog& NetLog() const override; | |
| 64 void SetSubresourceSpeculation() override; | |
| 65 void SetOmniboxSpeculation() override; | |
| 66 bool WasEverUsed() const override; | |
| 67 bool UsingTCPFastOpen() const override; | |
| 68 bool WasNpnNegotiated() const override; | |
| 69 NextProto GetNegotiatedProtocol() const override; | |
| 70 bool GetSSLInfo(SSLInfo* ssl_info) override; | |
| 71 void GetConnectionAttempts(ConnectionAttempts* out) const override; | |
| 72 void ClearConnectionAttempts() override {} | |
| 73 void AddConnectionAttempts(const ConnectionAttempts& attempts) override {} | |
| 74 int64_t GetTotalReceivedBytes() const override; | |
| 75 | 34 |
| 76 private: | 35 private: |
| 77 enum State { | |
| 78 STATE_NONE, | |
| 79 STATE_HANDSHAKE, | |
| 80 }; | |
| 81 | |
| 82 int InitializeSSLOptions(); | |
| 83 | |
| 84 void OnSendComplete(int result); | |
| 85 void OnRecvComplete(int result); | |
| 86 void OnHandshakeIOComplete(int result); | |
| 87 | |
| 88 int BufferSend(); | |
| 89 void BufferSendComplete(int result); | |
| 90 int BufferRecv(); | |
| 91 void BufferRecvComplete(int result); | |
| 92 bool DoTransportIO(); | |
| 93 int DoPayloadRead(); | |
| 94 int DoPayloadWrite(); | |
| 95 | |
| 96 int DoHandshakeLoop(int last_io_result); | |
| 97 int DoReadLoop(int result); | |
| 98 int DoWriteLoop(int result); | |
| 99 int DoHandshake(); | |
| 100 void DoHandshakeCallback(int result); | |
| 101 void DoReadCallback(int result); | |
| 102 void DoWriteCallback(int result); | |
| 103 | |
| 104 static SECStatus OwnAuthCertHandler(void* arg, | |
| 105 PRFileDesc* socket, | |
| 106 PRBool checksig, | |
| 107 PRBool is_server); | |
| 108 static void HandshakeCallback(PRFileDesc* socket, void* arg); | |
| 109 | |
| 110 int Init(); | |
| 111 | |
| 112 // Members used to send and receive buffer. | |
| 113 bool transport_send_busy_; | |
| 114 bool transport_recv_busy_; | |
| 115 | |
| 116 scoped_refptr<IOBuffer> recv_buffer_; | |
| 117 | |
| 118 BoundNetLog net_log_; | |
| 119 | |
| 120 CompletionCallback user_handshake_callback_; | |
| 121 CompletionCallback user_read_callback_; | |
| 122 CompletionCallback user_write_callback_; | |
| 123 | |
| 124 // Used by Read function. | |
| 125 scoped_refptr<IOBuffer> user_read_buf_; | |
| 126 int user_read_buf_len_; | |
| 127 | |
| 128 // Used by Write function. | |
| 129 scoped_refptr<IOBuffer> user_write_buf_; | |
| 130 int user_write_buf_len_; | |
| 131 | |
| 132 // The NSS SSL state machine | |
| 133 PRFileDesc* nss_fd_; | |
| 134 | |
| 135 // Buffers for the network end of the SSL state machine | |
| 136 memio_Private* nss_bufs_; | |
| 137 | |
| 138 // StreamSocket for sending and receiving data. | |
| 139 scoped_ptr<StreamSocket> transport_socket_; | |
| 140 | |
| 141 // Options for the SSL socket. | 36 // Options for the SSL socket. |
| 142 SSLServerConfig ssl_server_config_; | 37 SSLServerConfig ssl_server_config_; |
| 143 | 38 |
| 144 // Certificate for the server. | 39 // Certificate for the server. |
| 145 scoped_refptr<X509Certificate> cert_; | 40 scoped_refptr<X509Certificate> cert_; |
| 146 | 41 |
| 147 // Private key used by the server. | 42 // Private key used by the server. |
| 148 scoped_ptr<crypto::RSAPrivateKey> key_; | 43 scoped_ptr<crypto::RSAPrivateKey> key_; |
| 149 | |
| 150 State next_handshake_state_; | |
| 151 bool completed_handshake_; | |
| 152 | |
| 153 DISALLOW_COPY_AND_ASSIGN(SSLServerSocketNSS); | |
| 154 }; | 44 }; |
| 155 | 45 |
| 156 } // namespace net | 46 } // namespace net |
| 157 | 47 |
| 158 #endif // NET_SOCKET_SSL_SERVER_SOCKET_NSS_H_ | 48 #endif // NET_SOCKET_SSL_SERVER_SOCKET_NSS_H_ |
| OLD | NEW |