Bug 1899500 - Implement explicit resource management in Baseline compiler. r=arai
[gecko.git] / security / ct / CTLogVerifier.h
blob9f52c688fa14f296c5819f67655450201cf137e1
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 "CTKnownLogs.h"
13 #include "CTLog.h"
14 #include "CTUtils.h"
15 #include "SignedCertificateTimestamp.h"
16 #include "mozpkix/Input.h"
17 #include "mozpkix/Result.h"
18 #include "mozpkix/pkix.h"
20 namespace mozilla {
21 namespace ct {
23 // Verifies Signed Certificate Timestamps (SCTs) provided by a specific log
24 // using the public key of that log. Assumes the SCT being verified
25 // matches the log by log key ID and signature parameters (an error is returned
26 // otherwise).
27 // The verification functions return Success if the provided SCT has passed
28 // verification, ERROR_BAD_SIGNATURE if failed verification, or other result
29 // on error.
30 class CTLogVerifier {
31 public:
32 // |operatorId| The numeric ID of the log operator.
33 // |logState| "Qualified", "Usable", "ReadOnly", or "Retired".
34 // |timestamp| timestamp associated with logState.
35 CTLogVerifier(CTLogOperatorId operatorId, CTLogState logState,
36 uint64_t timestamp);
38 // Initializes the verifier with the given subjectPublicKeyInfo.
39 // |subjectPublicKeyInfo| is a DER-encoded SubjectPublicKeyInfo.
40 // An error is returned if |subjectPublicKeyInfo| refers to an unsupported
41 // public key.
42 pkix::Result Init(pkix::Input subjectPublicKeyInfo);
44 // Returns the log's key ID, which is a SHA256 hash of its public key.
45 // See RFC 6962, Section 3.2.
46 const Buffer& keyId() const { return mKeyId; }
48 CTLogOperatorId operatorId() const { return mOperatorId; }
49 CTLogState state() const { return mState; }
50 uint64_t timestamp() const { return mTimestamp; }
52 // Verifies that |sct| contains a valid signature for |entry|.
53 // |sct| must be signed by the verifier's log.
54 pkix::Result Verify(const LogEntry& entry,
55 const SignedCertificateTimestamp& sct);
57 // Returns true if the signature and hash algorithms in |signature|
58 // match those of the log.
59 bool SignatureParametersMatch(const DigitallySigned& signature);
61 private:
62 // Performs the underlying verification using the log's public key. Note
63 // that |signature| contains the raw signature data (i.e. without any
64 // DigitallySigned struct encoding).
65 // Returns Success if passed verification, ERROR_BAD_SIGNATURE if failed
66 // verification, or other result on error.
67 pkix::Result VerifySignature(pkix::Input data, pkix::Input signature);
68 pkix::Result VerifySignature(const Buffer& data, const Buffer& signature);
70 // mPublicECKey works around an architectural deficiency in NSS. In the case
71 // of EC, if we don't create, import, and cache this key, NSS will import and
72 // verify it every signature verification, which is slow. For RSA, this is
73 // unused and will be null.
74 UniqueSECKEYPublicKey mPublicECKey;
75 Buffer mSubjectPublicKeyInfo;
76 Buffer mKeyId;
77 DigitallySigned::SignatureAlgorithm mSignatureAlgorithm;
78 CTLogOperatorId mOperatorId;
79 CTLogState mState;
80 uint64_t mTimestamp;
83 } // namespace ct
84 } // namespace mozilla
86 #endif // CTLogVerifier_h