| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 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 | 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_CLIENT_SOCKET_NSS_H_ | 5 #ifndef NET_SOCKET_SSL_CLIENT_SOCKET_NSS_H_ |
| 6 #define NET_SOCKET_SSL_CLIENT_SOCKET_NSS_H_ | 6 #define NET_SOCKET_SSL_CLIENT_SOCKET_NSS_H_ |
| 7 | 7 |
| 8 // Work around https://bugzilla.mozilla.org/show_bug.cgi?id=455424 | 8 // Work around https://bugzilla.mozilla.org/show_bug.cgi?id=455424 |
| 9 // until NSS 3.12.2 comes out and we update to it. | 9 // until NSS 3.12.2 comes out and we update to it. |
| 10 #define Lock FOO_NSS_Lock | 10 #define Lock FOO_NSS_Lock |
| 11 #include <certt.h> | 11 #include <certt.h> |
| 12 #undef Lock | 12 #undef Lock |
| 13 #include <keyt.h> | 13 #include <keyt.h> |
| 14 #include <nspr.h> | 14 #include <nspr.h> |
| 15 #include <nss.h> | 15 #include <nss.h> |
| 16 | 16 |
| 17 #include <string> | 17 #include <string> |
| 18 #include <vector> | 18 #include <vector> |
| 19 | 19 |
| 20 #include "base/scoped_ptr.h" | 20 #include "base/scoped_ptr.h" |
| 21 #include "net/base/cert_verify_result.h" | 21 #include "net/base/cert_verify_result.h" |
| 22 #include "net/base/completion_callback.h" | 22 #include "net/base/completion_callback.h" |
| 23 #include "net/base/nss_memio.h" | 23 #include "net/base/nss_memio.h" |
| 24 #include "net/base/ssl_config_service.h" | 24 #include "net/base/ssl_config_service.h" |
| 25 #include "net/socket/ssl_client_socket.h" | 25 #include "net/socket/ssl_client_socket.h" |
| 26 | 26 |
| 27 namespace net { | 27 namespace net { |
| 28 | 28 |
| 29 class CertVerifier; | 29 class CertVerifier; |
| 30 class LoadLog; |
| 30 class X509Certificate; | 31 class X509Certificate; |
| 31 | 32 |
| 32 // An SSL client socket implemented with Mozilla NSS. | 33 // An SSL client socket implemented with Mozilla NSS. |
| 33 class SSLClientSocketNSS : public SSLClientSocket { | 34 class SSLClientSocketNSS : public SSLClientSocket { |
| 34 public: | 35 public: |
| 35 // Takes ownership of the transport_socket, which may already be connected. | 36 // Takes ownership of the transport_socket, which may already be connected. |
| 36 // The given hostname will be compared with the name(s) in the server's | 37 // The given hostname will be compared with the name(s) in the server's |
| 37 // certificate during the SSL handshake. ssl_config specifies the SSL | 38 // certificate during the SSL handshake. ssl_config specifies the SSL |
| 38 // settings. | 39 // settings. |
| 39 SSLClientSocketNSS(ClientSocket* transport_socket, | 40 SSLClientSocketNSS(ClientSocket* transport_socket, |
| 40 const std::string& hostname, | 41 const std::string& hostname, |
| 41 const SSLConfig& ssl_config); | 42 const SSLConfig& ssl_config); |
| 42 ~SSLClientSocketNSS(); | 43 ~SSLClientSocketNSS(); |
| 43 | 44 |
| 44 // SSLClientSocket methods: | 45 // SSLClientSocket methods: |
| 45 virtual void GetSSLInfo(SSLInfo* ssl_info); | 46 virtual void GetSSLInfo(SSLInfo* ssl_info); |
| 46 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info); | 47 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info); |
| 47 | 48 |
| 48 // ClientSocket methods: | 49 // ClientSocket methods: |
| 49 virtual int Connect(CompletionCallback* callback); | 50 virtual int Connect(CompletionCallback* callback, LoadLog* load_log); |
| 50 virtual void Disconnect(); | 51 virtual void Disconnect(); |
| 51 virtual bool IsConnected() const; | 52 virtual bool IsConnected() const; |
| 52 virtual bool IsConnectedAndIdle() const; | 53 virtual bool IsConnectedAndIdle() const; |
| 53 | 54 |
| 54 // Socket methods: | 55 // Socket methods: |
| 55 virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback); | 56 virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback); |
| 56 virtual int Write(IOBuffer* buf, int buf_len, CompletionCallback* callback); | 57 virtual int Write(IOBuffer* buf, int buf_len, CompletionCallback* callback); |
| 57 virtual bool SetReceiveBufferSize(int32 size); | 58 virtual bool SetReceiveBufferSize(int32 size); |
| 58 virtual bool SetSendBufferSize(int32 size); | 59 virtual bool SetSendBufferSize(int32 size); |
| 59 | 60 |
| 60 private: | 61 private: |
| 62 // Initializes NSS SSL options. Returns a net error code. |
| 63 int InitializeSSLOptions(); |
| 64 |
| 61 void InvalidateSessionIfBadCertificate(); | 65 void InvalidateSessionIfBadCertificate(); |
| 62 X509Certificate* UpdateServerCert(); | 66 X509Certificate* UpdateServerCert(); |
| 63 void DoReadCallback(int result); | 67 void DoReadCallback(int result); |
| 64 void DoWriteCallback(int result); | 68 void DoWriteCallback(int result); |
| 65 void DoConnectCallback(int result); | 69 void DoConnectCallback(int result); |
| 66 void OnHandshakeIOComplete(int result); | 70 void OnHandshakeIOComplete(int result); |
| 67 void OnSendComplete(int result); | 71 void OnSendComplete(int result); |
| 68 void OnRecvComplete(int result); | 72 void OnRecvComplete(int result); |
| 69 | 73 |
| 70 int DoHandshakeLoop(int last_io_result); | 74 int DoHandshakeLoop(int last_io_result); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 STATE_VERIFY_CERT_COMPLETE, | 145 STATE_VERIFY_CERT_COMPLETE, |
| 142 }; | 146 }; |
| 143 State next_handshake_state_; | 147 State next_handshake_state_; |
| 144 | 148 |
| 145 // The NSS SSL state machine | 149 // The NSS SSL state machine |
| 146 PRFileDesc* nss_fd_; | 150 PRFileDesc* nss_fd_; |
| 147 | 151 |
| 148 // Buffers for the network end of the SSL state machine | 152 // Buffers for the network end of the SSL state machine |
| 149 memio_Private* nss_bufs_; | 153 memio_Private* nss_bufs_; |
| 150 | 154 |
| 155 scoped_refptr<LoadLog> load_log_; |
| 156 |
| 151 static bool nss_options_initialized_; | 157 static bool nss_options_initialized_; |
| 152 }; | 158 }; |
| 153 | 159 |
| 154 } // namespace net | 160 } // namespace net |
| 155 | 161 |
| 156 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_NSS_H_ | 162 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_NSS_H_ |
| OLD | NEW |