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 NET_QUIC_CRYPTO_PROOF_VERIFIER_H_ 6 #define NET_QUIC_CRYPTO_PROOF_VERIFIER_H_ 7 8 #include <string> 9 #include <vector> 10 11 #include "base/memory/scoped_ptr.h" 12 #include "net/base/net_export.h" 13 #include "net/quic/quic_types.h" 14 15 namespace net { 16 17 // ProofVerifyDetails is an abstract class that acts as a container for any 18 // implementation specific details that a ProofVerifier wishes to return. These 19 // details are saved in the CachedState for the origin in question. 20 class NET_EXPORT_PRIVATE ProofVerifyDetails { 21 public: 22 virtual ~ProofVerifyDetails() {} 23 }; 24 25 // ProofVerifyContext is an abstract class that acts as a container for any 26 // implementation specific context that a ProofVerifier needs. 27 class NET_EXPORT_PRIVATE ProofVerifyContext { 28 public: 29 virtual ~ProofVerifyContext() {} 30 }; 31 32 // ProofVerifierCallback provides a generic mechanism for a ProofVerifier to 33 // call back after an asynchronous verification. 34 class NET_EXPORT_PRIVATE ProofVerifierCallback { 35 public: 36 virtual ~ProofVerifierCallback() {} 37 38 // Run is called on the original thread to mark the completion of an 39 // asynchonous verification. If |ok| is true then the certificate is valid 40 // and |error_details| is unused. Otherwise, |error_details| contains a 41 // description of the error. |details| contains implementation-specific 42 // details of the verification. |Run| may take ownership of |details| by 43 // calling |release| on it. 44 virtual void Run(bool ok, 45 const std::string& error_details, 46 scoped_ptr<ProofVerifyDetails>* details) = 0; 47 }; 48 49 // A ProofVerifier checks the signature on a server config, and the certificate 50 // chain that backs the public key. 51 class NET_EXPORT_PRIVATE ProofVerifier { 52 public: 53 virtual ~ProofVerifier() {} 54 55 // VerifyProof checks that |signature| is a valid signature of 56 // |server_config| by the public key in the leaf certificate of |certs|, and 57 // that |certs| is a valid chain for |hostname|. On success, it returns 58 // QUIC_SUCCESS. On failure, it returns QUIC_FAILURE and sets |*error_details| 59 // to a description of the problem. In either case it may set |*details|, 60 // which the caller takes ownership of. 61 // 62 // |context| specifies an implementation specific struct (which may be NULL 63 // for some implementations) that provides useful information for the 64 // verifier, e.g. logging handles. 65 // 66 // This function may also return QUIC_PENDING, in which case the ProofVerifier 67 // will call back, on the original thread, via |callback| when complete. 68 // In this case, the ProofVerifier will take ownership of |callback|. 69 // 70 // The signature uses SHA-256 as the hash function and PSS padding in the 71 // case of RSA. 72 virtual QuicAsyncStatus VerifyProof(const std::string& hostname, 73 const std::string& server_config, 74 const std::vector<std::string>& certs, 75 const std::string& signature, 76 const ProofVerifyContext* context, 77 std::string* error_details, 78 scoped_ptr<ProofVerifyDetails>* details, 79 ProofVerifierCallback* callback) = 0; 80 }; 81 82 } // namespace net 83 84 #endif // NET_QUIC_CRYPTO_PROOF_VERIFIER_H_ 85