Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / net / quic / p2p / quic_p2p_crypto_stream.cc
blobc8a3e6c4a94014d8399243053d60614e25dcc949
1 // Copyright 2015 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/p2p/quic_p2p_crypto_stream.h"
7 #include "crypto/hkdf.h"
8 #include "net/quic/crypto/crypto_handshake_message.h"
9 #include "net/quic/crypto/quic_decrypter.h"
10 #include "net/quic/crypto/quic_encrypter.h"
11 #include "net/quic/quic_session.h"
13 namespace net {
15 QuicP2PCryptoStream::QuicP2PCryptoStream(QuicSession* session,
16 const QuicP2PCryptoConfig& config)
17 : QuicCryptoStream(session), config_(config) {}
19 QuicP2PCryptoStream::~QuicP2PCryptoStream() {}
21 bool QuicP2PCryptoStream::Connect() {
22 if (!config_.GetNegotiatedParameters(session()->connection()->perspective(),
23 &crypto_negotiated_params_)) {
24 return false;
27 CrypterPair* crypters = &crypto_negotiated_params_.forward_secure_crypters;
29 session()->connection()->SetEncrypter(ENCRYPTION_FORWARD_SECURE,
30 crypters->encrypter.release());
31 session()->connection()->SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE);
32 session()->connection()->SetAlternativeDecrypter(
33 ENCRYPTION_FORWARD_SECURE, crypters->decrypter.release(),
34 false /* don't latch */);
35 encryption_established_ = true;
36 session()->OnCryptoHandshakeEvent(QuicSession::ENCRYPTION_FIRST_ESTABLISHED);
37 session()->OnConfigNegotiated();
38 session()->connection()->OnHandshakeComplete();
39 handshake_confirmed_ = true;
40 session()->OnCryptoHandshakeEvent(QuicSession::HANDSHAKE_CONFIRMED);
42 return true;
45 } // namespace net