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

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

Issue 1953273002: Add support to GCMKeyStore for multiple keys per app_id (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@iid6fixstore
Patch Set: Simplify Decrypt fallback by banning IID token & GCM reg from sharing same app_id Created 4 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 side-by-side diff with in-line comments
Download patch
Index: components/gcm_driver/crypto/gcm_key_store.h
diff --git a/components/gcm_driver/crypto/gcm_key_store.h b/components/gcm_driver/crypto/gcm_key_store.h
index 05efc034ad096d7b48bf32708306c5e8ca594c83..b83c3b9b1f933eb6be6eda33a65bd859b5ff4c69 100644
--- a/components/gcm_driver/crypto/gcm_key_store.h
+++ b/components/gcm_driver/crypto/gcm_key_store.h
@@ -5,9 +5,10 @@
#ifndef COMPONENTS_GCM_DRIVER_CRYPTO_GCM_KEY_STORE_H_
#define COMPONENTS_GCM_DRIVER_CRYPTO_GCM_KEY_STORE_H_
-#include <map>
#include <memory>
#include <string>
+#include <unordered_map>
+#include <utility>
#include <vector>
#include "base/callback_forward.h"
@@ -31,7 +32,7 @@ namespace gcm {
// Key storage for use with encrypted messages received from Google Cloud
// Messaging. It provides the ability to create and store a key-pair for a given
-// app id, as well as retrieving and deleting key-pairs.
+// app id + authorized entity pair, and to retrieve and delete key-pairs.
//
// This class is backed by a proto database and might end up doing file I/O on
// a background task runner. For this reason, all public APIs take a callback
@@ -46,17 +47,38 @@ class GCMKeyStore {
const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner);
~GCMKeyStore();
- // Retrieves the public/private key-pair associated with |app_id|, and
- // invokes |callback| when they are available, or when an error occurred.
- void GetKeys(const std::string& app_id, const KeysCallback& callback);
-
- // Creates a new public/private key-pair for |app_id|, and invokes
- // |callback| when they are available, or when an error occurred.
- void CreateKeys(const std::string& app_id, const KeysCallback& callback);
-
- // Removes the keys associated with |app_id|, and invokes |callback| when
- // the operation has finished.
- void RemoveKeys(const std::string& app_id, const base::Closure& callback);
+ // Retrieves the public/private key-pair associated with the |app_id| +
+ // authorized entity pair, and invokes |callback| when they are available, or
+ // when an error occurred.
+ // |instance_id_authorized_entity|: pass InstanceID token's authorized_entity
+ // or "" for legacy GCM registrations.
+ // |fallback_to_empty_authorized_entity|: if true and the keys are not found,
+ // will try again with empty authorized
+ // entity (use this when you're not
+ // sure if you have an Instance ID).
+ void GetKeys(const std::string& app_id,
+ const std::string& instance_id_authorized_entity,
+ bool fallback_to_empty_authorized_entity,
+ const KeysCallback& callback);
+
+ // Creates a new public/private key-pair for the |app_id| + authorized entity
+ // pair, and invokes |callback| when they are available, or when an error
+ // occurred. Simultaneously using the same |app_id| for both a legacy GCM
+ // registration and one or more InstanceID tokens is not supported.
+ // |instance_id_authorized_entity|: pass InstanceID token's authorized_entity
+ // or "" for legacy GCM registrations.
+ void CreateKeys(const std::string& app_id,
+ const std::string& instance_id_authorized_entity,
+ const KeysCallback& callback);
+
+ // Removes the keys associated with the |app_id| + authorized entity pair, and
+ // invokes |callback| when the operation has finished.
+ // |instance_id_authorized_entity|: pass InstanceID token's authorized_entity
+ // or "*" to remove for all InstanceID tokens
+ // or "" for legacy GCM registrations.
+ void RemoveKeys(const std::string& app_id,
+ const std::string& instance_id_authorized_entity,
+ const base::Closure& callback);
private:
// Initializes the database if necessary, and runs |done_closure| when done.
@@ -77,11 +99,17 @@ class GCMKeyStore {
// has either been successfully loaded, or failed to load.
void GetKeysAfterInitialize(const std::string& app_id,
+ const std::string& instance_id_authorized_entity,
+ bool fallback_to_empty_authorized_entity,
const KeysCallback& callback);
- void CreateKeysAfterInitialize(const std::string& app_id,
- const KeysCallback& callback);
- void RemoveKeysAfterInitialize(const std::string& app_id,
- const base::Closure& callback);
+ void CreateKeysAfterInitialize(
+ const std::string& app_id,
+ const std::string& instance_id_authorized_entity,
+ const KeysCallback& callback);
+ void RemoveKeysAfterInitialize(
+ const std::string& app_id,
+ const std::string& instance_id_authorized_entity,
+ const base::Closure& callback);
// Path in which the key store database will be saved.
base::FilePath key_store_path_;
@@ -101,10 +129,12 @@ class GCMKeyStore {
// finished initializing.
GCMDelayedTaskController delayed_task_controller_;
- // Mapping of an app id to the loaded key pair and authentication secrets.
- // TODO(peter): Switch these to std::unordered_map<> once allowed.
- std::map<std::string, KeyPair> key_pairs_;
- std::map<std::string, std::string> auth_secrets_;
+ // Nested map from app_id to a map from instance_id_authorized_entity to the
+ // loaded key pair and authentication secrets.
+ using KeyPairAndAuthSecret = std::pair<KeyPair, std::string>;
+ std::unordered_map<std::string,
Peter Beverloo 2016/05/09 14:10:10 Why can't we use a multimap from |app_id| to a tup
johnme 2016/05/09 18:15:55 I considered that, but I'm not convinced a multima
+ std::unordered_map<std::string, KeyPairAndAuthSecret>>
+ key_data_;
base::WeakPtrFactory<GCMKeyStore> weak_factory_;

Powered by Google App Engine
This is Rietveld 408576698