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

Side by Side Diff: chrome/browser/chromeos/platform_keys/key_permissions.h

Issue 1150373002: platformKeys: Add policy and corporate key tagging. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@key_perm
Patch Set: Created 5 years, 6 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 unified diff | Download patch
OLDNEW
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 #ifndef CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_KEY_PERMISSIONS_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_KEY_PERMISSIONS_H_
6 #define CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_KEY_PERMISSIONS_H_ 6 #define CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_KEY_PERMISSIONS_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback_forward.h" 10 #include "base/callback_forward.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 13
14 class PrefService;
15
14 namespace base { 16 namespace base {
17 class DictionaryValue;
15 class Value; 18 class Value;
16 } 19 }
17 20
18 namespace extensions { 21 namespace extensions {
19 class StateStore; 22 class StateStore;
20 } 23 }
21 24
25 namespace policy {
26 class PolicyService;
27 }
28
29 namespace user_prefs {
30 class PrefRegistrySyncable;
31 }
32
22 namespace chromeos { 33 namespace chromeos {
23 34
24 // This class manages permissions for extensions to use private keys through 35 // This class manages permissions for extensions to use private keys through
25 // chrome.platformKeys . 36 // chrome.platformKeys .
26 // It handles the following permissions: 37 // It handles the following permissions:
27 // * The extension that generated a key has the permission to sign arbitrary 38 // * The extension that generated a key has the permission to sign arbitrary
28 // data with that key at most once. 39 // data with that key at most once.
29 // * The user can grant an extension the permission to sign arbitrary data 40 // * The user can grant an extension the permission to sign arbitrary data
30 // with a key an unlimited number of times. 41 // with a key an unlimited number of times.
31 class KeyPermissions { 42 class KeyPermissions {
32 public: 43 public:
33 // Allows querying and modifying permissions and registering keys for a 44 // Allows querying and modifying permissions and registering keys for a
34 // specific extension. 45 // specific extension.
35 class PermissionsForExtension { 46 class PermissionsForExtension {
36 public: 47 public:
37 // |key_permissions| must not be null and outlive this object. 48 // |key_permissions| must not be null and outlive this object.
38 // Methods of this object refer implicitly to the extension with the id 49 // Methods of this object refer implicitly to the extension with the id
39 // |extension_id|. 50 // |extension_id|.
40 // Don't use this constructor directly. Call 51 // Don't use this constructor directly. Call
41 // |KeyPermissions::GetPermissionsForExtension| instead. 52 // |KeyPermissions::GetPermissionsForExtension| instead.
42 PermissionsForExtension(const std::string& extension_id, 53 PermissionsForExtension(const std::string& extension_id,
43 scoped_ptr<base::Value> state_store_value, 54 scoped_ptr<base::Value> state_store_value,
55 PrefService* profile_prefs,
56 policy::PolicyService* profile_policies,
44 KeyPermissions* key_permissions); 57 KeyPermissions* key_permissions);
45 58
46 ~PermissionsForExtension(); 59 ~PermissionsForExtension();
47 60
48 // Returns true if the private key matching |public_key_spki_der| can be 61 // Returns true if the private key matching |public_key_spki_der| can be
49 // used for signing by the extension with id |extension_id|. 62 // used for signing by the extension with id |extension_id|.
50 bool CanUseKeyForSigning(const std::string& public_key_spki_der); 63 bool CanUseKeyForSigning(const std::string& public_key_spki_der);
51 64
52 // Registers the key |public_key_spki_der| as being generated by the 65 // Registers the key |public_key_spki_der| as being generated by the
53 // extension with id |extension_id| and marks it for corporate usage. 66 // extension with id |extension_id| and marks it for corporate usage.
(...skipping 22 matching lines...) Expand all
76 // |state_store_entries_|. 89 // |state_store_entries_|.
77 void KeyEntriesFromState(const base::Value& state); 90 void KeyEntriesFromState(const base::Value& state);
78 91
79 // Converts |state_store_entries_| to a base::Value for storing in the state 92 // Converts |state_store_entries_| to a base::Value for storing in the state
80 // store. 93 // store.
81 scoped_ptr<base::Value> KeyEntriesToState(); 94 scoped_ptr<base::Value> KeyEntriesToState();
82 95
83 // Returns an existing entry for |public_key_spki_der| from 96 // Returns an existing entry for |public_key_spki_der| from
84 // |state_store_entries_|. If there is no existing entry, creates, adds and 97 // |state_store_entries_|. If there is no existing entry, creates, adds and
85 // returns a new entry. 98 // returns a new entry.
86 KeyPermissions::PermissionsForExtension::KeyEntry* GetKeyEntry( 99 KeyPermissions::PermissionsForExtension::KeyEntry* GetStateStoreEntry(
87 const std::string& public_key_spki_der); 100 const std::string& public_key_spki_der);
88 101
102 bool PolicyAllowsCorporateKeyUsage();
103
89 const std::string extension_id_; 104 const std::string extension_id_;
90 std::vector<KeyEntry> state_store_entries_; 105 std::vector<KeyEntry> state_store_entries_;
106 PrefService* const profile_prefs_;
107 policy::PolicyService* const profile_policies_;
91 KeyPermissions* const key_permissions_; 108 KeyPermissions* const key_permissions_;
92 109
93 DISALLOW_COPY_AND_ASSIGN(PermissionsForExtension); 110 DISALLOW_COPY_AND_ASSIGN(PermissionsForExtension);
94 }; 111 };
95 112
96 // |extensions_state_store| must not be null and outlive this object. 113 // |profile_prefs| and |extensions_state_store| must not be null and outlive
97 explicit KeyPermissions(extensions::StateStore* extensions_state_store); 114 // this object.
115 // If |profile_is_managed| is false, |profile_policies| is ignored. Otherwise,
116 // |profile_policies| must not be null and outlive this object.
117 KeyPermissions(PrefService* profile_prefs,
118 bool profile_is_managed,
119 policy::PolicyService* profile_policies,
120 extensions::StateStore* extensions_state_store);
98 121
99 ~KeyPermissions(); 122 ~KeyPermissions();
100 123
101 using PermissionsCallback = 124 using PermissionsCallback =
102 base::Callback<void(scoped_ptr<PermissionsForExtension>)>; 125 base::Callback<void(scoped_ptr<PermissionsForExtension>)>;
103 126
104 // Passes an object managing the key permissions of the extension with id 127 // Passes an object managing the key permissions of the extension with id
105 // |extension_id| to |callback|. This can happen synchronously or 128 // |extension_id| to |callback|. This can happen synchronously or
106 // asynchronously. 129 // asynchronously.
107 void GetPermissionsForExtension(const std::string& extension_id, 130 void GetPermissionsForExtension(const std::string& extension_id,
108 const PermissionsCallback& callback); 131 const PermissionsCallback& callback);
109 132
133 // Returns true if the user can grant any permission for |public_key_spki_der|
134 // to extensions.
135 bool CanUserGrantPermissionFor(const std::string& public_key_spki_der);
136
137 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
138
110 private: 139 private:
140 bool IsCorporateKey(const std::string& public_key_spki_der);
141
111 // Creates a PermissionsForExtension object from |extension_id| and |value| 142 // Creates a PermissionsForExtension object from |extension_id| and |value|
112 // and passes the object to |callback|. 143 // and passes the object to |callback|.
113 void CreatePermissionObjectAndPassToCallback( 144 void CreatePermissionObjectAndPassToCallback(
114 const std::string& extension_id, 145 const std::string& extension_id,
115 const PermissionsCallback& callback, 146 const PermissionsCallback& callback,
116 scoped_ptr<base::Value> value); 147 scoped_ptr<base::Value> value);
117 148
118 // Writes |value| to the state store of the extension with id |extension_id|. 149 // Writes |value| to the state store of the extension with id |extension_id|.
119 void SetPlatformKeysOfExtension(const std::string& extension_id, 150 void SetPlatformKeysOfExtension(const std::string& extension_id,
120 scoped_ptr<base::Value> value); 151 scoped_ptr<base::Value> value);
121 152
153 const base::DictionaryValue* GetPrefsEntry(
154 const std::string& public_key_spki_der);
155
156 PrefService* const profile_prefs_;
157 bool profile_is_managed_;
158 policy::PolicyService* const profile_policies_;
122 extensions::StateStore* const extensions_state_store_; 159 extensions::StateStore* const extensions_state_store_;
123 base::WeakPtrFactory<KeyPermissions> weak_factory_; 160 base::WeakPtrFactory<KeyPermissions> weak_factory_;
124 161
125 DISALLOW_COPY_AND_ASSIGN(KeyPermissions); 162 DISALLOW_COPY_AND_ASSIGN(KeyPermissions);
126 }; 163 };
127 164
128 } // namespace chromeos 165 } // namespace chromeos
129 166
130 #endif // CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_KEY_PERMISSIONS_H_ 167 #endif // CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_KEY_PERMISSIONS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698