Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Side by Side Diff: components/gcm_driver/crypto/gcm_encryption_provider.cc

Issue 1453503002: [NOT FOR REVIEW] Ensure contributory behaviour for Web Push encryption. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@push-renames
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | components/gcm_driver/crypto/gcm_encryption_provider_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « no previous file | components/gcm_driver/crypto/gcm_encryption_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698