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 GCMMessageCryptographer::Label::P256, pair.public_key(), | 499 pair.public_key(), server_pair.public_key(), auth_secret); |
500 server_pair.public_key(), auth_secret); | |
501 | 500 |
502 ASSERT_TRUE(cryptographer.Encrypt(kExampleMessage, shared_secret, salt, | 501 ASSERT_TRUE(cryptographer.Encrypt(kExampleMessage, shared_secret, salt, |
503 &record_size, &message.raw_data)); | 502 &record_size, &message.raw_data)); |
504 | 503 |
505 std::string encoded_salt, encoded_key; | 504 std::string encoded_salt, encoded_key; |
506 | 505 |
507 // Compile the incoming GCM message, including the required headers. | 506 // Compile the incoming GCM message, including the required headers. |
508 base::Base64UrlEncode( | 507 base::Base64UrlEncode( |
509 salt, base::Base64UrlEncodePolicy::INCLUDE_PADDING, &encoded_salt); | 508 salt, base::Base64UrlEncodePolicy::INCLUDE_PADDING, &encoded_salt); |
510 base::Base64UrlEncode( | 509 base::Base64UrlEncode( |
(...skipping 26 matching lines...) Expand all Loading... |
537 } | 536 } |
538 | 537 |
539 TEST_F(GCMEncryptionProviderTest, EncryptionRoundTripInstanceIDToken) { | 538 TEST_F(GCMEncryptionProviderTest, EncryptionRoundTripInstanceIDToken) { |
540 // GCMEncryptionProvider::DecryptMessage should succeed when the message was | 539 // GCMEncryptionProvider::DecryptMessage should succeed when the message was |
541 // sent to an InstanceID token (non-empty authorized_entity). | 540 // sent to an InstanceID token (non-empty authorized_entity). |
542 ASSERT_NO_FATAL_FAILURE( | 541 ASSERT_NO_FATAL_FAILURE( |
543 TestEncryptionRoundTrip(kExampleAppId, kExampleAuthorizedEntity)); | 542 TestEncryptionRoundTrip(kExampleAppId, kExampleAuthorizedEntity)); |
544 } | 543 } |
545 | 544 |
546 } // namespace gcm | 545 } // namespace gcm |
OLD | NEW |