Andrew Top | 0d1858f | 2019-05-15 22:01:47 -0700 | [diff] [blame] | 1 | // Copyright 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_CERT_CT_VERIFIER_H_ |
| 6 | #define NET_CERT_CT_VERIFIER_H_ |
| 7 | |
| 8 | #include "base/strings/string_piece.h" |
| 9 | #include "net/base/net_export.h" |
| 10 | #include "net/cert/signed_certificate_timestamp_and_status.h" |
| 11 | |
| 12 | namespace net { |
| 13 | |
| 14 | class NetLogWithSource; |
| 15 | class X509Certificate; |
| 16 | |
| 17 | // Interface for verifying Signed Certificate Timestamps over a certificate. |
| 18 | class NET_EXPORT CTVerifier { |
| 19 | public: |
| 20 | class NET_EXPORT Observer { |
| 21 | public: |
| 22 | // Called for each Signed Certificate Timestamp from a known log that vas |
| 23 | // verified successfully (i.e. the signature verifies). |sct| is the |
| 24 | // Signed Certificate Timestamp, |cert| is the certificate it applies to and |
| 25 | // |hostname| is the server that presented the certificate (DNS name or IP |
| 26 | // address literal). The certificate is needed to calculate the hash of the |
| 27 | // log entry, necessary for checking inclusion in the log. |
| 28 | // Note: The observer (whose implementation is expected to exist outside |
| 29 | // net/) may store the observed |cert| and |sct|. |
| 30 | virtual void OnSCTVerified(base::StringPiece hostname, |
| 31 | X509Certificate* cert, |
| 32 | const ct::SignedCertificateTimestamp* sct) = 0; |
| 33 | |
| 34 | protected: |
| 35 | virtual ~Observer() {} |
| 36 | }; |
| 37 | |
| 38 | virtual ~CTVerifier() {} |
| 39 | |
| 40 | // Verifies SCTs embedded in the certificate itself, SCTs embedded in a |
| 41 | // stapled OCSP response, and SCTs obtained via the |
| 42 | // signed_certificate_timestamp TLS extension on the given |cert|. |
| 43 | // A certificate is permitted but not required to use multiple sources for |
| 44 | // SCTs. It is expected that most certificates will use only one source |
| 45 | // (embedding, TLS extension or OCSP stapling). If no stapled OCSP response |
| 46 | // is available, |stapled_ocsp_response| should be an empty string. If no SCT |
| 47 | // TLS extension was negotiated, |sct_list_from_tls_extension| should be an |
| 48 | // empty string. |output_scts| will be cleared and filled with the SCTs |
| 49 | // present, if any, along with their verification results. |
| 50 | // The |hostname| (or IP address literal) of the server that presented |cert| |
| 51 | // must be provided so that inclusion checks for |cert| are able to avoid |
| 52 | // leaking information about which servers have been visited. |
| 53 | virtual void Verify(base::StringPiece hostname, |
| 54 | X509Certificate* cert, |
| 55 | base::StringPiece stapled_ocsp_response, |
| 56 | base::StringPiece sct_list_from_tls_extension, |
| 57 | SignedCertificateTimestampAndStatusList* output_scts, |
| 58 | const NetLogWithSource& net_log) = 0; |
| 59 | |
| 60 | // Registers |observer| to receive notifications of validated SCTs. Does not |
| 61 | // take ownership of the observer as the observer may be performing |
| 62 | // URLRequests which have to be cancelled before this object is destroyed. |
| 63 | // Setting |observer| to nullptr has the effect of stopping all notifications. |
| 64 | virtual void SetObserver(Observer* observer) = 0; |
| 65 | |
| 66 | // Gets the Observer, if any, that is currently receiving notifications of |
| 67 | // validated SCTs. |
| 68 | virtual Observer* GetObserver() const = 0; |
| 69 | }; |
| 70 | |
| 71 | } // namespace net |
| 72 | |
| 73 | #endif // NET_CERT_CT_VERIFIER_H_ |