Chromium Code Reviews| 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" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
| 13 #include "net/base/net_export.h" | 13 #include "net/base/net_export.h" |
| 14 #include "net/cert/signed_certificate_timestamp.h" | 14 #include "net/cert/signed_certificate_timestamp.h" |
| 15 | 15 |
| 16 // Forward declare the crypto types to avoid having to include the full | 16 // Forward declare the crypto types to avoid having to include the full |
| 17 // headers. | 17 // headers. |
| 18 #if defined(USE_OPENSSL) | 18 #if defined(USE_OPENSSL) |
| 19 typedef struct evp_pkey_st EVP_PKEY; | 19 typedef struct evp_pkey_st EVP_PKEY; |
| 20 #else | 20 #else |
| 21 typedef struct SECKEYPublicKeyStr SECKEYPublicKey; | 21 typedef struct SECKEYPublicKeyStr SECKEYPublicKey; |
| 22 #endif | 22 #endif |
| 23 | 23 |
| 24 namespace net { | 24 namespace net { |
| 25 | 25 |
| 26 namespace ct { | |
| 27 struct SignedTreeHead; | |
| 28 } // namespace ct | |
| 29 | |
| 26 // Class for verifying Signed Certificate Timestamps (SCTs) provided by a | 30 // Class for verifying Signed Certificate Timestamps (SCTs) provided by a |
| 27 // specific log (whose identity is provided during construction). | 31 // specific log (whose identity is provided during construction). |
| 28 class NET_EXPORT CTLogVerifier { | 32 class NET_EXPORT CTLogVerifier { |
| 29 public: | 33 public: |
| 30 // Creates a new CTLogVerifier that will verify SignedCertificateTimestamps | 34 // Creates a new CTLogVerifier that will verify SignedCertificateTimestamps |
| 31 // using |public_key|, which is a DER-encoded SubjectPublicKeyInfo. | 35 // using |public_key|, which is a DER-encoded SubjectPublicKeyInfo. |
| 32 // If |public_key| refers to an unsupported public key, returns NULL. | 36 // If |public_key| refers to an unsupported public key, returns NULL. |
| 33 // |description| is a textual description of the log. | 37 // |description| is a textual description of the log. |
| 34 static scoped_ptr<CTLogVerifier> Create( | 38 static scoped_ptr<CTLogVerifier> Create( |
| 35 const base::StringPiece& public_key, | 39 const base::StringPiece& public_key, |
| 36 const base::StringPiece& description); | 40 const base::StringPiece& description); |
| 37 | 41 |
| 38 ~CTLogVerifier(); | 42 ~CTLogVerifier(); |
| 39 | 43 |
| 40 // Returns the log's key ID (RFC6962, Section 3.2) | 44 // Returns the log's key ID (RFC6962, Section 3.2) |
| 41 const std::string& key_id() const { return key_id_; } | 45 const std::string& key_id() const { return key_id_; } |
| 42 // Returns the log's human-readable description. | 46 // Returns the log's human-readable description. |
| 43 const std::string& description() const { return description_; } | 47 const std::string& description() const { return description_; } |
| 44 | 48 |
| 45 // Verifies that |sct| contains a valid signature for |entry|. | 49 // Verifies that |sct| contains a valid signature for |entry|. |
| 46 bool Verify(const ct::LogEntry& entry, | 50 bool Verify(const ct::LogEntry& entry, |
| 47 const ct::SignedCertificateTimestamp& sct); | 51 const ct::SignedCertificateTimestamp& sct); |
| 48 | 52 |
| 53 // Verifies and sets |signed_tree_head|. If |signed_tree_head|'s signature is | |
| 54 // valid, stores it and returns true. Otherwise, discards the sth and | |
| 55 // returns false. | |
| 56 bool SetSignedTreeHead(scoped_ptr<ct::SignedTreeHead> signed_tree_head); | |
| 57 | |
| 49 private: | 58 private: |
| 50 FRIEND_TEST_ALL_PREFIXES(CTLogVerifierTest, VerifySignature); | 59 FRIEND_TEST_ALL_PREFIXES(CTLogVerifierTest, VerifySignature); |
| 51 | 60 |
| 52 CTLogVerifier(); | 61 CTLogVerifier(); |
| 53 | 62 |
| 54 // Performs crypto-library specific initialization. | 63 // Performs crypto-library specific initialization. |
| 55 bool Init(const base::StringPiece& public_key, | 64 bool Init(const base::StringPiece& public_key, |
| 56 const base::StringPiece& description); | 65 const base::StringPiece& description); |
| 57 | 66 |
| 58 // Performs the underlying verification using the selected public key. Note | 67 // Performs the underlying verification using the selected public key. Note |
| 59 // that |signature| contains the raw signature data (eg: without any | 68 // that |signature| contains the raw signature data (eg: without any |
| 60 // DigitallySigned struct encoding). | 69 // DigitallySigned struct encoding). |
| 61 bool VerifySignature(const base::StringPiece& data_to_sign, | 70 bool VerifySignature(const base::StringPiece& data_to_sign, |
| 62 const base::StringPiece& signature); | 71 const base::StringPiece& signature); |
| 63 | 72 |
| 73 // Returns true if the signature and hash algorithms in |signature| | |
| 74 // match those of the log | |
| 75 bool SignatureParametersMatch(const ct::DigitallySigned& signature); | |
| 76 | |
| 64 std::string key_id_; | 77 std::string key_id_; |
| 65 std::string description_; | 78 std::string description_; |
| 66 ct::DigitallySigned::HashAlgorithm hash_algorithm_; | 79 ct::DigitallySigned::HashAlgorithm hash_algorithm_; |
| 67 ct::DigitallySigned::SignatureAlgorithm signature_algorithm_; | 80 ct::DigitallySigned::SignatureAlgorithm signature_algorithm_; |
| 81 scoped_ptr<ct::SignedTreeHead> sth_; | |
|
Ryan Sleevi
2014/04/25 23:33:19
s/sth_/signed_tree_head_/
Eran Messeri
2014/04/29 15:22:24
Done.
| |
| 68 | 82 |
| 69 #if defined(USE_OPENSSL) | 83 #if defined(USE_OPENSSL) |
| 70 EVP_PKEY* public_key_; | 84 EVP_PKEY* public_key_; |
| 71 #else | 85 #else |
| 72 SECKEYPublicKey* public_key_; | 86 SECKEYPublicKey* public_key_; |
| 73 #endif | 87 #endif |
| 74 }; | 88 }; |
| 75 | 89 |
| 76 } // namespace net | 90 } // namespace net |
| 77 | 91 |
| 78 #endif // NET_CERT_CT_LOG_VERIFIER_H_ | 92 #endif // NET_CERT_CT_LOG_VERIFIER_H_ |
| OLD | NEW |