QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [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 | |
QUICHE team | 5be974e | 2020-12-29 18:35:24 -0500 | [diff] [blame] | 5 | #include "quic/core/quic_crypto_handshaker.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6 | |
QUICHE team | 5be974e | 2020-12-29 18:35:24 -0500 | [diff] [blame] | 7 | #include "quic/core/quic_session.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8 | |
| 9 | namespace quic { |
| 10 | |
| 11 | #define ENDPOINT \ |
| 12 | (session()->perspective() == Perspective::IS_SERVER ? "Server: " : "Client: ") |
| 13 | |
| 14 | QuicCryptoHandshaker::QuicCryptoHandshaker(QuicCryptoStream* stream, |
| 15 | QuicSession* session) |
| 16 | : stream_(stream), session_(session), last_sent_handshake_message_tag_(0) { |
| 17 | crypto_framer_.set_visitor(this); |
| 18 | } |
| 19 | |
| 20 | QuicCryptoHandshaker::~QuicCryptoHandshaker() {} |
| 21 | |
| 22 | void QuicCryptoHandshaker::SendHandshakeMessage( |
fayang | 9c41f8b | 2020-10-30 13:13:06 -0700 | [diff] [blame] | 23 | const CryptoHandshakeMessage& message, |
| 24 | EncryptionLevel level) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 25 | QUIC_DVLOG(1) << ENDPOINT << "Sending " << message.DebugString(); |
| 26 | session()->NeuterUnencryptedData(); |
| 27 | session()->OnCryptoHandshakeMessageSent(message); |
| 28 | last_sent_handshake_message_tag_ = message.tag(); |
| 29 | const QuicData& data = message.GetSerialized(); |
fayang | e402302 | 2021-07-26 15:11:40 -0700 | [diff] [blame] | 30 | stream_->WriteCryptoData(level, data.AsStringPiece()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | void QuicCryptoHandshaker::OnError(CryptoFramer* framer) { |
| 34 | QUIC_DLOG(WARNING) << "Error processing crypto data: " |
| 35 | << QuicErrorCodeToString(framer->error()); |
| 36 | } |
| 37 | |
| 38 | void QuicCryptoHandshaker::OnHandshakeMessage( |
| 39 | const CryptoHandshakeMessage& message) { |
| 40 | QUIC_DVLOG(1) << ENDPOINT << "Received " << message.DebugString(); |
| 41 | session()->OnCryptoHandshakeMessageReceived(message); |
| 42 | } |
| 43 | |
| 44 | CryptoMessageParser* QuicCryptoHandshaker::crypto_message_parser() { |
| 45 | return &crypto_framer_; |
| 46 | } |
| 47 | |
nharper | 486a8a9 | 2019-08-28 16:25:10 -0700 | [diff] [blame] | 48 | size_t QuicCryptoHandshaker::BufferSizeLimitForLevel(EncryptionLevel) const { |
| 49 | return GetQuicFlag(FLAGS_quic_max_buffered_crypto_bytes); |
| 50 | } |
| 51 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 52 | #undef ENDPOINT // undef for jumbo builds |
| 53 | } // namespace quic |