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 (is_server_ ? "Server: " : " Client: ")
23 QuicCryptoStream::QuicCryptoStream(QuicSession
* session
)
24 : ReliableQuicStream(kCryptoStreamId
, session
),
25 encryption_established_(false),
26 handshake_confirmed_(false),
27 is_server_(session
->is_server()) {
28 crypto_framer_
.set_visitor(this);
29 if (version() <= QUIC_VERSION_20
) {
30 // Prior to QUIC_VERSION_21 the crypto stream is not subject to any flow
34 // The crypto stream is exempt from connection level flow control.
35 DisableConnectionFlowControlForThisStream();
38 void QuicCryptoStream::OnError(CryptoFramer
* framer
) {
39 DLOG(WARNING
) << "Error processing crypto data: "
40 << QuicUtils::ErrorToString(framer
->error());
43 void QuicCryptoStream::OnHandshakeMessage(
44 const CryptoHandshakeMessage
& message
) {
45 DVLOG(1) << ENDPOINT
<< "Received " << message
.DebugString();
46 session()->OnCryptoHandshakeMessageReceived(message
);
49 uint32
QuicCryptoStream::ProcessRawData(const char* data
,
51 if (!crypto_framer_
.ProcessInput(StringPiece(data
, data_len
))) {
52 CloseConnection(crypto_framer_
.error());
58 QuicPriority
QuicCryptoStream::EffectivePriority() const {
59 return QuicUtils::HighestPriority();
62 void QuicCryptoStream::SendHandshakeMessage(
63 const CryptoHandshakeMessage
& message
) {
64 SendHandshakeMessage(message
, NULL
);
67 void QuicCryptoStream::SendHandshakeMessage(
68 const CryptoHandshakeMessage
& message
,
69 QuicAckNotifier::DelegateInterface
* delegate
) {
70 DVLOG(1) << ENDPOINT
<< "Sending " << message
.DebugString();
71 session()->OnCryptoHandshakeMessageSent(message
);
72 const QuicData
& data
= message
.GetSerialized();
73 // TODO(wtc): check the return value.
74 WriteOrBufferData(string(data
.data(), data
.length()), false, delegate
);
77 bool QuicCryptoStream::ExportKeyingMaterial(
81 string
* result
) const {
82 if (!handshake_confirmed()) {
83 DLOG(ERROR
) << "ExportKeyingMaterial was called before forward-secure"
84 << "encryption was established.";
87 return CryptoUtils::ExportKeyingMaterial(
88 crypto_negotiated_params_
.subkey_secret
,
95 const QuicCryptoNegotiatedParameters
&
96 QuicCryptoStream::crypto_negotiated_params() const {
97 return crypto_negotiated_params_
;