QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1 | // 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> |
vasilvv | 872e7a3 | 2019-03-12 16:42:44 -0700 | [diff] [blame] | 9 | #include <string> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10 | #include <vector> |
| 11 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12 | #include "net/third_party/quiche/src/quic/core/quic_types.h" |
danzh | 1450868 | 2019-05-09 08:10:40 -0700 | [diff] [blame] | 13 | #include "net/third_party/quiche/src/quic/core/quic_versions.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 14 | #include "net/third_party/quiche/src/quic/platform/api/quic_export.h" |
dmcardle | 904ef18 | 2019-12-13 08:34:33 -0800 | [diff] [blame] | 15 | #include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 16 | |
| 17 | namespace 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. |
| 22 | class 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. |
| 33 | class 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. |
| 40 | class 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, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 51 | const std::string& error_details, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 52 | 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. |
| 57 | class 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( |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 78 | const std::string& hostname, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 79 | const uint16_t port, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 80 | const std::string& server_config, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 81 | QuicTransportVersion transport_version, |
dmcardle | 904ef18 | 2019-12-13 08:34:33 -0800 | [diff] [blame] | 82 | quiche::QuicheStringPiece chlo_hash, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 83 | const std::vector<std::string>& certs, |
| 84 | const std::string& cert_sct, |
| 85 | const std::string& signature, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 86 | const ProofVerifyContext* context, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 87 | std::string* error_details, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 88 | 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( |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 104 | const std::string& hostname, |
| 105 | const std::vector<std::string>& certs, |
QUICHE team | 38c190b | 2019-05-08 09:12:01 -0700 | [diff] [blame] | 106 | const std::string& ocsp_response, |
| 107 | const std::string& cert_sct, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 108 | const ProofVerifyContext* context, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 109 | std::string* error_details, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 110 | 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_ |