| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "components/certificate_reporting/encrypted_cert_logger.pb.h" | 14 #include "components/certificate_reporting/encrypted_cert_logger.pb.h" |
| 15 #include "crypto/aead.h" | 15 #include "crypto/aead.h" |
| 16 #include "crypto/curve25519.h" | 16 #include "crypto/curve25519.h" |
| 17 #include "crypto/hkdf.h" | 17 #include "crypto/hkdf.h" |
| 18 #include "crypto/random.h" | 18 #include "crypto/random.h" |
| 19 #include "net/url_request/certificate_report_sender.h" | 19 #include "net/url_request/report_sender.h" |
| 20 | 20 |
| 21 namespace certificate_reporting { | 21 namespace certificate_reporting { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 // Constants used for crypto. The corresponding private key is used by | 25 // Constants used for crypto. The corresponding private key is used by |
| 26 // the SafeBrowsing client-side detection server to decrypt reports. | 26 // the SafeBrowsing client-side detection server to decrypt reports. |
| 27 static const uint8_t kServerPublicKey[] = { | 27 static const uint8_t kServerPublicKey[] = { |
| 28 0x51, 0xcc, 0x52, 0x67, 0x42, 0x47, 0x3b, 0x10, 0xe8, 0x63, 0x18, | 28 0x51, 0xcc, 0x52, 0x67, 0x42, 0x47, 0x3b, 0x10, 0xe8, 0x63, 0x18, |
| 29 0x3c, 0x61, 0xa7, 0x96, 0x76, 0x86, 0x91, 0x40, 0x71, 0x39, 0x5f, | 29 0x3c, 0x61, 0xa7, 0x96, 0x76, 0x86, 0x91, 0x40, 0x71, 0x39, 0x5f, |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 encrypted_report->set_algorithm( | 96 encrypted_report->set_algorithm( |
| 97 EncryptedCertLoggerRequest::AEAD_ECDH_AES_128_CTR_HMAC_SHA256); | 97 EncryptedCertLoggerRequest::AEAD_ECDH_AES_128_CTR_HMAC_SHA256); |
| 98 return true; | 98 return true; |
| 99 } | 99 } |
| 100 | 100 |
| 101 } // namespace | 101 } // namespace |
| 102 | 102 |
| 103 ErrorReporter::ErrorReporter( | 103 ErrorReporter::ErrorReporter( |
| 104 net::URLRequestContext* request_context, | 104 net::URLRequestContext* request_context, |
| 105 const GURL& upload_url, | 105 const GURL& upload_url, |
| 106 net::CertificateReportSender::CookiesPreference cookies_preference) | 106 net::ReportSender::CookiesPreference cookies_preference) |
| 107 : ErrorReporter(upload_url, | 107 : ErrorReporter( |
| 108 kServerPublicKey, | 108 upload_url, |
| 109 kServerPublicKeyVersion, | 109 kServerPublicKey, |
| 110 base::WrapUnique(new net::CertificateReportSender( | 110 kServerPublicKeyVersion, |
| 111 request_context, | 111 base::WrapUnique( |
| 112 cookies_preference))) {} | 112 new net::ReportSender(request_context, cookies_preference))) {} |
| 113 | 113 |
| 114 ErrorReporter::ErrorReporter( | 114 ErrorReporter::ErrorReporter( |
| 115 const GURL& upload_url, | 115 const GURL& upload_url, |
| 116 const uint8_t server_public_key[/* 32 */], | 116 const uint8_t server_public_key[/* 32 */], |
| 117 const uint32_t server_public_key_version, | 117 const uint32_t server_public_key_version, |
| 118 std::unique_ptr<net::CertificateReportSender> certificate_report_sender) | 118 std::unique_ptr<net::ReportSender> certificate_report_sender) |
| 119 : certificate_report_sender_(std::move(certificate_report_sender)), | 119 : certificate_report_sender_(std::move(certificate_report_sender)), |
| 120 upload_url_(upload_url), | 120 upload_url_(upload_url), |
| 121 server_public_key_(server_public_key), | 121 server_public_key_(server_public_key), |
| 122 server_public_key_version_(server_public_key_version) { | 122 server_public_key_version_(server_public_key_version) { |
| 123 DCHECK(certificate_report_sender_); | 123 DCHECK(certificate_report_sender_); |
| 124 DCHECK(!upload_url.is_empty()); | 124 DCHECK(!upload_url.is_empty()); |
| 125 } | 125 } |
| 126 | 126 |
| 127 ErrorReporter::~ErrorReporter() {} | 127 ErrorReporter::~ErrorReporter() {} |
| 128 | 128 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 aead.Init(&key); | 165 aead.Init(&key); |
| 166 | 166 |
| 167 // Use an all-zero nonce because the key is random per-message. | 167 // Use an all-zero nonce because the key is random per-message. |
| 168 std::string nonce(aead.NonceLength(), 0); | 168 std::string nonce(aead.NonceLength(), 0); |
| 169 | 169 |
| 170 return aead.Open(encrypted_report.encrypted_report(), nonce, std::string(), | 170 return aead.Open(encrypted_report.encrypted_report(), nonce, std::string(), |
| 171 decrypted_serialized_report); | 171 decrypted_serialized_report); |
| 172 } | 172 } |
| 173 | 173 |
| 174 } // namespace certificate_reporting | 174 } // namespace certificate_reporting |
| OLD | NEW |