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 #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 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 | 14 |
| 15 class PrefService; |
| 16 |
15 namespace base { | 17 namespace base { |
| 18 class DictionaryValue; |
16 class Value; | 19 class Value; |
17 } | 20 } |
18 | 21 |
19 namespace extensions { | 22 namespace extensions { |
20 class StateStore; | 23 class StateStore; |
21 } | 24 } |
22 | 25 |
| 26 namespace policy { |
| 27 class PolicyService; |
| 28 } |
| 29 |
| 30 namespace user_prefs { |
| 31 class PrefRegistrySyncable; |
| 32 } |
| 33 |
23 namespace chromeos { | 34 namespace chromeos { |
24 | 35 |
25 // This class manages permissions for extensions to use private keys through | 36 // This class manages permissions for extensions to use private keys through |
26 // chrome.platformKeys . | 37 // chrome.platformKeys . |
27 // It handles the following permissions: | 38 // It handles the following permissions: |
28 // * The extension that generated a key has the permission to sign arbitrary | 39 // * The extension that generated a key has the permission to sign arbitrary |
29 // data with that key at most once. | 40 // data with that key at most once. |
30 // * The user can explicitly grant an extension the permission to sign | 41 // * The user can explicitly grant an extension the permission to sign |
31 // arbitrary data with a key an unlimited number of times. | 42 // arbitrary data with a key an unlimited number of times. |
| 43 // |
| 44 // Additionally, it takes care of restrictions that apply on managed profiles, |
| 45 // applies the KeyPermissions policy and distinguishes corporate from |
| 46 // non-corporate keys. |
32 class KeyPermissions { | 47 class KeyPermissions { |
33 public: | 48 public: |
34 // Allows querying and modifying permissions and registering keys for a | 49 // Allows querying and modifying permissions and registering keys for a |
35 // specific extension. | 50 // specific extension. |
36 class PermissionsForExtension { | 51 class PermissionsForExtension { |
37 public: | 52 public: |
38 // |key_permissions| must not be null and outlive this object. | 53 // |key_permissions| must not be null and outlive this object. |
39 // Methods of this object refer implicitly to the extension with the id | 54 // Methods of this object refer implicitly to the extension with the id |
40 // |extension_id|. Don't use this constructor directly. Call | 55 // |extension_id|. Don't use this constructor directly. Call |
41 // |KeyPermissions::GetPermissionsForExtension| instead. | 56 // |KeyPermissions::GetPermissionsForExtension| instead. |
42 PermissionsForExtension(const std::string& extension_id, | 57 PermissionsForExtension(const std::string& extension_id, |
43 scoped_ptr<base::Value> state_store_value, | 58 scoped_ptr<base::Value> state_store_value, |
| 59 PrefService* profile_prefs, |
| 60 policy::PolicyService* profile_policies, |
44 KeyPermissions* key_permissions); | 61 KeyPermissions* key_permissions); |
45 | 62 |
46 ~PermissionsForExtension(); | 63 ~PermissionsForExtension(); |
47 | 64 |
48 // Returns true if the private key matching |public_key_spki_der| can be | 65 // Returns true if the private key matching |public_key_spki_der| can be |
49 // used for signing by the extension with id |extension_id|. | 66 // used for signing by the extension with id |extension_id|. |
50 // |public_key_spki_der| must be the DER of a Subject Public Key Info. | 67 // |public_key_spki_der| must be the DER of a Subject Public Key Info. |
51 bool CanUseKeyForSigning(const std::string& public_key_spki_der); | 68 bool CanUseKeyForSigning(const std::string& public_key_spki_der); |
52 | 69 |
53 // Registers the key |public_key_spki_der| as being generated by the | 70 // Registers the key |public_key_spki_der| as being generated by the |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 scoped_ptr<base::Value> KeyEntriesToState(); | 102 scoped_ptr<base::Value> KeyEntriesToState(); |
86 | 103 |
87 // Returns an existing entry for |public_key_spki_der_b64| from | 104 // Returns an existing entry for |public_key_spki_der_b64| from |
88 // |state_store_entries_|. If there is no existing entry, creates, adds and | 105 // |state_store_entries_|. If there is no existing entry, creates, adds and |
89 // returns a new entry. | 106 // returns a new entry. |
90 // |public_key_spki_der| must be the base64 encoding of the DER of a Subject | 107 // |public_key_spki_der| must be the base64 encoding of the DER of a Subject |
91 // Public Key Info. | 108 // Public Key Info. |
92 KeyPermissions::PermissionsForExtension::KeyEntry* GetStateStoreEntry( | 109 KeyPermissions::PermissionsForExtension::KeyEntry* GetStateStoreEntry( |
93 const std::string& public_key_spki_der_b64); | 110 const std::string& public_key_spki_der_b64); |
94 | 111 |
| 112 bool PolicyAllowsCorporateKeyUsage(); |
| 113 |
95 const std::string extension_id_; | 114 const std::string extension_id_; |
96 std::vector<KeyEntry> state_store_entries_; | 115 std::vector<KeyEntry> state_store_entries_; |
| 116 PrefService* const profile_prefs_; |
| 117 policy::PolicyService* const profile_policies_; |
97 KeyPermissions* const key_permissions_; | 118 KeyPermissions* const key_permissions_; |
98 | 119 |
99 DISALLOW_COPY_AND_ASSIGN(PermissionsForExtension); | 120 DISALLOW_COPY_AND_ASSIGN(PermissionsForExtension); |
100 }; | 121 }; |
101 | 122 |
102 // |extensions_state_store| must not be null and outlive this object. | 123 // |profile_prefs| and |extensions_state_store| must not be null and outlive |
| 124 // this object. |
| 125 // If |profile_is_managed| is false, |profile_policies| is ignored. Otherwise, |
| 126 // |profile_policies| must not be null and outlive this object. |
103 // |profile_is_managed| determines the default usage and permissions for | 127 // |profile_is_managed| determines the default usage and permissions for |
104 // keys without explicitly assigned usage. | 128 // keys without explicitly assigned usage. |
105 KeyPermissions(bool profile_is_managed, | 129 KeyPermissions(bool profile_is_managed, |
| 130 PrefService* profile_prefs, |
| 131 policy::PolicyService* profile_policies, |
106 extensions::StateStore* extensions_state_store); | 132 extensions::StateStore* extensions_state_store); |
107 | 133 |
108 ~KeyPermissions(); | 134 ~KeyPermissions(); |
109 | 135 |
110 using PermissionsCallback = | 136 using PermissionsCallback = |
111 base::Callback<void(scoped_ptr<PermissionsForExtension>)>; | 137 base::Callback<void(scoped_ptr<PermissionsForExtension>)>; |
112 | 138 |
113 // Passes an object managing the key permissions of the extension with id | 139 // Passes an object managing the key permissions of the extension with id |
114 // |extension_id| to |callback|. This can happen synchronously or | 140 // |extension_id| to |callback|. This can happen synchronously or |
115 // asynchronously. | 141 // asynchronously. |
116 void GetPermissionsForExtension(const std::string& extension_id, | 142 void GetPermissionsForExtension(const std::string& extension_id, |
117 const PermissionsCallback& callback); | 143 const PermissionsCallback& callback); |
118 | 144 |
119 // Returns true if the user can grant any permission for |public_key_spki_der| | 145 // Returns true if the user can grant any permission for |public_key_spki_der| |
120 // to extensions. |public_key_spki_der| must be the DER of a Subject Public | 146 // to extensions. |public_key_spki_der| must be the DER of a Subject Public |
121 // Key Info. | 147 // Key Info. |
122 bool CanUserGrantPermissionFor(const std::string& public_key_spki_der); | 148 bool CanUserGrantPermissionFor(const std::string& public_key_spki_der); |
123 | 149 |
| 150 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| 151 |
124 private: | 152 private: |
| 153 bool IsCorporateKey(const std::string& public_key_spki_der_b64); |
| 154 |
125 // Creates a PermissionsForExtension object from |extension_id| and |value| | 155 // Creates a PermissionsForExtension object from |extension_id| and |value| |
126 // and passes the object to |callback|. | 156 // and passes the object to |callback|. |
127 void CreatePermissionObjectAndPassToCallback( | 157 void CreatePermissionObjectAndPassToCallback( |
128 const std::string& extension_id, | 158 const std::string& extension_id, |
129 const PermissionsCallback& callback, | 159 const PermissionsCallback& callback, |
130 scoped_ptr<base::Value> value); | 160 scoped_ptr<base::Value> value); |
131 | 161 |
132 // Writes |value| to the state store of the extension with id |extension_id|. | 162 // Writes |value| to the state store of the extension with id |extension_id|. |
133 void SetPlatformKeysOfExtension(const std::string& extension_id, | 163 void SetPlatformKeysOfExtension(const std::string& extension_id, |
134 scoped_ptr<base::Value> value); | 164 scoped_ptr<base::Value> value); |
135 | 165 |
| 166 const base::DictionaryValue* GetPrefsEntry( |
| 167 const std::string& public_key_spki_der_b64); |
| 168 |
136 const bool profile_is_managed_; | 169 const bool profile_is_managed_; |
| 170 PrefService* const profile_prefs_; |
| 171 policy::PolicyService* const profile_policies_; |
137 extensions::StateStore* const extensions_state_store_; | 172 extensions::StateStore* const extensions_state_store_; |
138 base::WeakPtrFactory<KeyPermissions> weak_factory_; | 173 base::WeakPtrFactory<KeyPermissions> weak_factory_; |
139 | 174 |
140 DISALLOW_COPY_AND_ASSIGN(KeyPermissions); | 175 DISALLOW_COPY_AND_ASSIGN(KeyPermissions); |
141 }; | 176 }; |
142 | 177 |
143 } // namespace chromeos | 178 } // namespace chromeos |
144 | 179 |
145 #endif // CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_KEY_PERMISSIONS_H_ | 180 #endif // CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_KEY_PERMISSIONS_H_ |
OLD | NEW |