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 | |
| 5 | #include "net/third_party/quiche/src/quic/core/quic_crypto_handshaker.h" |
| 6 | |
| 7 | #include "net/third_party/quiche/src/quic/core/quic_session.h" |
| 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( |
| 23 | const CryptoHandshakeMessage& message) { |
| 24 | QUIC_DVLOG(1) << ENDPOINT << "Sending " << message.DebugString(); |
| 25 | session()->NeuterUnencryptedData(); |
| 26 | session()->OnCryptoHandshakeMessageSent(message); |
| 27 | last_sent_handshake_message_tag_ = message.tag(); |
| 28 | const QuicData& data = message.GetSerialized(); |
| 29 | stream_->WriteCryptoData(session_->connection()->encryption_level(), |
| 30 | data.AsStringPiece()); |
| 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 | |
| 48 | #undef ENDPOINT // undef for jumbo builds |
| 49 | } // namespace quic |