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.
5 #include "net/quic/quic_crypto_stream.h"
9 #include "base/strings/string_piece.h"
10 #include "net/quic/crypto/crypto_handshake.h"
11 #include "net/quic/crypto/crypto_utils.h"
12 #include "net/quic/quic_connection.h"
13 #include "net/quic/quic_session.h"
14 #include "net/quic/quic_utils.h"
17 using base::StringPiece
;
21 #define ENDPOINT (session()->is_server() ? "Server: " : " Client: ")
23 QuicCryptoStream::QuicCryptoStream(QuicSession
* session
)
24 : ReliableQuicStream(kCryptoStreamId
, session
),
25 encryption_established_(false),
26 handshake_confirmed_(false) {
27 crypto_framer_
.set_visitor(this);
28 if (version() < QUIC_VERSION_21
) {
29 // Prior to QUIC_VERSION_21 the crypto stream is not subject to any flow
33 // The crypto stream is exempt from connection level flow control.
34 DisableConnectionFlowControlForThisStream();
37 void QuicCryptoStream::OnError(CryptoFramer
* framer
) {
38 DLOG(WARNING
) << "Error processing crypto data: "
39 << QuicUtils::ErrorToString(framer
->error());
42 void QuicCryptoStream::OnHandshakeMessage(
43 const CryptoHandshakeMessage
& message
) {
44 DVLOG(1) << ENDPOINT
<< "Received " << message
.DebugString();
45 session()->OnCryptoHandshakeMessageReceived(message
);
48 uint32
QuicCryptoStream::ProcessRawData(const char* data
,
50 if (!crypto_framer_
.ProcessInput(StringPiece(data
, data_len
))) {
51 CloseConnection(crypto_framer_
.error());
57 QuicPriority
QuicCryptoStream::EffectivePriority() const {
58 return QuicUtils::HighestPriority();
61 void QuicCryptoStream::SendHandshakeMessage(
62 const CryptoHandshakeMessage
& message
) {
63 SendHandshakeMessage(message
, nullptr);
66 void QuicCryptoStream::SendHandshakeMessage(
67 const CryptoHandshakeMessage
& message
,
68 QuicAckNotifier::DelegateInterface
* delegate
) {
69 DVLOG(1) << ENDPOINT
<< "Sending " << message
.DebugString();
70 session()->OnCryptoHandshakeMessageSent(message
);
71 const QuicData
& data
= message
.GetSerialized();
72 // TODO(wtc): check the return value.
73 WriteOrBufferData(string(data
.data(), data
.length()), false, delegate
);
76 bool QuicCryptoStream::ExportKeyingMaterial(
80 string
* result
) const {
81 if (!handshake_confirmed()) {
82 DLOG(ERROR
) << "ExportKeyingMaterial was called before forward-secure"
83 << "encryption was established.";
86 return CryptoUtils::ExportKeyingMaterial(
87 crypto_negotiated_params_
.subkey_secret
,
94 const QuicCryptoNegotiatedParameters
&
95 QuicCryptoStream::crypto_negotiated_params() const {
96 return crypto_negotiated_params_
;