[email protected] | 72818ea | 2013-03-13 03:23:57 | [diff] [blame^] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "net/quic/quic_crypto_server_stream.h" |
| 6 | |
| 7 | #include "net/quic/crypto/crypto_protocol.h" |
| 8 | #include "net/quic/crypto/crypto_utils.h" |
| 9 | #include "net/quic/quic_protocol.h" |
| 10 | #include "net/quic/quic_session.h" |
| 11 | |
| 12 | namespace net { |
| 13 | |
| 14 | QuicCryptoServerStream::QuicCryptoServerStream(QuicSession* session) |
| 15 | : QuicCryptoStream(session) { |
| 16 | config_.SetDefaults(); |
| 17 | // Use hardcoded crypto parameters for now. |
| 18 | CryptoHandshakeMessage extra_tags; |
| 19 | config_.ToHandshakeMessage(&extra_tags); |
| 20 | // TODO(agl): AddTestingConfig generates a new, random config. In the future |
| 21 | // this will be replaced with a real source of configs. |
| 22 | scoped_ptr<CryptoTagValueMap> config_tags( |
| 23 | crypto_config_.AddTestingConfig(session->connection()->random_generator(), |
| 24 | session->connection()->clock(), |
| 25 | extra_tags)); |
| 26 | // If we were using the same config in many servers then we would have to |
| 27 | // parse a QuicConfig from config_tags here. |
| 28 | } |
| 29 | |
| 30 | QuicCryptoServerStream::~QuicCryptoServerStream() { |
| 31 | } |
| 32 | |
| 33 | void QuicCryptoServerStream::OnHandshakeMessage( |
| 34 | const CryptoHandshakeMessage& message) { |
| 35 | // Do not process handshake messages after the handshake is complete. |
| 36 | if (handshake_complete()) { |
| 37 | CloseConnection(QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE); |
| 38 | return; |
| 39 | } |
| 40 | |
| 41 | if (message.tag != kCHLO) { |
| 42 | CloseConnection(QUIC_INVALID_CRYPTO_MESSAGE_TYPE); |
| 43 | return; |
| 44 | } |
| 45 | |
| 46 | string error_details; |
| 47 | QuicErrorCode error = config_.ProcessPeerHandshake( |
| 48 | message, CryptoUtils::LOCAL_PRIORITY, &negotiated_params_, |
| 49 | &error_details); |
| 50 | if (error != QUIC_NO_ERROR) { |
| 51 | CloseConnectionWithDetails(error, "negotiated params"); |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | CryptoHandshakeMessage shlo; |
| 56 | CryptoUtils::GenerateNonce(session()->connection()->clock(), |
| 57 | session()->connection()->random_generator(), |
| 58 | &server_nonce_); |
| 59 | QuicCryptoNegotiatedParams params; |
| 60 | crypto_config_.ProcessClientHello(message, server_nonce_, &shlo, ¶ms, |
| 61 | &error_details); |
| 62 | if (!error_details.empty()) { |
| 63 | DLOG(INFO) << "Rejecting CHLO: " << error_details; |
| 64 | } |
| 65 | config_.ToHandshakeMessage(&shlo); |
| 66 | SendHandshakeMessage(shlo); |
| 67 | |
| 68 | // TODO(rch): correctly validate the message |
| 69 | SetHandshakeComplete(QUIC_NO_ERROR); |
| 70 | return; |
| 71 | } |
| 72 | |
| 73 | } // namespace net |