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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <sstream> | 9 #include <sstream> |
10 #include <string> | 10 #include <string> |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 &shared_secret)); | 489 &shared_secret)); |
490 | 490 |
491 IncomingMessage message; | 491 IncomingMessage message; |
492 size_t record_size; | 492 size_t record_size; |
493 | 493 |
494 message.sender_id = kExampleAuthorizedEntity; | 494 message.sender_id = kExampleAuthorizedEntity; |
495 | 495 |
496 // Encrypts the |kExampleMessage| using the generated shared key and the | 496 // Encrypts the |kExampleMessage| using the generated shared key and the |
497 // random |salt|, storing the result in |record_size| and the message. | 497 // random |salt|, storing the result in |record_size| and the message. |
498 GCMMessageCryptographer cryptographer( | 498 GCMMessageCryptographer cryptographer( |
499 pair.public_key(), server_pair.public_key(), auth_secret); | 499 GCMMessageCryptographer::Version::DRAFT_03); |
500 | 500 |
501 ASSERT_TRUE(cryptographer.Encrypt(kExampleMessage, shared_secret, salt, | 501 ASSERT_TRUE(cryptographer.Encrypt( |
502 &record_size, &message.raw_data)); | 502 pair.public_key(), server_pair.public_key(), shared_secret, auth_secret, |
| 503 salt, kExampleMessage, &record_size, &message.raw_data)); |
503 | 504 |
504 std::string encoded_salt, encoded_key; | 505 std::string encoded_salt, encoded_key; |
505 | 506 |
506 // Compile the incoming GCM message, including the required headers. | 507 // Compile the incoming GCM message, including the required headers. |
507 base::Base64UrlEncode( | 508 base::Base64UrlEncode( |
508 salt, base::Base64UrlEncodePolicy::INCLUDE_PADDING, &encoded_salt); | 509 salt, base::Base64UrlEncodePolicy::INCLUDE_PADDING, &encoded_salt); |
509 base::Base64UrlEncode( | 510 base::Base64UrlEncode( |
510 server_pair.public_key(), base::Base64UrlEncodePolicy::INCLUDE_PADDING, | 511 server_pair.public_key(), base::Base64UrlEncodePolicy::INCLUDE_PADDING, |
511 &encoded_key); | 512 &encoded_key); |
512 | 513 |
(...skipping 23 matching lines...) Expand all Loading... |
536 } | 537 } |
537 | 538 |
538 TEST_F(GCMEncryptionProviderTest, EncryptionRoundTripInstanceIDToken) { | 539 TEST_F(GCMEncryptionProviderTest, EncryptionRoundTripInstanceIDToken) { |
539 // GCMEncryptionProvider::DecryptMessage should succeed when the message was | 540 // GCMEncryptionProvider::DecryptMessage should succeed when the message was |
540 // sent to an InstanceID token (non-empty authorized_entity). | 541 // sent to an InstanceID token (non-empty authorized_entity). |
541 ASSERT_NO_FATAL_FAILURE( | 542 ASSERT_NO_FATAL_FAILURE( |
542 TestEncryptionRoundTrip(kExampleAppId, kExampleAuthorizedEntity)); | 543 TestEncryptionRoundTrip(kExampleAppId, kExampleAuthorizedEntity)); |
543 } | 544 } |
544 | 545 |
545 } // namespace gcm | 546 } // namespace gcm |
OLD | NEW |