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