1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/quic/quic_crypto_client_stream.h"
#include "net/quic/crypto/crypto_protocol.h"
#include "net/quic/crypto/crypto_utils.h"
#include "net/quic/quic_protocol.h"
#include "net/quic/quic_session.h"
namespace net {
QuicCryptoClientStream::QuicCryptoClientStream(QuicSession* session,
const string& server_hostname)
: QuicCryptoStream(session),
server_hostname_(server_hostname) {
config_.SetDefaults();
QuicGuid guid = session->connection()->guid();
crypto_config_.hkdf_info.append(reinterpret_cast<char*>(&guid),
sizeof(guid));
}
QuicCryptoClientStream::~QuicCryptoClientStream() {
}
void QuicCryptoClientStream::OnHandshakeMessage(
const CryptoHandshakeMessage& message) {
// Do not process handshake messages after the handshake is complete.
if (handshake_complete()) {
CloseConnection(QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE);
return;
}
if (message.tag != kSHLO) {
CloseConnection(QUIC_INVALID_CRYPTO_MESSAGE_TYPE);
return;
}
string error_details;
QuicErrorCode error = config_.ProcessPeerHandshake(
message,
CryptoUtils::PEER_PRIORITY,
&negotiated_params_,
&error_details);
if (error != QUIC_NO_ERROR) {
CloseConnectionWithDetails(error, error_details);
return;
}
QuicErrorCode err = crypto_config_.ProcessServerHello(
message, nonce_, &crypto_negotiated_params_, &error_details);
if (err != QUIC_NO_ERROR) {
CloseConnectionWithDetails(err, error_details);
return;
}
SetHandshakeComplete(QUIC_NO_ERROR);
return;
}
bool QuicCryptoClientStream::CryptoConnect() {
crypto_config_.SetDefaults(session()->connection()->random_generator());
CryptoUtils::GenerateNonce(session()->connection()->clock(),
session()->connection()->random_generator(),
&nonce_);
CryptoHandshakeMessage message;
crypto_config_.FillClientHello(nonce_, server_hostname_, &message);
config_.ToHandshakeMessage(&message);
const QuicData& data = message.GetSerialized();
crypto_config_.hkdf_info.append(data.data(), data.length());
SendHandshakeMessage(message);
return true;
}
} // namespace net
|