blob: cdf14a040eb302f428ee72ecf032db96a29f126c [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"
QUICHE teama6ef0a62019-03-07 20:34:33 -050020#include "net/third_party/quiche/src/quic/platform/api/quic_string_piece.h"
21
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,
50 QuicStringPiece chlo_hash,
51 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,
61 QuicStringPiece in,
62 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,
79 QuicStringPiece 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.
102class QuartcCryptoServerStreamHelper : public QuicCryptoServerStream::Helper {
103 public:
QUICHE teama6ef0a62019-03-07 20:34:33 -0500104 bool CanAcceptClientHello(const CryptoHandshakeMessage& message,
105 const QuicSocketAddress& client_address,
106 const QuicSocketAddress& peer_address,
107 const QuicSocketAddress& self_address,
vasilvvc48c8712019-03-11 13:38:16 -0700108 std::string* error_details) const override;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500109};
110
111std::unique_ptr<QuicCryptoClientConfig> CreateCryptoClientConfig(
112 QuicStringPiece pre_shared_key);
113
114CryptoServerConfig CreateCryptoServerConfig(QuicRandom* random,
115 const QuicClock* clock,
116 QuicStringPiece pre_shared_key);
117
118} // namespace quic
119
120#endif // QUICHE_QUIC_QUARTC_QUARTC_CRYPTO_HELPERS_H_