blob: 92c68b65d3f10a98bec9ade2510a4fd2c9ad8317 [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// Copyright (c) 2017 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.
4
5#ifndef QUICHE_QUIC_QUARTC_QUARTC_CRYPTO_HELPERS_H_
6#define QUICHE_QUIC_QUARTC_QUARTC_CRYPTO_HELPERS_H_
7
vasilvv872e7a32019-03-12 16:42:44 -07008#include <string>
9
QUICHE teama6ef0a62019-03-07 20:34:33 -050010#include "net/third_party/quiche/src/quic/core/crypto/crypto_handshake_message.h"
11#include "net/third_party/quiche/src/quic/core/crypto/proof_source.h"
12#include "net/third_party/quiche/src/quic/core/crypto/proof_verifier.h"
13#include "net/third_party/quiche/src/quic/core/crypto/quic_crypto_client_config.h"
14#include "net/third_party/quiche/src/quic/core/crypto/quic_crypto_server_config.h"
15#include "net/third_party/quiche/src/quic/core/quic_connection_id.h"
16#include "net/third_party/quiche/src/quic/core/quic_crypto_server_stream.h"
17#include "net/third_party/quiche/src/quic/core/quic_versions.h"
18#include "net/third_party/quiche/src/quic/platform/api/quic_reference_counted.h"
19#include "net/third_party/quiche/src/quic/platform/api/quic_socket_address.h"
dmcardlec60e87a2019-12-12 09:43:19 -080020#include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050021
22namespace quic {
23
24// Never, ever, change this certificate name. You will break 0-rtt handshake if
25// you do.
26static constexpr char kDummyCertName[] = "Dummy cert";
27
28struct CryptoServerConfig {
29 std::unique_ptr<QuicCryptoServerConfig> config;
vasilvvc48c8712019-03-11 13:38:16 -070030 std::string serialized_crypto_config;
QUICHE teama6ef0a62019-03-07 20:34:33 -050031};
32
33// Length of HKDF input keying material, equal to its number of bytes.
34// https://tools.ietf.org/html/rfc5869#section-2.2.
35// TODO(zhihuang): Verify that input keying material length is correct.
36constexpr size_t kInputKeyingMaterialLength = 32;
37
38// Used by QuicCryptoServerConfig to provide dummy proof credentials.
39// TODO(zhihuang): Remove when secure P2P QUIC handshake is possible.
40class DummyProofSource : public ProofSource {
41 public:
42 DummyProofSource() {}
43 ~DummyProofSource() override {}
44
45 // ProofSource overrides.
46 void GetProof(const QuicSocketAddress& server_address,
vasilvvc48c8712019-03-11 13:38:16 -070047 const std::string& hostname,
48 const std::string& server_config,
QUICHE teama6ef0a62019-03-07 20:34:33 -050049 QuicTransportVersion transport_version,
dmcardlec60e87a2019-12-12 09:43:19 -080050 quiche::QuicheStringPiece chlo_hash,
QUICHE teama6ef0a62019-03-07 20:34:33 -050051 std::unique_ptr<Callback> callback) override;
52
53 QuicReferenceCountedPointer<Chain> GetCertChain(
54 const QuicSocketAddress& server_address,
vasilvvc48c8712019-03-11 13:38:16 -070055 const std::string& hostname) override;
QUICHE teama6ef0a62019-03-07 20:34:33 -050056
57 void ComputeTlsSignature(
58 const QuicSocketAddress& server_address,
vasilvvc48c8712019-03-11 13:38:16 -070059 const std::string& hostname,
QUICHE teama6ef0a62019-03-07 20:34:33 -050060 uint16_t signature_algorithm,
dmcardlec60e87a2019-12-12 09:43:19 -080061 quiche::QuicheStringPiece in,
QUICHE teama6ef0a62019-03-07 20:34:33 -050062 std::unique_ptr<SignatureCallback> callback) override;
63};
64
65// Used by QuicCryptoClientConfig to ignore the peer's credentials
66// and establish an insecure QUIC connection.
67// TODO(zhihuang): Remove when secure P2P QUIC handshake is possible.
68class InsecureProofVerifier : public ProofVerifier {
69 public:
70 InsecureProofVerifier() {}
71 ~InsecureProofVerifier() override {}
72
73 // ProofVerifier overrides.
74 QuicAsyncStatus VerifyProof(
vasilvvc48c8712019-03-11 13:38:16 -070075 const std::string& hostname,
QUICHE teama6ef0a62019-03-07 20:34:33 -050076 const uint16_t port,
vasilvvc48c8712019-03-11 13:38:16 -070077 const std::string& server_config,
QUICHE teama6ef0a62019-03-07 20:34:33 -050078 QuicTransportVersion transport_version,
dmcardlec60e87a2019-12-12 09:43:19 -080079 quiche::QuicheStringPiece chlo_hash,
vasilvvc48c8712019-03-11 13:38:16 -070080 const std::vector<std::string>& certs,
81 const std::string& cert_sct,
82 const std::string& signature,
QUICHE teama6ef0a62019-03-07 20:34:33 -050083 const ProofVerifyContext* context,
vasilvvc48c8712019-03-11 13:38:16 -070084 std::string* error_details,
QUICHE teama6ef0a62019-03-07 20:34:33 -050085 std::unique_ptr<ProofVerifyDetails>* verify_details,
86 std::unique_ptr<ProofVerifierCallback> callback) override;
87
88 QuicAsyncStatus VerifyCertChain(
vasilvvc48c8712019-03-11 13:38:16 -070089 const std::string& hostname,
90 const std::vector<std::string>& certs,
QUICHE team38c190b2019-05-08 09:12:01 -070091 const std::string& ocsp_response,
92 const std::string& cert_sct,
QUICHE teama6ef0a62019-03-07 20:34:33 -050093 const ProofVerifyContext* context,
vasilvvc48c8712019-03-11 13:38:16 -070094 std::string* error_details,
QUICHE teama6ef0a62019-03-07 20:34:33 -050095 std::unique_ptr<ProofVerifyDetails>* details,
96 std::unique_ptr<ProofVerifierCallback> callback) override;
97
98 std::unique_ptr<ProofVerifyContext> CreateDefaultContext() override;
99};
100
101// Implementation of the server-side crypto stream helper.
nharper5f23a2d2020-02-20 10:44:09 -0800102class QuartcCryptoServerStreamHelper
103 : public QuicCryptoServerStreamBase::Helper {
QUICHE teama6ef0a62019-03-07 20:34:33 -0500104 public:
QUICHE teama6ef0a62019-03-07 20:34:33 -0500105 bool CanAcceptClientHello(const CryptoHandshakeMessage& message,
106 const QuicSocketAddress& client_address,
107 const QuicSocketAddress& peer_address,
108 const QuicSocketAddress& self_address,
vasilvvc48c8712019-03-11 13:38:16 -0700109 std::string* error_details) const override;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500110};
111
112std::unique_ptr<QuicCryptoClientConfig> CreateCryptoClientConfig(
dmcardlec60e87a2019-12-12 09:43:19 -0800113 quiche::QuicheStringPiece pre_shared_key);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500114
dmcardlec60e87a2019-12-12 09:43:19 -0800115CryptoServerConfig CreateCryptoServerConfig(
116 QuicRandom* random,
117 const QuicClock* clock,
118 quiche::QuicheStringPiece pre_shared_key);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500119
120} // namespace quic
121
122#endif // QUICHE_QUIC_QUARTC_QUARTC_CRYPTO_HELPERS_H_