Index: net/quic/quic_crypto_client_stream.cc |
diff --git a/net/quic/quic_crypto_client_stream.cc b/net/quic/quic_crypto_client_stream.cc |
index 674a441e7971a0b62e9c6ee49486139a489cfcbf..7f8dbd27ecff674d6bd97285d4bf1c5f924a45e8 100644 |
--- a/net/quic/quic_crypto_client_stream.cc |
+++ b/net/quic/quic_crypto_client_stream.cc |
@@ -4,6 +4,8 @@ |
#include "net/quic/quic_crypto_client_stream.h" |
+#include "net/base/completion_callback.h" |
+#include "net/base/net_errors.h" |
#include "net/quic/crypto/crypto_protocol.h" |
#include "net/quic/crypto/crypto_utils.h" |
#include "net/quic/crypto/null_encrypter.h" |
@@ -18,6 +20,7 @@ QuicCryptoClientStream::QuicCryptoClientStream( |
QuicSession* session, |
QuicCryptoClientConfig* crypto_config) |
: QuicCryptoStream(session), |
+ weak_factory_(this), |
next_state_(STATE_IDLE), |
num_client_hellos_(0), |
crypto_config_(crypto_config), |
@@ -29,12 +32,12 @@ QuicCryptoClientStream::~QuicCryptoClientStream() { |
void QuicCryptoClientStream::OnHandshakeMessage( |
const CryptoHandshakeMessage& message) { |
- DoHandshakeLoop(&message); |
+ DoHandshakeLoop(&message, OK); |
} |
bool QuicCryptoClientStream::CryptoConnect() { |
next_state_ = STATE_SEND_CHLO; |
- DoHandshakeLoop(NULL); |
+ DoHandshakeLoop(NULL, OK); |
return true; |
} |
@@ -50,7 +53,8 @@ int QuicCryptoClientStream::num_sent_client_hellos() const { |
static const int kMaxClientHellos = 3; |
void QuicCryptoClientStream::DoHandshakeLoop( |
- const CryptoHandshakeMessage* in) { |
+ const CryptoHandshakeMessage* in, |
+ int result) { |
CryptoHandshakeMessage out; |
QuicErrorCode error; |
string error_details; |
@@ -139,30 +143,60 @@ void QuicCryptoClientStream::DoHandshakeLoop( |
return; |
} |
if (!cached->proof_valid()) { |
- const ProofVerifier* verifier = crypto_config_->proof_verifier(); |
- if (!verifier) { |
- // If no verifier is set then we don't check the certificates. |
- cached->SetProofValid(); |
- } else if (!cached->signature().empty()) { |
- // TODO(rtenneti): In Chromium, we will need to make VerifyProof() |
- // asynchronous. |
- if (!verifier->VerifyProof(server_hostname_, |
- cached->server_config(), |
- cached->certs(), |
- cached->signature(), |
- &error_details)) { |
- CloseConnectionWithDetails(QUIC_PROOF_INVALID, |
- "Proof invalid: " + error_details); |
- return; |
- } |
- cached->SetProofValid(); |
+ ProofVerifier* verifier = session()->proof_verifier(); |
+ if (verifier && !cached->signature().empty()) { |
+ next_state_ = STATE_VERIFY_PROOF; |
+ continue; |
} |
} |
+ // If proof is valid or if there is no verifier is set or if |
+ // cached->signature is empty then we don't check the certificates. |
agl
2013/07/02 15:20:08
We can receive multiple REJ in a handshake. At the
ramant (doing other things)
2013/07/02 19:45:51
Reorganized the code. Could you take another look.
|
+ result = OK; |
+ next_state_ = STATE_VERIFY_PROOF_COMPLETED; |
+ break; |
+ case STATE_VERIFY_PROOF: { |
+ // We will verify proof if there is a verifier. |
+ ProofVerifier* verifier = session()->proof_verifier(); |
+ DCHECK_EQ(verifier->generation_counter(), 0u); |
agl
2013/07/02 15:20:08
Why should the generation counter always be zero?
ramant (doing other things)
2013/07/02 19:45:51
Done.
|
+ DCHECK_GT(cached->generation_counter(), 0u); |
+ result = verifier->VerifyProof( |
+ server_hostname_, |
+ cached->server_config(), |
+ cached->certs(), |
+ cached->signature(), |
+ cached->generation_counter(), |
+ base::Bind(&QuicCryptoClientStream::OnVerifyProofComplete, |
+ weak_factory_.GetWeakPtr())); |
+ if (result == ERR_IO_PENDING) { |
+ DVLOG(1) << "Doing VerifyProof"; |
+ return; |
+ } |
+ next_state_ = STATE_VERIFY_PROOF_COMPLETED; |
+ break; |
+ } |
+ case STATE_VERIFY_PROOF_COMPLETED: { |
+ if (!cached->proof_valid()) { |
+ ProofVerifier* verifier = session()->proof_verifier(); |
+ if (result != OK) { |
+ CloseConnectionWithDetails(QUIC_PROOF_INVALID, |
+ "Proof invalid: " + verifier->error_details()); |
+ return; |
+ } |
+ // Check if generation_counter has changed between STATE_VERIFY_PROOF |
+ // and STATE_VERIFY_PROOF_COMPLETED state changes. |
+ if (verifier && verifier->generation_counter() > 0 && |
+ verifier->generation_counter() != cached->generation_counter()) { |
+ CloseConnectionWithDetails(QUIC_PROOF_INVALID, |
agl
2013/07/02 15:20:08
The generation counter changing isn't an error. We
ramant (doing other things)
2013/07/02 19:45:51
Done.
|
+ "Proof invalid: server certs have changed"); |
+ return; |
+ } |
+ cached->SetProofValid(); |
+ } |
// Send the subsequent client hello in plaintext. |
- session()->connection()->SetDefaultEncryptionLevel( |
- ENCRYPTION_NONE); |
+ session()->connection()->SetDefaultEncryptionLevel(ENCRYPTION_NONE); |
next_state_ = STATE_SEND_CHLO; |
break; |
+ } |
case STATE_RECV_SHLO: { |
// We sent a CHLO that we expected to be accepted and now we're hoping |
// for a SHLO from the server to confirm that. |
@@ -232,4 +266,10 @@ void QuicCryptoClientStream::DoHandshakeLoop( |
} |
} |
+void QuicCryptoClientStream::OnVerifyProofComplete(int result) { |
+ DVLOG(1) << "VerifyProof completed: " << result; |
agl
2013/07/02 15:20:08
Is it ensured that this callback is always made on
ramant (doing other things)
2013/07/02 19:45:51
Added the comment to VerifyProof.
Done.
|
+ next_state_ = STATE_VERIFY_PROOF_COMPLETED; |
+ DoHandshakeLoop(NULL, result); |
+} |
+ |
} // namespace net |