| 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/gcm_driver/crypto/gcm_encryption_provider.h" | 5 #include "components/gcm_driver/crypto/gcm_encryption_provider.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 std::string shared_secret; | 240 std::string shared_secret; |
| 241 if (!ComputeSharedP256Secret(pair.private_key(), pair.public_key_x509(), dh, | 241 if (!ComputeSharedP256Secret(pair.private_key(), pair.public_key_x509(), dh, |
| 242 &shared_secret)) { | 242 &shared_secret)) { |
| 243 DLOG(ERROR) << "Unable to calculate the shared secret."; | 243 DLOG(ERROR) << "Unable to calculate the shared secret."; |
| 244 callback.Run(DECRYPTION_RESULT_INVALID_SHARED_SECRET, IncomingMessage()); | 244 callback.Run(DECRYPTION_RESULT_INVALID_SHARED_SECRET, IncomingMessage()); |
| 245 return; | 245 return; |
| 246 } | 246 } |
| 247 | 247 |
| 248 std::string plaintext; | 248 std::string plaintext; |
| 249 | 249 |
| 250 GCMMessageCryptographer cryptographer(pair.public_key(), dh, auth_secret); | 250 GCMMessageCryptographer cryptographer( |
| 251 if (!cryptographer.Decrypt(message.raw_data, shared_secret, salt, rs, | 251 GCMMessageCryptographer::Version::DRAFT_03); |
| 252 &plaintext)) { | 252 |
| 253 if (!cryptographer.Decrypt(pair.public_key(), dh, shared_secret, auth_secret, |
| 254 salt, message.raw_data, rs, &plaintext)) { |
| 253 DLOG(ERROR) << "Unable to decrypt the incoming data."; | 255 DLOG(ERROR) << "Unable to decrypt the incoming data."; |
| 254 callback.Run(DECRYPTION_RESULT_INVALID_PAYLOAD, IncomingMessage()); | 256 callback.Run(DECRYPTION_RESULT_INVALID_PAYLOAD, IncomingMessage()); |
| 255 return; | 257 return; |
| 256 } | 258 } |
| 257 | 259 |
| 258 IncomingMessage decrypted_message; | 260 IncomingMessage decrypted_message; |
| 259 decrypted_message.collapse_key = message.collapse_key; | 261 decrypted_message.collapse_key = message.collapse_key; |
| 260 decrypted_message.sender_id = message.sender_id; | 262 decrypted_message.sender_id = message.sender_id; |
| 261 decrypted_message.raw_data.swap(plaintext); | 263 decrypted_message.raw_data.swap(plaintext); |
| 262 decrypted_message.decrypted = true; | 264 decrypted_message.decrypted = true; |
| 263 | 265 |
| 264 // There must be no data associated with the decrypted message at this point, | 266 // There must be no data associated with the decrypted message at this point, |
| 265 // to make sure that we don't end up in an infinite decryption loop. | 267 // to make sure that we don't end up in an infinite decryption loop. |
| 266 DCHECK_EQ(0u, decrypted_message.data.size()); | 268 DCHECK_EQ(0u, decrypted_message.data.size()); |
| 267 | 269 |
| 268 callback.Run(DECRYPTION_RESULT_DECRYPTED, decrypted_message); | 270 callback.Run(DECRYPTION_RESULT_DECRYPTED, decrypted_message); |
| 269 } | 271 } |
| 270 | 272 |
| 271 } // namespace gcm | 273 } // namespace gcm |
| OLD | NEW |