OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_PLATFORM_KEYS_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_PLATFORM_KEYS_SERVICE_H_ |
6 #define CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_PLATFORM_KEYS_SERVICE_H_ | 6 #define CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_PLATFORM_KEYS_SERVICE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 // only. | 78 // only. |
79 // Will only call back during the lifetime of this object. | 79 // Will only call back during the lifetime of this object. |
80 void Sign(const std::string& token_id, | 80 void Sign(const std::string& token_id, |
81 const std::string& public_key_spki_der, | 81 const std::string& public_key_spki_der, |
82 platform_keys::HashAlgorithm hash_algorithm, | 82 platform_keys::HashAlgorithm hash_algorithm, |
83 const std::string& data, | 83 const std::string& data, |
84 const std::string& extension_id, | 84 const std::string& extension_id, |
85 const SignCallback& callback); | 85 const SignCallback& callback); |
86 | 86 |
87 private: | 87 private: |
88 typedef base::Callback<void(scoped_ptr<base::ListValue> platform_keys)> | 88 using GetPlatformKeysCallback = |
89 GetPlatformKeysCallback; | 89 base::Callback<void(scoped_ptr<base::ListValue> platform_keys)>; |
90 | 90 |
91 // Registers the given public key as newly generated key, which is allowed to | 91 // Registers the given public key as newly generated key, which is allowed to |
92 // be used for signing for a single time. Afterwards, calls |callback|. If | 92 // be used for signing for a single time. Afterwards, calls |callback|. If |
93 // registration was successful, passes |true| otherwise |false| to the | 93 // registration was successful, passes |true| otherwise |false| to the |
94 // callback. | 94 // callback. |
95 void RegisterPublicKey(const std::string& extension_id, | 95 void RegisterPublicKey(const std::string& extension_id, |
96 const std::string& public_key_spki_der, | 96 const std::string& public_key_spki_der, |
97 const base::Callback<void(bool)>& callback); | 97 const base::Closure& callback); |
98 | 98 |
99 // Gets the current validity of the given public key by reading StateStore. | 99 // Gets the current validity of the given public key by reading StateStore. |
100 // Invalidates the key if it was found to be valid. Finally, calls |callback| | 100 // Invalidates the key if it was found to be valid. Finally, calls |callback| |
101 // with the old validity. | 101 // with the old validity. |
102 void ReadValidityAndInvalidateKey(const std::string& extension_id, | 102 void ReadValidityAndInvalidateKey(const std::string& extension_id, |
103 const std::string& public_key_spki_der, | 103 const std::string& public_key_spki_der, |
104 const base::Callback<void(bool)>& callback); | 104 const base::Callback<void(bool)>& callback); |
105 | 105 |
106 // Reads the list of public keys currently registered for |extension_id| from | 106 // Reads the list of public keys currently registered for |extension_id| from |
107 // StateStore. Calls |callback| with the read list, or a new empty list if | 107 // StateStore. Calls |callback| with the read list, or a new empty list if |
108 // none existed. If an error occurred, calls |callback| with NULL. | 108 // none existed. If an error occurred, calls |callback| with NULL. |
109 void GetPlatformKeysOfExtension(const std::string& extension_id, | 109 void GetPlatformKeysOfExtension(const std::string& extension_id, |
110 const GetPlatformKeysCallback& callback); | 110 const GetPlatformKeysCallback& callback); |
111 | 111 |
| 112 // Writes |platform_keys| to the state store of the extension with id |
| 113 // |extension_id|. |
| 114 void SetPlatformKeysOfExtension(const std::string& extension_id, |
| 115 scoped_ptr<base::ListValue> platform_keys); |
| 116 |
112 // Callback used by |GenerateRSAKey|. | 117 // Callback used by |GenerateRSAKey|. |
113 // If the key generation was successful, registers the generated public key | 118 // If the key generation was successful, registers the generated public key |
114 // for the given extension. If any error occurs during key generation or | 119 // for the given extension. If any error occurs during key generation or |
115 // registration, calls |callback| with an error. Otherwise, on success, calls | 120 // registration, calls |callback| with an error. Otherwise, on success, calls |
116 // |callback| with the public key. | 121 // |callback| with the public key. |
117 void GenerateRSAKeyCallback(const std::string& extension_id, | 122 void GenerateRSAKeyCallback(const std::string& extension_id, |
118 const GenerateKeyCallback& callback, | 123 const GenerateKeyCallback& callback, |
119 const std::string& public_key_spki_der, | 124 const std::string& public_key_spki_der, |
120 const std::string& error_message); | 125 const std::string& error_message); |
121 | 126 |
122 // Callback used by |RegisterPublicKey|. | 127 // Callback used by |RegisterPublicKey|. |
123 // Updates the old |platform_keys| read from the StateStore and writes the | 128 // Updates the old |platform_keys| read from the StateStore and writes the |
124 // updated value back to the StateStore. | 129 // updated value back to the StateStore. |
125 void RegisterPublicKeyGotPlatformKeys( | 130 void RegisterPublicKeyGotPlatformKeys( |
126 const std::string& extension_id, | 131 const std::string& extension_id, |
127 const std::string& public_key_spki_der, | 132 const std::string& public_key_spki_der, |
128 const base::Callback<void(bool)>& callback, | 133 const base::Closure& callback, |
129 scoped_ptr<base::ListValue> platform_keys); | 134 scoped_ptr<base::ListValue> platform_keys); |
130 | 135 |
131 // Callback used by |ReadValidityAndInvalidateKey|. | 136 // Callback used by |ReadValidityAndInvalidateKey|. |
132 // Invalidates the given public key so that future signing is prohibited and | 137 // Invalidates the given public key so that future signing is prohibited and |
133 // calls |callback| with the old validity. | 138 // calls |callback| with the old validity. |
134 void InvalidateKey(const std::string& extension_id, | 139 void InvalidateKey(const std::string& extension_id, |
135 const std::string& public_key_spki_der, | 140 const std::string& public_key_spki_der, |
136 const base::Callback<void(bool)>& callback, | 141 const base::Callback<void(bool)>& callback, |
137 scoped_ptr<base::ListValue> platform_keys); | 142 scoped_ptr<base::ListValue> platform_keys); |
138 | 143 |
139 // Callback used by |GetPlatformKeysOfExtension|. | 144 // Callback used by |GetPlatformKeysOfExtension|. |
140 // Is called with |value| set to the PlatformKeys value read from the | 145 // Is called with |value| set to the PlatformKeys value read from the |
141 // StateStore, which it forwards to |callback|. On error, calls |callback| | 146 // StateStore, which it forwards to |callback|. On error, calls |callback| |
142 // with NULL; if no value existed, with an empty list. | 147 // with NULL; if no value existed, with an empty list. |
143 void GotPlatformKeysOfExtension(const std::string& extension_id, | 148 void GotPlatformKeysOfExtension(const std::string& extension_id, |
144 const GetPlatformKeysCallback& callback, | 149 const GetPlatformKeysCallback& callback, |
145 scoped_ptr<base::Value> value); | 150 scoped_ptr<base::Value> value); |
146 | 151 |
147 content::BrowserContext* browser_context_; | 152 content::BrowserContext* browser_context_; |
148 extensions::StateStore* state_store_; | 153 extensions::StateStore* state_store_; |
149 base::WeakPtrFactory<PlatformKeysService> weak_factory_; | 154 base::WeakPtrFactory<PlatformKeysService> weak_factory_; |
150 | 155 |
151 DISALLOW_COPY_AND_ASSIGN(PlatformKeysService); | 156 DISALLOW_COPY_AND_ASSIGN(PlatformKeysService); |
152 }; | 157 }; |
153 | 158 |
154 } // namespace chromeos | 159 } // namespace chromeos |
155 | 160 |
156 #endif // CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_PLATFORM_KEYS_SERVICE_H_ | 161 #endif // CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_PLATFORM_KEYS_SERVICE_H_ |
OLD | NEW |