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 void QuicCryptoStream::OnDataAvailable() {
48 if (sequencer()->GetReadableRegions(&iov
, 1) != 1) {
49 // No more data to read.
52 StringPiece
data(static_cast<char*>(iov
.iov_base
), iov
.iov_len
);
53 if (!crypto_framer_
.ProcessInput(data
)) {
54 CloseConnection(crypto_framer_
.error());
57 sequencer()->MarkConsumed(iov
.iov_len
);
61 QuicPriority
QuicCryptoStream::EffectivePriority() const {
62 return QuicUtils::HighestPriority();
65 void QuicCryptoStream::SendHandshakeMessage(
66 const CryptoHandshakeMessage
& message
) {
67 SendHandshakeMessage(message
, nullptr);
70 void QuicCryptoStream::SendHandshakeMessage(
71 const CryptoHandshakeMessage
& message
,
72 QuicAckNotifier::DelegateInterface
* delegate
) {
73 DVLOG(1) << ENDPOINT
<< "Sending " << message
.DebugString();
74 session()->OnCryptoHandshakeMessageSent(message
);
75 const QuicData
& data
= message
.GetSerialized();
76 // TODO(wtc): check the return value.
77 WriteOrBufferData(string(data
.data(), data
.length()), false, delegate
);
80 bool QuicCryptoStream::ExportKeyingMaterial(
84 string
* result
) const {
85 if (!handshake_confirmed()) {
86 DLOG(ERROR
) << "ExportKeyingMaterial was called before forward-secure"
87 << "encryption was established.";
90 return CryptoUtils::ExportKeyingMaterial(
91 crypto_negotiated_params_
.subkey_secret
,
98 const QuicCryptoNegotiatedParameters
&
99 QuicCryptoStream::crypto_negotiated_params() const {
100 return crypto_negotiated_params_
;