blob: 0a9b3eff03d8aa9af62ea68f5085bcc1259a4ead (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef NET_CERT_CT_LOG_VERIFIER_H_
#define NET_CERT_CT_LOG_VERIFIER_H_
#include <string>
#include "base/gtest_prod_util.h"
#include "base/memory/ref_counted.h"
#include "base/strings/string_piece.h"
#include "net/base/net_export.h"
#include "net/cert/signed_certificate_timestamp.h"
#include "url/gurl.h"
// Forward declare the crypto types to avoid having to include the full
// headers.
#if defined(USE_OPENSSL)
typedef struct evp_pkey_st EVP_PKEY;
#else
typedef struct SECKEYPublicKeyStr SECKEYPublicKey;
#endif
namespace net {
namespace ct {
struct SignedTreeHead;
} // namespace ct
// Class for verifying Signed Certificate Timestamps (SCTs) provided by a
// specific log (whose identity is provided during construction).
class NET_EXPORT CTLogVerifier
: public base::RefCountedThreadSafe<CTLogVerifier> {
public:
// Creates a new CTLogVerifier that will verify SignedCertificateTimestamps
// using |public_key|, which is a DER-encoded SubjectPublicKeyInfo.
// If |public_key| refers to an unsupported public key, returns NULL.
// |description| is a textual description of the log.
static scoped_refptr<CTLogVerifier> Create(
const base::StringPiece& public_key,
const base::StringPiece& description,
const base::StringPiece& url);
// Returns the log's key ID (RFC6962, Section 3.2)
const std::string& key_id() const { return key_id_; }
// Returns the log's human-readable description.
const std::string& description() const { return description_; }
// Returns the log's URL
const GURL& url() const { return url_; }
// Verifies that |sct| contains a valid signature for |entry|.
bool Verify(const ct::LogEntry& entry,
const ct::SignedCertificateTimestamp& sct);
// Returns true if the signature in |signed_tree_head| verifies.
bool VerifySignedTreeHead(const ct::SignedTreeHead& signed_tree_head);
private:
FRIEND_TEST_ALL_PREFIXES(CTLogVerifierTest, VerifySignature);
friend class base::RefCountedThreadSafe<CTLogVerifier>;
CTLogVerifier(const base::StringPiece& description, const GURL& url);
~CTLogVerifier();
// Performs crypto-library specific initialization.
bool Init(const base::StringPiece& public_key);
// Performs the underlying verification using the selected public key. Note
// that |signature| contains the raw signature data (eg: without any
// DigitallySigned struct encoding).
bool VerifySignature(const base::StringPiece& data_to_sign,
const base::StringPiece& signature);
// Returns true if the signature and hash algorithms in |signature|
// match those of the log
bool SignatureParametersMatch(const ct::DigitallySigned& signature);
std::string key_id_;
std::string description_;
GURL url_;
ct::DigitallySigned::HashAlgorithm hash_algorithm_;
ct::DigitallySigned::SignatureAlgorithm signature_algorithm_;
#if defined(USE_OPENSSL)
EVP_PKEY* public_key_;
#else
SECKEYPublicKey* public_key_;
#endif
};
} // namespace net
#endif // NET_CERT_CT_LOG_VERIFIER_H_
|