| 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 #include "net/cert/ct_log_verifier.h" | 5 #include "net/cert/ct_log_verifier.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "net/cert/signed_certificate_timestamp.h" | 10 #include "net/cert/signed_certificate_timestamp.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 scoped_ptr<CTLogVerifier> log_; | 28 scoped_ptr<CTLogVerifier> log_; |
| 29 }; | 29 }; |
| 30 | 30 |
| 31 TEST_F(CTLogVerifierTest, VerifiesCertSCT) { | 31 TEST_F(CTLogVerifierTest, VerifiesCertSCT) { |
| 32 ct::LogEntry cert_entry; | 32 ct::LogEntry cert_entry; |
| 33 ct::GetX509CertLogEntry(&cert_entry); | 33 ct::GetX509CertLogEntry(&cert_entry); |
| 34 | 34 |
| 35 ct::SignedCertificateTimestamp cert_sct; | 35 ct::SignedCertificateTimestamp cert_sct; |
| 36 ct::GetX509CertSCT(&cert_sct); | 36 ct::GetX509CertSCT(&cert_sct); |
| 37 | 37 |
| 38 EXPECT_TRUE(log_->Verify(cert_entry, cert_sct)); | 38 ASSERT_EQ( |
| 39 CTLogVerifier::SCT_VERIFIED_OK, |
| 40 log_->Verify(cert_entry, cert_sct)); |
| 39 } | 41 } |
| 40 | 42 |
| 41 TEST_F(CTLogVerifierTest, VerifiesPrecertSCT) { | 43 TEST_F(CTLogVerifierTest, VerifiesPrecertSCT) { |
| 42 ct::LogEntry precert_entry; | 44 ct::LogEntry precert_entry; |
| 43 ct::GetPrecertLogEntry(&precert_entry); | 45 ct::GetPrecertLogEntry(&precert_entry); |
| 44 | 46 |
| 45 ct::SignedCertificateTimestamp precert_sct; | 47 ct::SignedCertificateTimestamp precert_sct; |
| 46 ct::GetPrecertSCT(&precert_sct); | 48 ct::GetPrecertSCT(&precert_sct); |
| 47 | 49 |
| 48 EXPECT_TRUE(log_->Verify(precert_entry, precert_sct)); | 50 ASSERT_EQ( |
| 51 CTLogVerifier::SCT_VERIFIED_OK, |
| 52 log_->Verify(precert_entry, precert_sct)); |
| 49 } | 53 } |
| 50 | 54 |
| 51 TEST_F(CTLogVerifierTest, FailsInvalidTimestamp) { | 55 TEST_F(CTLogVerifierTest, FailsInvalidTimestamp) { |
| 52 ct::LogEntry cert_entry; | 56 ct::LogEntry cert_entry; |
| 53 ct::GetX509CertLogEntry(&cert_entry); | 57 ct::GetX509CertLogEntry(&cert_entry); |
| 54 | 58 |
| 55 ct::SignedCertificateTimestamp cert_sct; | 59 ct::SignedCertificateTimestamp cert_sct; |
| 56 ct::GetX509CertSCT(&cert_sct); | 60 ct::GetX509CertSCT(&cert_sct); |
| 57 | 61 |
| 58 // Mangle the timestamp, so that it should fail signature validation. | 62 // Mangle the timestamp, so that it should fail signature validation. |
| 59 cert_sct.timestamp = base::Time::Now(); | 63 cert_sct.timestamp = base::Time::Now(); |
| 60 | 64 |
| 61 EXPECT_FALSE(log_->Verify(cert_entry, cert_sct)); | 65 ASSERT_EQ( |
| 66 CTLogVerifier::SCT_VERIFICATION_FAILED, |
| 67 log_->Verify(cert_entry, cert_sct)); |
| 62 } | 68 } |
| 63 | 69 |
| 64 TEST_F(CTLogVerifierTest, FailsInvalidLogID) { | 70 TEST_F(CTLogVerifierTest, FailsInvalidLogID) { |
| 65 ct::LogEntry cert_entry; | 71 ct::LogEntry cert_entry; |
| 66 ct::GetX509CertLogEntry(&cert_entry); | 72 ct::GetX509CertLogEntry(&cert_entry); |
| 67 | 73 |
| 68 ct::SignedCertificateTimestamp cert_sct; | 74 ct::SignedCertificateTimestamp cert_sct; |
| 69 ct::GetX509CertSCT(&cert_sct); | 75 ct::GetX509CertSCT(&cert_sct); |
| 70 | 76 |
| 71 // Mangle the log ID, which should cause it to match a different log before | 77 // Mangle the log ID, which should cause it to match a different log before |
| 72 // attempting signature validation. | 78 // attempting signature validation. |
| 73 cert_sct.log_id.assign(cert_sct.log_id.size(), '\0'); | 79 cert_sct.log_id.assign(cert_sct.log_id.size(), '\0'); |
| 74 | 80 |
| 75 EXPECT_FALSE(log_->Verify(cert_entry, cert_sct)); | 81 ASSERT_EQ( |
| 82 CTLogVerifier::SCT_NOT_FROM_THIS_LOG, log_->Verify(cert_entry, cert_sct)); |
| 76 } | 83 } |
| 77 | 84 |
| 78 } // namespace net | 85 } // namespace net |
| OLD | NEW |