Bug 1869043 allow a device to be specified with MediaTrackGraph::NotifyWhenDeviceStar...
[gecko.git] / security / ct / CTLogVerifier.h
blob659698b4a1414d357240aa817fb1dd015b494be0
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef CTLogVerifier_h
8 #define CTLogVerifier_h
10 #include <memory>
12 #include "CTLog.h"
13 #include "CTUtils.h"
14 #include "SignedCertificateTimestamp.h"
15 #include "mozpkix/Input.h"
16 #include "mozpkix/Result.h"
17 #include "mozpkix/pkix.h"
19 namespace mozilla {
20 namespace ct {
22 // Verifies Signed Certificate Timestamps (SCTs) provided by a specific log
23 // using the public key of that log. Assumes the SCT being verified
24 // matches the log by log key ID and signature parameters (an error is returned
25 // otherwise).
26 // The verification functions return Success if the provided SCT has passed
27 // verification, ERROR_BAD_SIGNATURE if failed verification, or other result
28 // on error.
29 class CTLogVerifier {
30 public:
31 CTLogVerifier();
33 // Initializes the verifier with log-specific information. Only the public
34 // key is used for verification, other parameters are purely informational.
35 // |subjectPublicKeyInfo| is a DER-encoded SubjectPublicKeyInfo.
36 // |operatorId| The numeric ID of the log operator as assigned at
37 // https://www.certificate-transparency.org/known-logs .
38 // |logStatus| Either "Included" or "Disqualified".
39 // |disqualificationTime| Disqualification timestamp (for disqualified logs).
40 // An error is returned if |subjectPublicKeyInfo| refers to an unsupported
41 // public key.
42 pkix::Result Init(pkix::Input subjectPublicKeyInfo,
43 CTLogOperatorId operatorId, CTLogStatus logStatus,
44 uint64_t disqualificationTime);
46 // Returns the log's key ID, which is a SHA256 hash of its public key.
47 // See RFC 6962, Section 3.2.
48 const Buffer& keyId() const { return mKeyId; }
50 CTLogOperatorId operatorId() const { return mOperatorId; }
51 bool isDisqualified() const { return mDisqualified; }
52 uint64_t disqualificationTime() const { return mDisqualificationTime; }
54 // Verifies that |sct| contains a valid signature for |entry|.
55 // |sct| must be signed by the verifier's log.
56 pkix::Result Verify(const LogEntry& entry,
57 const SignedCertificateTimestamp& sct);
59 // Returns true if the signature and hash algorithms in |signature|
60 // match those of the log.
61 bool SignatureParametersMatch(const DigitallySigned& signature);
63 private:
64 // Performs the underlying verification using the log's public key. Note
65 // that |signature| contains the raw signature data (i.e. without any
66 // DigitallySigned struct encoding).
67 // Returns Success if passed verification, ERROR_BAD_SIGNATURE if failed
68 // verification, or other result on error.
69 pkix::Result VerifySignature(pkix::Input data, pkix::Input signature);
70 pkix::Result VerifySignature(const Buffer& data, const Buffer& signature);
72 // mPublicECKey works around an architectural deficiency in NSS. In the case
73 // of EC, if we don't create, import, and cache this key, NSS will import and
74 // verify it every signature verification, which is slow. For RSA, this is
75 // unused and will be null.
76 UniqueSECKEYPublicKey mPublicECKey;
77 Buffer mSubjectPublicKeyInfo;
78 Buffer mKeyId;
79 DigitallySigned::SignatureAlgorithm mSignatureAlgorithm;
80 CTLogOperatorId mOperatorId;
81 bool mDisqualified;
82 uint64_t mDisqualificationTime;
85 } // namespace ct
86 } // namespace mozilla
88 #endif // CTLogVerifier_h