blob: 12036d69887fa38a70a2a976ca29263eb9b484c9 [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_VERIFIER_H_
6#define QUICHE_QUIC_CORE_CRYPTO_PROOF_VERIFIER_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
QUICHE teama6ef0a62019-03-07 20:34:33 -050012#include "net/third_party/quiche/src/quic/core/quic_types.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"
dmcardle904ef182019-12-13 08:34:33 -080015#include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050016
17namespace quic {
18
19// ProofVerifyDetails is an abstract class that acts as a container for any
20// implementation specific details that a ProofVerifier wishes to return. These
21// details are saved in the CachedState for the origin in question.
22class QUIC_EXPORT_PRIVATE ProofVerifyDetails {
23 public:
24 virtual ~ProofVerifyDetails() {}
25
26 // Returns an new ProofVerifyDetails object with the same contents
27 // as this one.
28 virtual ProofVerifyDetails* Clone() const = 0;
29};
30
31// ProofVerifyContext is an abstract class that acts as a container for any
32// implementation specific context that a ProofVerifier needs.
33class QUIC_EXPORT_PRIVATE ProofVerifyContext {
34 public:
35 virtual ~ProofVerifyContext() {}
36};
37
38// ProofVerifierCallback provides a generic mechanism for a ProofVerifier to
39// call back after an asynchronous verification.
40class QUIC_EXPORT_PRIVATE ProofVerifierCallback {
41 public:
42 virtual ~ProofVerifierCallback() {}
43
44 // Run is called on the original thread to mark the completion of an
45 // asynchonous verification. If |ok| is true then the certificate is valid
46 // and |error_details| is unused. Otherwise, |error_details| contains a
47 // description of the error. |details| contains implementation-specific
48 // details of the verification. |Run| may take ownership of |details| by
49 // calling |release| on it.
50 virtual void Run(bool ok,
vasilvvc48c8712019-03-11 13:38:16 -070051 const std::string& error_details,
QUICHE teama6ef0a62019-03-07 20:34:33 -050052 std::unique_ptr<ProofVerifyDetails>* details) = 0;
53};
54
55// A ProofVerifier checks the signature on a server config, and the certificate
56// chain that backs the public key.
57class QUIC_EXPORT_PRIVATE ProofVerifier {
58 public:
59 virtual ~ProofVerifier() {}
60
61 // VerifyProof checks that |signature| is a valid signature of
62 // |server_config| by the public key in the leaf certificate of |certs|, and
63 // that |certs| is a valid chain for |hostname|. On success, it returns
64 // QUIC_SUCCESS. On failure, it returns QUIC_FAILURE and sets |*error_details|
65 // to a description of the problem. In either case it may set |*details|,
66 // which the caller takes ownership of.
67 //
68 // |context| specifies an implementation specific struct (which may be nullptr
69 // for some implementations) that provides useful information for the
70 // verifier, e.g. logging handles.
71 //
72 // This function may also return QUIC_PENDING, in which case the ProofVerifier
73 // will call back, on the original thread, via |callback| when complete.
74 //
75 // The signature uses SHA-256 as the hash function and PSS padding in the
76 // case of RSA.
77 virtual QuicAsyncStatus VerifyProof(
vasilvvc48c8712019-03-11 13:38:16 -070078 const std::string& hostname,
QUICHE teama6ef0a62019-03-07 20:34:33 -050079 const uint16_t port,
vasilvvc48c8712019-03-11 13:38:16 -070080 const std::string& server_config,
QUICHE teama6ef0a62019-03-07 20:34:33 -050081 QuicTransportVersion transport_version,
dmcardle904ef182019-12-13 08:34:33 -080082 quiche::QuicheStringPiece chlo_hash,
vasilvvc48c8712019-03-11 13:38:16 -070083 const std::vector<std::string>& certs,
84 const std::string& cert_sct,
85 const std::string& signature,
QUICHE teama6ef0a62019-03-07 20:34:33 -050086 const ProofVerifyContext* context,
vasilvvc48c8712019-03-11 13:38:16 -070087 std::string* error_details,
QUICHE teama6ef0a62019-03-07 20:34:33 -050088 std::unique_ptr<ProofVerifyDetails>* details,
89 std::unique_ptr<ProofVerifierCallback> callback) = 0;
90
91 // VerifyCertChain checks that |certs| is a valid chain for |hostname|. On
92 // success, it returns QUIC_SUCCESS. On failure, it returns QUIC_FAILURE and
93 // sets |*error_details| to a description of the problem. In either case it
94 // may set |*details|, which the caller takes ownership of.
95 //
96 // |context| specifies an implementation specific struct (which may be nullptr
97 // for some implementations) that provides useful information for the
98 // verifier, e.g. logging handles.
99 //
100 // This function may also return QUIC_PENDING, in which case the ProofVerifier
101 // will call back, on the original thread, via |callback| when complete.
102 // In this case, the ProofVerifier will take ownership of |callback|.
103 virtual QuicAsyncStatus VerifyCertChain(
vasilvvc48c8712019-03-11 13:38:16 -0700104 const std::string& hostname,
105 const std::vector<std::string>& certs,
QUICHE team38c190b2019-05-08 09:12:01 -0700106 const std::string& ocsp_response,
107 const std::string& cert_sct,
QUICHE teama6ef0a62019-03-07 20:34:33 -0500108 const ProofVerifyContext* context,
vasilvvc48c8712019-03-11 13:38:16 -0700109 std::string* error_details,
QUICHE teama6ef0a62019-03-07 20:34:33 -0500110 std::unique_ptr<ProofVerifyDetails>* details,
111 std::unique_ptr<ProofVerifierCallback> callback) = 0;
112
113 // Returns a ProofVerifyContext instance which can be use for subsequent
114 // verifications. Applications may chose create a different context and
115 // supply it for verifications instead.
116 virtual std::unique_ptr<ProofVerifyContext> CreateDefaultContext() = 0;
117};
118
119} // namespace quic
120
121#endif // QUICHE_QUIC_CORE_CRYPTO_PROOF_VERIFIER_H_