OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/certificate_reporting/error_reporter.h" | 5 #include "components/certificate_reporting/error_reporter.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include <set> | 10 #include <set> |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 new MockCertificateReportSender(); | 85 new MockCertificateReportSender(); |
86 GURL http_url(kDummyHttpReportUri); | 86 GURL http_url(kDummyHttpReportUri); |
87 ErrorReporter http_reporter(http_url, server_public_key_, | 87 ErrorReporter http_reporter(http_url, server_public_key_, |
88 kServerPublicKeyTestVersion, | 88 kServerPublicKeyTestVersion, |
89 make_scoped_ptr(http_mock_report_sender)); | 89 make_scoped_ptr(http_mock_report_sender)); |
90 http_reporter.SendExtendedReportingReport(kDummyReport); | 90 http_reporter.SendExtendedReportingReport(kDummyReport); |
91 | 91 |
92 EXPECT_EQ(http_mock_report_sender->latest_report_uri(), http_url); | 92 EXPECT_EQ(http_mock_report_sender->latest_report_uri(), http_url); |
93 | 93 |
94 std::string uploaded_report; | 94 std::string uploaded_report; |
95 #if defined(USE_OPENSSL) | |
96 EncryptedCertLoggerRequest encrypted_request; | 95 EncryptedCertLoggerRequest encrypted_request; |
97 ASSERT_TRUE(encrypted_request.ParseFromString( | 96 ASSERT_TRUE(encrypted_request.ParseFromString( |
98 http_mock_report_sender->latest_report())); | 97 http_mock_report_sender->latest_report())); |
99 EXPECT_EQ(kServerPublicKeyTestVersion, | 98 EXPECT_EQ(kServerPublicKeyTestVersion, |
100 encrypted_request.server_public_key_version()); | 99 encrypted_request.server_public_key_version()); |
101 EXPECT_EQ(EncryptedCertLoggerRequest::AEAD_ECDH_AES_128_CTR_HMAC_SHA256, | 100 EXPECT_EQ(EncryptedCertLoggerRequest::AEAD_ECDH_AES_128_CTR_HMAC_SHA256, |
102 encrypted_request.algorithm()); | 101 encrypted_request.algorithm()); |
103 ASSERT_TRUE(ErrorReporter::DecryptErrorReport( | 102 ASSERT_TRUE(ErrorReporter::DecryptErrorReport( |
104 server_private_key_, encrypted_request, &uploaded_report)); | 103 server_private_key_, encrypted_request, &uploaded_report)); |
105 #else | |
106 ADD_FAILURE() << "Only supported in OpenSSL ports"; | |
107 #endif | |
108 | 104 |
109 EXPECT_EQ(kDummyReport, uploaded_report); | 105 EXPECT_EQ(kDummyReport, uploaded_report); |
110 } | 106 } |
111 } | 107 } |
112 | 108 |
113 #if defined(USE_OPENSSL) | |
114 // This test decrypts a "known gold" report. It's intentionally brittle | 109 // This test decrypts a "known gold" report. It's intentionally brittle |
115 // in order to catch changes in report encryption that could cause the | 110 // in order to catch changes in report encryption that could cause the |
116 // server to no longer be able to decrypt reports that it receives from | 111 // server to no longer be able to decrypt reports that it receives from |
117 // Chrome. | 112 // Chrome. |
118 TEST_F(ErrorReporterTest, DecryptExampleReport) { | 113 TEST_F(ErrorReporterTest, DecryptExampleReport) { |
119 // This data should not be changed without also changing the | 114 // This data should not be changed without also changing the |
120 // corresponding server-side test. | 115 // corresponding server-side test. |
121 const unsigned char kSerializedEncryptedReport[] = { | 116 const unsigned char kSerializedEncryptedReport[] = { |
122 0x0A, 0xFB, 0x0C, 0xD5, 0x44, 0x21, 0x36, 0x4D, 0xFC, 0x29, 0x56, 0xBD, | 117 0x0A, 0xFB, 0x0C, 0xD5, 0x44, 0x21, 0x36, 0x4D, 0xFC, 0x29, 0x56, 0xBD, |
123 0x47, 0x18, 0xB1, 0x6F, 0x97, 0xF1, 0xF0, 0x3C, 0x31, 0x31, 0x1D, 0xD7, | 118 0x47, 0x18, 0xB1, 0x6F, 0x97, 0xF1, 0xF0, 0x3C, 0x31, 0x31, 0x1D, 0xD7, |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 0x1A, 0x7D, 0x19, 0x81, 0xF0, 0x4D, 0x20, 0x01}; | 258 0x1A, 0x7D, 0x19, 0x81, 0xF0, 0x4D, 0x20, 0x01}; |
264 | 259 |
265 EncryptedCertLoggerRequest encrypted_request; | 260 EncryptedCertLoggerRequest encrypted_request; |
266 std::string decrypted_serialized_report; | 261 std::string decrypted_serialized_report; |
267 ASSERT_TRUE(encrypted_request.ParseFromString( | 262 ASSERT_TRUE(encrypted_request.ParseFromString( |
268 std::string(reinterpret_cast<const char*>(kSerializedEncryptedReport), | 263 std::string(reinterpret_cast<const char*>(kSerializedEncryptedReport), |
269 sizeof(kSerializedEncryptedReport)))); | 264 sizeof(kSerializedEncryptedReport)))); |
270 ASSERT_TRUE(ErrorReporter::DecryptErrorReport( | 265 ASSERT_TRUE(ErrorReporter::DecryptErrorReport( |
271 server_private_key_, encrypted_request, &decrypted_serialized_report)); | 266 server_private_key_, encrypted_request, &decrypted_serialized_report)); |
272 } | 267 } |
273 #endif | |
274 | 268 |
275 } // namespace | 269 } // namespace |
276 | 270 |
277 } // namespace certificate_reporting | 271 } // namespace certificate_reporting |
OLD | NEW |