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
;
22 (session()->perspective() == Perspective::IS_SERVER ? "Server: " : "Client:" \
25 QuicCryptoStream::QuicCryptoStream(QuicSession
* session
)
26 : ReliableQuicStream(kCryptoStreamId
, session
),
27 encryption_established_(false),
28 handshake_confirmed_(false) {
29 crypto_framer_
.set_visitor(this);
30 // The crypto stream is exempt from connection level flow control.
31 DisableConnectionFlowControlForThisStream();
34 void QuicCryptoStream::OnError(CryptoFramer
* framer
) {
35 DLOG(WARNING
) << "Error processing crypto data: "
36 << QuicUtils::ErrorToString(framer
->error());
39 void QuicCryptoStream::OnHandshakeMessage(
40 const CryptoHandshakeMessage
& message
) {
41 DVLOG(1) << ENDPOINT
<< "Received " << message
.DebugString();
42 session()->OnCryptoHandshakeMessageReceived(message
);
45 uint32
QuicCryptoStream::ProcessRawData(const char* data
,
47 if (!crypto_framer_
.ProcessInput(StringPiece(data
, data_len
))) {
48 CloseConnection(crypto_framer_
.error());
54 QuicPriority
QuicCryptoStream::EffectivePriority() const {
55 return QuicUtils::HighestPriority();
58 void QuicCryptoStream::SendHandshakeMessage(
59 const CryptoHandshakeMessage
& message
) {
60 SendHandshakeMessage(message
, nullptr);
63 void QuicCryptoStream::SendHandshakeMessage(
64 const CryptoHandshakeMessage
& message
,
65 QuicAckNotifier::DelegateInterface
* delegate
) {
66 DVLOG(1) << ENDPOINT
<< "Sending " << message
.DebugString();
67 session()->OnCryptoHandshakeMessageSent(message
);
68 const QuicData
& data
= message
.GetSerialized();
69 // TODO(wtc): check the return value.
70 WriteOrBufferData(string(data
.data(), data
.length()), false, delegate
);
73 bool QuicCryptoStream::ExportKeyingMaterial(
77 string
* result
) const {
78 if (!handshake_confirmed()) {
79 DLOG(ERROR
) << "ExportKeyingMaterial was called before forward-secure"
80 << "encryption was established.";
83 return CryptoUtils::ExportKeyingMaterial(
84 crypto_negotiated_params_
.subkey_secret
,
91 const QuicCryptoNegotiatedParameters
&
92 QuicCryptoStream::crypto_negotiated_params() const {
93 return crypto_negotiated_params_
;