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

Unified Diff: components/gcm_driver/crypto/gcm_encryption_provider.h

Issue 1243563002: Teach the GCM Driver how to decrypt incoming messages. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gcm-push-keys
Patch Set: address comment Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/gcm_driver/crypto/BUILD.gn ('k') | components/gcm_driver/crypto/gcm_encryption_provider.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..c4ff271ea48a278d876b4fadcea055d8d0e2b337 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 {
+ DECRYPTION_FAILURE_UNKNOWN,
+
+ // 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
+ };
+
+ // 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);
+
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_;
« no previous file with comments | « components/gcm_driver/crypto/BUILD.gn ('k') | components/gcm_driver/crypto/gcm_encryption_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698