blob: fd890987d5d515aeaf8d9c49542be2e2eb82de8c [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// Copyright (c) 2013 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_CORE_CRYPTO_PROOF_SOURCE_H_
6#define QUICHE_QUIC_CORE_CRYPTO_PROOF_SOURCE_H_
7
8#include <memory>
vasilvv872e7a32019-03-12 16:42:44 -07009#include <string>
QUICHE teama6ef0a62019-03-07 20:34:33 -050010#include <vector>
11
12#include "net/third_party/quiche/src/quic/core/crypto/quic_crypto_proof.h"
danzh14508682019-05-09 08:10:40 -070013#include "net/third_party/quiche/src/quic/core/quic_versions.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050014#include "net/third_party/quiche/src/quic/platform/api/quic_export.h"
15#include "net/third_party/quiche/src/quic/platform/api/quic_reference_counted.h"
16#include "net/third_party/quiche/src/quic/platform/api/quic_socket_address.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050017#include "net/third_party/quiche/src/quic/platform/api/quic_string_piece.h"
18
19namespace quic {
20
21// ProofSource is an interface by which a QUIC server can obtain certificate
22// chains and signatures that prove its identity.
23class QUIC_EXPORT_PRIVATE ProofSource {
24 public:
25 // Chain is a reference-counted wrapper for a vector of stringified
26 // certificates.
27 struct QUIC_EXPORT_PRIVATE Chain : public QuicReferenceCounted {
vasilvvc48c8712019-03-11 13:38:16 -070028 explicit Chain(const std::vector<std::string>& certs);
QUICHE teama6ef0a62019-03-07 20:34:33 -050029 Chain(const Chain&) = delete;
30 Chain& operator=(const Chain&) = delete;
31
vasilvvc48c8712019-03-11 13:38:16 -070032 const std::vector<std::string> certs;
QUICHE teama6ef0a62019-03-07 20:34:33 -050033
34 protected:
35 ~Chain() override;
36 };
37
38 // Details is an abstract class which acts as a container for any
39 // implementation-specific details that a ProofSource wants to return.
40 class Details {
41 public:
42 virtual ~Details() {}
43 };
44
45 // Callback base class for receiving the results of an async call to GetProof.
46 class Callback {
47 public:
48 Callback() {}
49 virtual ~Callback() {}
50
51 // Invoked upon completion of GetProof.
52 //
53 // |ok| indicates whether the operation completed successfully. If false,
54 // the values of the remaining three arguments are undefined.
55 //
56 // |chain| is a reference-counted pointer to an object representing the
57 // certificate chain.
58 //
59 // |signature| contains the signature of the server config.
60 //
61 // |leaf_cert_sct| holds the signed timestamp (RFC6962) of the leaf cert.
62 //
63 // |details| holds a pointer to an object representing the statistics, if
64 // any, gathered during the operation of GetProof. If no stats are
65 // available, this will be nullptr.
66 virtual void Run(bool ok,
67 const QuicReferenceCountedPointer<Chain>& chain,
68 const QuicCryptoProof& proof,
69 std::unique_ptr<Details> details) = 0;
70
71 private:
72 Callback(const Callback&) = delete;
73 Callback& operator=(const Callback&) = delete;
74 };
75
76 // Base class for signalling the completion of a call to ComputeTlsSignature.
77 class SignatureCallback {
78 public:
79 SignatureCallback() {}
80 virtual ~SignatureCallback() = default;
81
82 // Invoked upon completion of ComputeTlsSignature.
83 //
84 // |ok| indicates whether the operation completed successfully.
85 //
86 // |signature| contains the signature of the data provided to
87 // ComputeTlsSignature. Its value is undefined if |ok| is false.
vasilvvc48c8712019-03-11 13:38:16 -070088 virtual void Run(bool ok, std::string signature) = 0;
QUICHE teama6ef0a62019-03-07 20:34:33 -050089
90 private:
91 SignatureCallback(const SignatureCallback&) = delete;
92 SignatureCallback& operator=(const SignatureCallback&) = delete;
93 };
94
95 virtual ~ProofSource() {}
96
97 // GetProof finds a certificate chain for |hostname| (in leaf-first order),
98 // and calculates a signature of |server_config| using that chain.
99 //
100 // The signature uses SHA-256 as the hash function and PSS padding when the
101 // key is RSA.
102 //
103 // The signature uses SHA-256 as the hash function when the key is ECDSA.
104 // The signature may use an ECDSA key.
105 //
106 // The signature depends on |chlo_hash| which means that the signature can not
107 // be cached.
108 //
109 // |hostname| may be empty to signify that a default certificate should be
110 // used.
111 //
112 // This function may be called concurrently.
113 //
114 // Callers should expect that |callback| might be invoked synchronously.
115 virtual void GetProof(const QuicSocketAddress& server_address,
vasilvvc48c8712019-03-11 13:38:16 -0700116 const std::string& hostname,
117 const std::string& server_config,
QUICHE teama6ef0a62019-03-07 20:34:33 -0500118 QuicTransportVersion transport_version,
119 QuicStringPiece chlo_hash,
120 std::unique_ptr<Callback> callback) = 0;
121
122 // Returns the certificate chain for |hostname| in leaf-first order.
123 virtual QuicReferenceCountedPointer<Chain> GetCertChain(
124 const QuicSocketAddress& server_address,
vasilvvc48c8712019-03-11 13:38:16 -0700125 const std::string& hostname) = 0;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500126
127 // Computes a signature using the private key of the certificate for
128 // |hostname|. The value in |in| is signed using the algorithm specified by
129 // |signature_algorithm|, which is an |SSL_SIGN_*| value (as defined in TLS
130 // 1.3). Implementations can only assume that |in| is valid during the call to
131 // ComputeTlsSignature - an implementation computing signatures asynchronously
132 // must copy it if the value to be signed is used outside of this function.
133 //
134 // Callers should expect that |callback| might be invoked synchronously.
135 virtual void ComputeTlsSignature(
136 const QuicSocketAddress& server_address,
vasilvvc48c8712019-03-11 13:38:16 -0700137 const std::string& hostname,
QUICHE teama6ef0a62019-03-07 20:34:33 -0500138 uint16_t signature_algorithm,
139 QuicStringPiece in,
140 std::unique_ptr<SignatureCallback> callback) = 0;
141};
142
143} // namespace quic
144
145#endif // QUICHE_QUIC_CORE_CRYPTO_PROOF_SOURCE_H_