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