If there are no local credentials for a locked profile, show sign in button
[chromium-blink-merge.git] / net / quic / quic_crypto_stream.cc
blob8561ab7f5fcac5e53681df0f7828ced0491ae979
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"
7 #include <string>
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"
16 using std::string;
17 using base::StringPiece;
19 namespace net {
21 #define ENDPOINT \
22 (session()->perspective() == Perspective::IS_SERVER ? "Server: " : "Client:" \
23 " ")
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() {
46 struct iovec iov;
47 while (true) {
48 if (sequencer()->GetReadableRegions(&iov, 1) != 1) {
49 // No more data to read.
50 break;
52 StringPiece data(static_cast<char*>(iov.iov_base), iov.iov_len);
53 if (!crypto_framer_.ProcessInput(data)) {
54 CloseConnection(crypto_framer_.error());
55 return;
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(
81 StringPiece label,
82 StringPiece context,
83 size_t result_len,
84 string* result) const {
85 if (!handshake_confirmed()) {
86 DLOG(ERROR) << "ExportKeyingMaterial was called before forward-secure"
87 << "encryption was established.";
88 return false;
90 return CryptoUtils::ExportKeyingMaterial(
91 crypto_negotiated_params_.subkey_secret,
92 label,
93 context,
94 result_len,
95 result);
98 const QuicCryptoNegotiatedParameters&
99 QuicCryptoStream::crypto_negotiated_params() const {
100 return crypto_negotiated_params_;
103 } // namespace net