| 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_BASE_SSL_CLIENT_SOCKET_NSS_H_ | |
| 6 #define NET_BASE_SSL_CLIENT_SOCKET_NSS_H_ | |
| 7 | |
| 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. | |
| 10 #define Lock FOO_NSS_Lock | |
| 11 #include <certt.h> | |
| 12 #undef Lock | |
| 13 #include <nspr.h> | |
| 14 #include <nss.h> | |
| 15 #include <string> | |
| 16 | |
| 17 #include "base/scoped_ptr.h" | |
| 18 #include "net/base/cert_verifier.h" | |
| 19 #include "net/base/cert_verify_result.h" | |
| 20 #include "net/base/completion_callback.h" | |
| 21 #include "net/base/nss_memio.h" | |
| 22 #include "net/base/ssl_client_socket.h" | |
| 23 #include "net/base/ssl_config_service.h" | |
| 24 | |
| 25 namespace net { | |
| 26 | |
| 27 class X509Certificate; | |
| 28 | |
| 29 // An SSL client socket implemented with Mozilla NSS. | |
| 30 class SSLClientSocketNSS : public SSLClientSocket { | |
| 31 public: | |
| 32 // Takes ownership of the transport_socket, which may already be connected. | |
| 33 // The given hostname will be compared with the name(s) in the server's | |
| 34 // certificate during the SSL handshake. ssl_config specifies the SSL | |
| 35 // settings. | |
| 36 SSLClientSocketNSS(ClientSocket* transport_socket, | |
| 37 const std::string& hostname, | |
| 38 const SSLConfig& ssl_config); | |
| 39 ~SSLClientSocketNSS(); | |
| 40 | |
| 41 // SSLClientSocket methods: | |
| 42 virtual void GetSSLInfo(SSLInfo* ssl_info); | |
| 43 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info); | |
| 44 | |
| 45 // ClientSocket methods: | |
| 46 virtual int Connect(CompletionCallback* callback); | |
| 47 virtual void Disconnect(); | |
| 48 virtual bool IsConnected() const; | |
| 49 virtual bool IsConnectedAndIdle() const; | |
| 50 | |
| 51 // Socket methods: | |
| 52 virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback); | |
| 53 virtual int Write(IOBuffer* buf, int buf_len, CompletionCallback* callback); | |
| 54 | |
| 55 private: | |
| 56 void InvalidateSessionIfBadCertificate(); | |
| 57 X509Certificate* UpdateServerCert(); | |
| 58 void DoCallback(int result); | |
| 59 void OnIOComplete(int result); | |
| 60 | |
| 61 int DoLoop(int last_io_result); | |
| 62 int DoHandshakeRead(); | |
| 63 int DoVerifyCert(int result); | |
| 64 int DoVerifyCertComplete(int result); | |
| 65 int DoPayloadRead(); | |
| 66 int DoPayloadWrite(); | |
| 67 int Init(); | |
| 68 int BufferSend(void); | |
| 69 int BufferRecv(void); | |
| 70 void BufferSendComplete(int result); | |
| 71 void BufferRecvComplete(int result); | |
| 72 | |
| 73 // NSS calls this when checking certificates. We pass 'this' as the first | |
| 74 // argument. | |
| 75 static SECStatus OwnAuthCertHandler(void* arg, PRFileDesc* socket, | |
| 76 PRBool checksig, PRBool is_server); | |
| 77 // NSS calls this when handshake is completed. We pass 'this' as the second | |
| 78 // argument. | |
| 79 static void HandshakeCallback(PRFileDesc* socket, void* arg); | |
| 80 | |
| 81 CompletionCallbackImpl<SSLClientSocketNSS> buffer_send_callback_; | |
| 82 CompletionCallbackImpl<SSLClientSocketNSS> buffer_recv_callback_; | |
| 83 bool transport_send_busy_; | |
| 84 bool transport_recv_busy_; | |
| 85 scoped_refptr<IOBuffer> recv_buffer_; | |
| 86 | |
| 87 CompletionCallbackImpl<SSLClientSocketNSS> io_callback_; | |
| 88 scoped_ptr<ClientSocket> transport_; | |
| 89 std::string hostname_; | |
| 90 SSLConfig ssl_config_; | |
| 91 | |
| 92 CompletionCallback* user_callback_; | |
| 93 | |
| 94 // Used by both Read and Write functions. | |
| 95 scoped_refptr<IOBuffer> user_buf_; | |
| 96 int user_buf_len_; | |
| 97 | |
| 98 // Set when handshake finishes. | |
| 99 scoped_refptr<X509Certificate> server_cert_; | |
| 100 CertVerifyResult server_cert_verify_result_; | |
| 101 | |
| 102 CertVerifier verifier_; | |
| 103 | |
| 104 bool completed_handshake_; | |
| 105 | |
| 106 enum State { | |
| 107 STATE_NONE, | |
| 108 STATE_HANDSHAKE_READ, | |
| 109 STATE_VERIFY_CERT, | |
| 110 STATE_VERIFY_CERT_COMPLETE, | |
| 111 STATE_PAYLOAD_WRITE, | |
| 112 STATE_PAYLOAD_READ, | |
| 113 }; | |
| 114 State next_state_; | |
| 115 | |
| 116 // The NSS SSL state machine | |
| 117 PRFileDesc* nss_fd_; | |
| 118 | |
| 119 // Buffers for the network end of the SSL state machine | |
| 120 memio_Private* nss_bufs_; | |
| 121 | |
| 122 static bool nss_options_initialized_; | |
| 123 }; | |
| 124 | |
| 125 } // namespace net | |
| 126 | |
| 127 #endif // NET_BASE_SSL_CLIENT_SOCKET_NSS_H_ | |
| OLD | NEW |