 Chromium Code Reviews
 Chromium Code Reviews Issue 17385010:
  OpenSSL/NSS implementation of ProofVerfifier.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 17385010:
  OpenSSL/NSS implementation of ProofVerfifier.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| 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 #include "net/quic/quic_crypto_client_stream.h" | 5 #include "net/quic/quic_crypto_client_stream.h" | 
| 6 | 6 | 
| 7 #include "net/base/completion_callback.h" | |
| 8 #include "net/base/net_errors.h" | |
| 7 #include "net/quic/crypto/crypto_protocol.h" | 9 #include "net/quic/crypto/crypto_protocol.h" | 
| 8 #include "net/quic/crypto/crypto_utils.h" | 10 #include "net/quic/crypto/crypto_utils.h" | 
| 9 #include "net/quic/crypto/null_encrypter.h" | 11 #include "net/quic/crypto/null_encrypter.h" | 
| 10 #include "net/quic/crypto/proof_verifier.h" | 12 #include "net/quic/crypto/proof_verifier.h" | 
| 11 #include "net/quic/quic_protocol.h" | 13 #include "net/quic/quic_protocol.h" | 
| 12 #include "net/quic/quic_session.h" | 14 #include "net/quic/quic_session.h" | 
| 13 | 15 | 
| 14 namespace net { | 16 namespace net { | 
| 15 | 17 | 
| 16 QuicCryptoClientStream::QuicCryptoClientStream( | 18 QuicCryptoClientStream::QuicCryptoClientStream( | 
| 17 const string& server_hostname, | 19 const string& server_hostname, | 
| 18 QuicSession* session, | 20 QuicSession* session, | 
| 19 QuicCryptoClientConfig* crypto_config) | 21 QuicCryptoClientConfig* crypto_config) | 
| 20 : QuicCryptoStream(session), | 22 : QuicCryptoStream(session), | 
| 23 weak_factory_(this), | |
| 21 next_state_(STATE_IDLE), | 24 next_state_(STATE_IDLE), | 
| 22 num_client_hellos_(0), | 25 num_client_hellos_(0), | 
| 23 crypto_config_(crypto_config), | 26 crypto_config_(crypto_config), | 
| 24 server_hostname_(server_hostname) { | 27 server_hostname_(server_hostname) { | 
| 25 } | 28 } | 
| 26 | 29 | 
| 27 QuicCryptoClientStream::~QuicCryptoClientStream() { | 30 QuicCryptoClientStream::~QuicCryptoClientStream() { | 
| 28 } | 31 } | 
| 29 | 32 | 
| 30 void QuicCryptoClientStream::OnHandshakeMessage( | 33 void QuicCryptoClientStream::OnHandshakeMessage( | 
| 31 const CryptoHandshakeMessage& message) { | 34 const CryptoHandshakeMessage& message) { | 
| 32 DoHandshakeLoop(&message); | 35 DoHandshakeLoop(&message, OK); | 
| 33 } | 36 } | 
| 34 | 37 | 
| 35 bool QuicCryptoClientStream::CryptoConnect() { | 38 bool QuicCryptoClientStream::CryptoConnect() { | 
| 36 next_state_ = STATE_SEND_CHLO; | 39 next_state_ = STATE_SEND_CHLO; | 
| 37 DoHandshakeLoop(NULL); | 40 DoHandshakeLoop(NULL, OK); | 
| 38 return true; | 41 return true; | 
| 39 } | 42 } | 
| 40 | 43 | 
| 41 int QuicCryptoClientStream::num_sent_client_hellos() const { | 44 int QuicCryptoClientStream::num_sent_client_hellos() const { | 
| 42 return num_client_hellos_; | 45 return num_client_hellos_; | 
| 43 } | 46 } | 
| 44 | 47 | 
| 45 // kMaxClientHellos is the maximum number of times that we'll send a client | 48 // kMaxClientHellos is the maximum number of times that we'll send a client | 
| 46 // hello. The value 3 accounts for: | 49 // hello. The value 3 accounts for: | 
| 47 // * One failure due to an incorrect or missing source-address token. | 50 // * One failure due to an incorrect or missing source-address token. | 
| 48 // * One failure due the server's certificate chain being unavailible and the | 51 // * One failure due the server's certificate chain being unavailible and the | 
| 49 // server being unwilling to send it without a valid source-address token. | 52 // server being unwilling to send it without a valid source-address token. | 
| 50 static const int kMaxClientHellos = 3; | 53 static const int kMaxClientHellos = 3; | 
| 51 | 54 | 
| 52 void QuicCryptoClientStream::DoHandshakeLoop( | 55 void QuicCryptoClientStream::DoHandshakeLoop( | 
| 53 const CryptoHandshakeMessage* in) { | 56 const CryptoHandshakeMessage* in, | 
| 57 int result) { | |
| 54 CryptoHandshakeMessage out; | 58 CryptoHandshakeMessage out; | 
| 55 QuicErrorCode error; | 59 QuicErrorCode error; | 
| 56 string error_details; | 60 string error_details; | 
| 57 QuicCryptoClientConfig::CachedState* cached = | 61 QuicCryptoClientConfig::CachedState* cached = | 
| 58 crypto_config_->LookupOrCreate(server_hostname_); | 62 crypto_config_->LookupOrCreate(server_hostname_); | 
| 59 | 63 | 
| 60 if (in != NULL) { | 64 if (in != NULL) { | 
| 61 DVLOG(1) << "Client received: " << in->DebugString(); | 65 DVLOG(1) << "Client received: " << in->DebugString(); | 
| 62 } | 66 } | 
| 63 | 67 | 
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 return; | 136 return; | 
| 133 } | 137 } | 
| 134 error = crypto_config_->ProcessRejection( | 138 error = crypto_config_->ProcessRejection( | 
| 135 cached, *in, session()->connection()->clock()->WallNow(), | 139 cached, *in, session()->connection()->clock()->WallNow(), | 
| 136 &crypto_negotiated_params_, &error_details); | 140 &crypto_negotiated_params_, &error_details); | 
| 137 if (error != QUIC_NO_ERROR) { | 141 if (error != QUIC_NO_ERROR) { | 
| 138 CloseConnectionWithDetails(error, error_details); | 142 CloseConnectionWithDetails(error, error_details); | 
| 139 return; | 143 return; | 
| 140 } | 144 } | 
| 141 if (!cached->proof_valid()) { | 145 if (!cached->proof_valid()) { | 
| 142 const ProofVerifier* verifier = crypto_config_->proof_verifier(); | 146 ProofVerifier* verifier = crypto_config_->proof_verifier(); | 
| 143 if (!verifier) { | 147 if (verifier && !cached->signature().empty()) { | 
| 144 // If no verifier is set then we don't check the certificates. | 148 result = verifier->VerifyProof( | 
| 145 cached->SetProofValid(); | 149 server_hostname_, | 
| 146 } else if (!cached->signature().empty()) { | 150 cached->server_config(), | 
| 147 // TODO(rtenneti): In Chromium, we will need to make VerifyProof() | 151 cached->certs(), | 
| 148 // asynchronous. | 152 cached->signature(), | 
| 149 if (!verifier->VerifyProof(server_hostname_, | 153 base::Bind(&QuicCryptoClientStream::VerifyProofCompleted, | 
| 
agl2
2013/06/28 20:30:09
likewise, base::Bind can't be used in this code ei
 
ramant (doing other things)
2013/06/29 04:08:44
Will use internal API call here.
 | |
| 150 cached->server_config(), | 154 weak_factory_.GetWeakPtr())); | 
| 151 cached->certs(), | 155 if (result == ERR_IO_PENDING) { | 
| 152 cached->signature(), | 156 next_state_ = STATE_PROOF_VERIFY; | 
| 153 &error_details)) { | 157 DVLOG(1) << "Doing VerifyProof"; | 
| 154 CloseConnectionWithDetails(QUIC_PROOF_INVALID, | |
| 155 "Proof invalid: " + error_details); | |
| 156 return; | 158 return; | 
| 157 } | 159 } | 
| 158 cached->SetProofValid(); | |
| 159 } | 160 } | 
| 160 } | 161 } | 
| 162 next_state_ = STATE_PROOF_VERIFICATION_COMPLETED; | |
| 163 break; | |
| 164 case STATE_PROOF_VERIFICATION_COMPLETED: | |
| 165 if (result != OK) { | |
| 166 error_details = crypto_config_->proof_verifier()->error_details(); | |
| 167 CloseConnectionWithDetails(QUIC_PROOF_INVALID, | |
| 168 "Proof invalid: " + error_details); | |
| 169 return; | |
| 170 } | |
| 171 cached->SetProofValid(); | |
| 
agl2
2013/06/28 20:30:09
This is insecure:
In the time that a proof was be
 
ramant (doing other things)
2013/06/29 04:08:44
Done.
 | |
| 161 // Send the subsequent client hello in plaintext. | 172 // Send the subsequent client hello in plaintext. | 
| 162 session()->connection()->SetDefaultEncryptionLevel( | 173 session()->connection()->SetDefaultEncryptionLevel(ENCRYPTION_NONE); | 
| 163 ENCRYPTION_NONE); | |
| 164 next_state_ = STATE_SEND_CHLO; | 174 next_state_ = STATE_SEND_CHLO; | 
| 165 break; | 175 break; | 
| 166 case STATE_RECV_SHLO: { | 176 case STATE_RECV_SHLO: { | 
| 167 // We sent a CHLO that we expected to be accepted and now we're hoping | 177 // We sent a CHLO that we expected to be accepted and now we're hoping | 
| 168 // for a SHLO from the server to confirm that. | 178 // for a SHLO from the server to confirm that. | 
| 169 if (in->tag() == kREJ) { | 179 if (in->tag() == kREJ) { | 
| 170 // alternative_decrypter will be NULL if the original alternative | 180 // alternative_decrypter will be NULL if the original alternative | 
| 171 // decrypter latched and became the primary decrypter. That happens | 181 // decrypter latched and became the primary decrypter. That happens | 
| 172 // if we received a message encrypted with the INITIAL key. | 182 // if we received a message encrypted with the INITIAL key. | 
| 173 if (session()->connection()->alternative_decrypter() == NULL) { | 183 if (session()->connection()->alternative_decrypter() == NULL) { | 
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 ENCRYPTION_FORWARD_SECURE); | 231 ENCRYPTION_FORWARD_SECURE); | 
| 222 | 232 | 
| 223 handshake_confirmed_ = true; | 233 handshake_confirmed_ = true; | 
| 224 session()->OnCryptoHandshakeEvent(QuicSession::HANDSHAKE_CONFIRMED); | 234 session()->OnCryptoHandshakeEvent(QuicSession::HANDSHAKE_CONFIRMED); | 
| 225 return; | 235 return; | 
| 226 } | 236 } | 
| 227 case STATE_IDLE: | 237 case STATE_IDLE: | 
| 228 // This means that the peer sent us a message that we weren't expecting. | 238 // This means that the peer sent us a message that we weren't expecting. | 
| 229 CloseConnection(QUIC_INVALID_CRYPTO_MESSAGE_TYPE); | 239 CloseConnection(QUIC_INVALID_CRYPTO_MESSAGE_TYPE); | 
| 230 return; | 240 return; | 
| 241 case STATE_PROOF_VERIFY: | |
| 242 NOTREACHED() << "STATE_PROOF_VERIFY shouldn't be reached"; | |
| 243 return; | |
| 231 } | 244 } | 
| 232 } | 245 } | 
| 233 } | 246 } | 
| 234 | 247 | 
| 248 void QuicCryptoClientStream::VerifyProofCompleted(int result) { | |
| 249 DVLOG(1) << "VerifyProof completed: " << result; | |
| 250 next_state_ = STATE_PROOF_VERIFICATION_COMPLETED; | |
| 251 DoHandshakeLoop(NULL, result); | |
| 252 } | |
| 253 | |
| 235 } // namespace net | 254 } // namespace net | 
| OLD | NEW |