Chromium Code Reviews| Index: components/gcm_driver/crypto/gcm_encryption_provider.h |
| diff --git a/components/gcm_driver/crypto/gcm_encryption_provider.h b/components/gcm_driver/crypto/gcm_encryption_provider.h |
| index a395118a1293d9367a2f949af8eab7a5f0f922d5..c9f94521ad43d136059d3935aeeff2d960096900 100644 |
| --- a/components/gcm_driver/crypto/gcm_encryption_provider.h |
| +++ b/components/gcm_driver/crypto/gcm_encryption_provider.h |
| @@ -9,6 +9,7 @@ |
| #include <string> |
| #include "base/callback_forward.h" |
| +#include "base/gtest_prod_util.h" |
| #include "base/macros.h" |
| #include "base/memory/weak_ptr.h" |
| @@ -20,6 +21,7 @@ class SequencedTaskRunner; |
| namespace gcm { |
| class GCMKeyStore; |
| +struct IncomingMessage; |
| class KeyPair; |
| // Provider that enables the GCM Driver to deal with encryption key management |
| @@ -29,6 +31,29 @@ class GCMEncryptionProvider { |
| // Callback to be invoked when the public encryption key is available. |
| using PublicKeyCallback = base::Callback<void(const std::string&)>; |
| + // Callback to be invoked when a message has been decrypted. |
| + using MessageDecryptedCallback = base::Callback<void(const IncomingMessage&)>; |
| + |
| + // Reasons why the decryption of an incoming message can fail. |
| + enum DecryptionFailure { |
| + // The contents of the Encryption HTTP header could not be parsed. |
| + DECRYPTION_FAILURE_INVALID_ENCRYPTION_HEADER, |
| + |
| + // The contents of the Encryption-Key HTTP header could not be parsed. |
| + DECRYPTION_FAILURE_INVALID_ENCRYPTION_KEY_HEADER, |
| + |
| + // No public/private key-pair was associated with the app_id. |
| + DECRYPTION_FAILURE_NO_KEYS, |
| + |
| + // The payload could not be decrypted as AES-128-GCM. |
| + DECRYPTION_FAILURE_INVALID_PAYLOAD, |
| + |
| + DECRYPTION_FAILURE_UNKNOWN |
|
Michael van Ouwerkerk
2015/10/02 14:30:41
nit: Consider making this the first value as it mi
Peter Beverloo
2015/10/02 15:01:22
Done.
|
| + }; |
| + |
| + // Callback to be invoked when a message cannot be decoded. |
| + using DecryptionFailedCallback = base::Callback<void(DecryptionFailure)>; |
| + |
| GCMEncryptionProvider(); |
| ~GCMEncryptionProvider(); |
| @@ -44,7 +69,21 @@ class GCMEncryptionProvider { |
| void GetPublicKey(const std::string& app_id, |
| const PublicKeyCallback& callback); |
| + // Determines whether |message| contains encrypted content. |
| + bool IsEncryptedMessage(const IncomingMessage& message) const; |
| + |
| + // Asynchronously decrypts |message|. The |success_callback| will be invoked |
| + // the message could be decrypted successfully, accompanied by the decrypted |
| + // payload of the message. When decryption failed, the |failure_callback| will |
| + // be invoked with the reason that encryption failed. |
| + void DecryptMessage(const std::string& app_id, |
| + const IncomingMessage& message, |
| + const MessageDecryptedCallback& success_callback, |
| + const DecryptionFailedCallback& failure_callback); |
| + |
| private: |
| + FRIEND_TEST_ALL_PREFIXES(GCMEncryptionProviderTest, EncryptionRoundTrip); |
|
Michael van Ouwerkerk
2015/10/02 14:30:42
Why not friend class GCMEncryptionProviderTest? It
Peter Beverloo
2015/10/02 15:01:22
Unfortunately that's not how gtest works. The fixt
|
| + |
| void DidGetPublicKey(const std::string& app_id, |
| const PublicKeyCallback& callback, |
| const KeyPair& pair); |
| @@ -52,6 +91,14 @@ class GCMEncryptionProvider { |
| void DidCreatePublicKey(const PublicKeyCallback& callback, |
| const KeyPair& pair); |
| + void DecryptMessageWithKey(const IncomingMessage& message, |
| + const MessageDecryptedCallback& success_callback, |
| + const DecryptionFailedCallback& failure_callback, |
| + const std::string& salt, |
| + const std::string& dh, |
| + uint64_t rs, |
| + const KeyPair& pair); |
| + |
| scoped_ptr<GCMKeyStore> key_store_; |
| base::WeakPtrFactory<GCMEncryptionProvider> weak_ptr_factory_; |