| 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> |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 server_public_key_version_(server_public_key_version) { | 131 server_public_key_version_(server_public_key_version) { |
| 132 DCHECK(certificate_report_sender_); | 132 DCHECK(certificate_report_sender_); |
| 133 DCHECK(!upload_url.is_empty()); | 133 DCHECK(!upload_url.is_empty()); |
| 134 } | 134 } |
| 135 | 135 |
| 136 ErrorReporter::~ErrorReporter() {} | 136 ErrorReporter::~ErrorReporter() {} |
| 137 | 137 |
| 138 void ErrorReporter::SendExtendedReportingReport( | 138 void ErrorReporter::SendExtendedReportingReport( |
| 139 const std::string& serialized_report) { | 139 const std::string& serialized_report) { |
| 140 if (upload_url_.SchemeIsCryptographic()) { | 140 if (upload_url_.SchemeIsCryptographic()) { |
| 141 certificate_report_sender_->Send(upload_url_, serialized_report); | 141 certificate_report_sender_->Send(upload_url_, "application/octet-stream", |
| 142 serialized_report); |
| 142 } else { | 143 } else { |
| 143 EncryptedCertLoggerRequest encrypted_report; | 144 EncryptedCertLoggerRequest encrypted_report; |
| 144 if (!EncryptSerializedReport(server_public_key_, server_public_key_version_, | 145 if (!EncryptSerializedReport(server_public_key_, server_public_key_version_, |
| 145 serialized_report, &encrypted_report)) { | 146 serialized_report, &encrypted_report)) { |
| 146 LOG(ERROR) << "Failed to encrypt serialized report."; | 147 LOG(ERROR) << "Failed to encrypt serialized report."; |
| 147 return; | 148 return; |
| 148 } | 149 } |
| 149 std::string serialized_encrypted_report; | 150 std::string serialized_encrypted_report; |
| 150 encrypted_report.SerializeToString(&serialized_encrypted_report); | 151 encrypted_report.SerializeToString(&serialized_encrypted_report); |
| 151 certificate_report_sender_->Send(upload_url_, serialized_encrypted_report); | 152 certificate_report_sender_->Send(upload_url_, "application/octet-stream", |
| 153 serialized_encrypted_report); |
| 152 } | 154 } |
| 153 } | 155 } |
| 154 | 156 |
| 155 // Used only by tests. | 157 // Used only by tests. |
| 156 bool ErrorReporter::DecryptErrorReport( | 158 bool ErrorReporter::DecryptErrorReport( |
| 157 const uint8_t server_private_key[32], | 159 const uint8_t server_private_key[32], |
| 158 const EncryptedCertLoggerRequest& encrypted_report, | 160 const EncryptedCertLoggerRequest& encrypted_report, |
| 159 std::string* decrypted_serialized_report) { | 161 std::string* decrypted_serialized_report) { |
| 160 crypto::Aead aead(crypto::Aead::AES_128_CTR_HMAC_SHA256); | 162 crypto::Aead aead(crypto::Aead::AES_128_CTR_HMAC_SHA256); |
| 161 std::string key; | 163 std::string key; |
| 162 if (!GetHkdfSubkeySecret(aead.KeyLength(), server_private_key, | 164 if (!GetHkdfSubkeySecret(aead.KeyLength(), server_private_key, |
| 163 reinterpret_cast<const uint8_t*>( | 165 reinterpret_cast<const uint8_t*>( |
| 164 encrypted_report.client_public_key().data()), | 166 encrypted_report.client_public_key().data()), |
| 165 &key)) { | 167 &key)) { |
| 166 LOG(ERROR) << "Error getting subkey secret."; | 168 LOG(ERROR) << "Error getting subkey secret."; |
| 167 return false; | 169 return false; |
| 168 } | 170 } |
| 169 aead.Init(&key); | 171 aead.Init(&key); |
| 170 | 172 |
| 171 // Use an all-zero nonce because the key is random per-message. | 173 // Use an all-zero nonce because the key is random per-message. |
| 172 std::string nonce(aead.NonceLength(), 0); | 174 std::string nonce(aead.NonceLength(), 0); |
| 173 | 175 |
| 174 return aead.Open(encrypted_report.encrypted_report(), nonce, std::string(), | 176 return aead.Open(encrypted_report.encrypted_report(), nonce, std::string(), |
| 175 decrypted_serialized_report); | 177 decrypted_serialized_report); |
| 176 } | 178 } |
| 177 | 179 |
| 178 } // namespace certificate_reporting | 180 } // namespace certificate_reporting |
| OLD | NEW |