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

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

Issue 2713673002: Separate out the scheme from the GCMMessageCryptographer (Closed)
Patch Set: comments Created 3 years, 7 months 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.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_crypto_test_helpers.h" 5 #include "components/gcm_driver/crypto/gcm_crypto_test_helpers.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <sstream> 9 #include <sstream>
10 #include <string> 10 #include <string>
(...skipping 26 matching lines...) Expand all
37 &shared_secret)) { 37 &shared_secret)) {
38 return false; 38 return false;
39 } 39 }
40 40
41 std::string salt; 41 std::string salt;
42 42
43 // Generate a cryptographically secure random salt for the message. 43 // Generate a cryptographically secure random salt for the message.
44 const size_t salt_size = GCMMessageCryptographer::kSaltSize; 44 const size_t salt_size = GCMMessageCryptographer::kSaltSize;
45 crypto::RandBytes(base::WriteInto(&salt, salt_size + 1), salt_size); 45 crypto::RandBytes(base::WriteInto(&salt, salt_size + 1), salt_size);
46 46
47 GCMMessageCryptographer cryptographer(peer_public_key, public_key, 47 GCMMessageCryptographer cryptographer(
48 auth_secret.as_string()); 48 GCMMessageCryptographer::Version::DRAFT_03);
49 49
50 size_t record_size; 50 size_t record_size;
51 std::string ciphertext; 51 std::string ciphertext;
52 52
53 if (!cryptographer.Encrypt(payload, shared_secret, salt, &record_size, 53 if (!cryptographer.Encrypt(peer_public_key, public_key, shared_secret,
54 auth_secret, salt, payload, &record_size,
54 &ciphertext)) { 55 &ciphertext)) {
55 return false; 56 return false;
56 } 57 }
57 58
58 std::string encoded_salt, encoded_public_key; 59 std::string encoded_salt, encoded_public_key;
59 60
60 // Create base64url encoded representations of the salt and local public key. 61 // Create base64url encoded representations of the salt and local public key.
61 base::Base64UrlEncode(salt, base::Base64UrlEncodePolicy::OMIT_PADDING, 62 base::Base64UrlEncode(salt, base::Base64UrlEncodePolicy::OMIT_PADDING,
62 &encoded_salt); 63 &encoded_salt);
63 base::Base64UrlEncode(public_key, base::Base64UrlEncodePolicy::OMIT_PADDING, 64 base::Base64UrlEncode(public_key, base::Base64UrlEncodePolicy::OMIT_PADDING,
64 &encoded_public_key); 65 &encoded_public_key);
65 66
66 // Write the Encryption header value to |*message|. 67 // Write the Encryption header value to |*message|.
67 std::stringstream encryption_header; 68 std::stringstream encryption_header;
68 encryption_header << "salt=" << encoded_salt << ";rs=" << record_size; 69 encryption_header << "salt=" << encoded_salt << ";rs=" << record_size;
69 70
70 message->data["encryption"] = encryption_header.str(); 71 message->data["encryption"] = encryption_header.str();
71 72
72 // Write the Crypto-Key value to |*message|. 73 // Write the Crypto-Key value to |*message|.
73 std::stringstream crypto_key_header; 74 std::stringstream crypto_key_header;
74 crypto_key_header << "dh=" << encoded_public_key; 75 crypto_key_header << "dh=" << encoded_public_key;
75 76
76 message->data["crypto-key"] = crypto_key_header.str(); 77 message->data["crypto-key"] = crypto_key_header.str();
77 78
78 message->raw_data.swap(ciphertext); 79 message->raw_data.swap(ciphertext);
79 return true; 80 return true;
80 } 81 }
81 82
82 } // namespace gcm 83 } // namespace gcm
OLDNEW
« no previous file with comments | « no previous file | components/gcm_driver/crypto/gcm_encryption_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698