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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 std::string shared_secret; | 170 std::string shared_secret; |
171 if (!ComputeSharedP256Secret(pair.private_key(), pair.public_key_x509(), dh, | 171 if (!ComputeSharedP256Secret(pair.private_key(), pair.public_key_x509(), dh, |
172 &shared_secret)) { | 172 &shared_secret)) { |
173 DLOG(ERROR) << "Unable to calculate the shared secret."; | 173 DLOG(ERROR) << "Unable to calculate the shared secret."; |
174 failure_callback.Run(DECRYPTION_FAILURE_INVALID_PUBLIC_KEY); | 174 failure_callback.Run(DECRYPTION_FAILURE_INVALID_PUBLIC_KEY); |
175 return; | 175 return; |
176 } | 176 } |
177 | 177 |
178 std::string plaintext; | 178 std::string plaintext; |
179 | 179 |
180 GCMMessageCryptographer cryptographer; | 180 GCMMessageCryptographer cryptographer(pair.public_key(), dh); |
181 if (!cryptographer.Decrypt(message.raw_data, shared_secret, salt, rs, | 181 if (!cryptographer.Decrypt(message.raw_data, shared_secret, salt, rs, |
182 &plaintext)) { | 182 &plaintext)) { |
183 DLOG(ERROR) << "Unable to decrypt the incoming data."; | 183 DLOG(ERROR) << "Unable to decrypt the incoming data."; |
184 failure_callback.Run(DECRYPTION_FAILURE_INVALID_PAYLOAD); | 184 failure_callback.Run(DECRYPTION_FAILURE_INVALID_PAYLOAD); |
185 return; | 185 return; |
186 } | 186 } |
187 | 187 |
188 IncomingMessage decrypted_message; | 188 IncomingMessage decrypted_message; |
189 decrypted_message.collapse_key = message.collapse_key; | 189 decrypted_message.collapse_key = message.collapse_key; |
190 decrypted_message.sender_id = message.sender_id; | 190 decrypted_message.sender_id = message.sender_id; |
191 decrypted_message.raw_data.swap(plaintext); | 191 decrypted_message.raw_data.swap(plaintext); |
192 decrypted_message.decrypted = true; | 192 decrypted_message.decrypted = true; |
193 | 193 |
194 // There must be no data associated with the decrypted message at this point, | 194 // There must be no data associated with the decrypted message at this point, |
195 // to make sure that we don't end up in an infinite decryption loop. | 195 // to make sure that we don't end up in an infinite decryption loop. |
196 DCHECK_EQ(0u, decrypted_message.data.size()); | 196 DCHECK_EQ(0u, decrypted_message.data.size()); |
197 | 197 |
198 success_callback.Run(decrypted_message); | 198 success_callback.Run(decrypted_message); |
199 } | 199 } |
200 | 200 |
201 } // namespace gcm | 201 } // namespace gcm |
OLD | NEW |