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 #include <vector> |
9 | 10 |
10 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
14 #include "chrome/browser/chromeos/platform_keys/platform_keys.h" | 15 #include "chrome/browser/chromeos/platform_keys/platform_keys.h" |
15 #include "components/keyed_service/core/keyed_service.h" | 16 #include "components/keyed_service/core/keyed_service.h" |
16 | 17 |
17 namespace content { | 18 namespace content { |
18 class BrowserContext; | 19 class BrowserContext; |
19 } | 20 } |
20 | 21 |
21 namespace base { | 22 namespace base { |
22 class ListValue; | 23 class ListValue; |
23 class Value; | 24 class Value; |
24 } | 25 } |
25 | 26 |
26 namespace extensions { | 27 namespace extensions { |
27 class StateStore; | 28 class StateStore; |
28 } | 29 } |
29 | 30 |
| 31 namespace net { |
| 32 class X509Certificate; |
| 33 typedef std::vector<scoped_refptr<X509Certificate>> CertificateList; |
| 34 } |
| 35 |
30 namespace chromeos { | 36 namespace chromeos { |
31 | 37 |
32 class PlatformKeysService : public KeyedService { | 38 class PlatformKeysService : public KeyedService { |
33 public: | 39 public: |
34 // Stores registration information in |state_store|, i.e. for each extension | 40 // Stores registration information in |state_store|, i.e. for each extension |
35 // the list of public keys that are valid to be used for signing. Each key can | 41 // the list of public keys that are valid to be used for signing. Each key can |
36 // be used for signing at most once. | 42 // be used for signing at most once. |
37 // The format written to |state_store| is: | 43 // The format written to |state_store| is: |
38 // kStateStorePlatformKeys maps to a list of strings. | 44 // kStateStorePlatformKeys maps to a list of strings. |
39 // Each string is the base64 encoding of the DER representation of a public | 45 // Each string is the base64 encoding of the DER representation of a public |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 // invoked with the signature or an error message. Currently supports RSA keys | 83 // invoked with the signature or an error message. Currently supports RSA keys |
78 // only. | 84 // only. |
79 // Will only call back during the lifetime of this object. | 85 // Will only call back during the lifetime of this object. |
80 void Sign(const std::string& token_id, | 86 void Sign(const std::string& token_id, |
81 const std::string& public_key_spki_der, | 87 const std::string& public_key_spki_der, |
82 platform_keys::HashAlgorithm hash_algorithm, | 88 platform_keys::HashAlgorithm hash_algorithm, |
83 const std::string& data, | 89 const std::string& data, |
84 const std::string& extension_id, | 90 const std::string& extension_id, |
85 const SignCallback& callback); | 91 const SignCallback& callback); |
86 | 92 |
| 93 // If the certificate request could be processed successfully, |matches| will |
| 94 // contain the list of matching certificates (maybe empty) and |error_message| |
| 95 // will be empty. If an error occurred, |matches| will be null and |
| 96 // |error_message| contain an error message. |
| 97 typedef base::Callback<void(scoped_ptr<net::CertificateList> matches, |
| 98 const std::string& error_message)> |
| 99 SelectCertificatesCallback; |
| 100 |
| 101 // Returns the list of all certificates that match |request|. |callback| will |
| 102 // be invoked with these matches or an error message. |
| 103 // Will only call back during the lifetime of this object. |
| 104 // TODO(pneubeck): Add the interactive option and integrate the select |
| 105 // certificate dialog. |
| 106 void SelectClientCertificates( |
| 107 const platform_keys::ClientCertificateRequest& request, |
| 108 const std::string& extension_id, |
| 109 const SelectCertificatesCallback& callback); |
| 110 |
87 private: | 111 private: |
88 typedef base::Callback<void(scoped_ptr<base::ListValue> platform_keys)> | 112 typedef base::Callback<void(scoped_ptr<base::ListValue> platform_keys)> |
89 GetPlatformKeysCallback; | 113 GetPlatformKeysCallback; |
90 | 114 |
91 // Registers the given public key as newly generated key, which is allowed to | 115 // 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 | 116 // be used for signing for a single time. Afterwards, calls |callback|. If |
93 // registration was successful, passes |true| otherwise |false| to the | 117 // registration was successful, passes |true| otherwise |false| to the |
94 // callback. | 118 // callback. |
95 void RegisterPublicKey(const std::string& extension_id, | 119 void RegisterPublicKey(const std::string& extension_id, |
96 const std::string& public_key_spki_der, | 120 const std::string& public_key_spki_der, |
(...skipping 15 matching lines...) Expand all Loading... |
112 // Callback used by |GenerateRSAKey|. | 136 // Callback used by |GenerateRSAKey|. |
113 // If the key generation was successful, registers the generated public key | 137 // If the key generation was successful, registers the generated public key |
114 // for the given extension. If any error occurs during key generation or | 138 // for the given extension. If any error occurs during key generation or |
115 // registration, calls |callback| with an error. Otherwise, on success, calls | 139 // registration, calls |callback| with an error. Otherwise, on success, calls |
116 // |callback| with the public key. | 140 // |callback| with the public key. |
117 void GenerateRSAKeyCallback(const std::string& extension_id, | 141 void GenerateRSAKeyCallback(const std::string& extension_id, |
118 const GenerateKeyCallback& callback, | 142 const GenerateKeyCallback& callback, |
119 const std::string& public_key_spki_der, | 143 const std::string& public_key_spki_der, |
120 const std::string& error_message); | 144 const std::string& error_message); |
121 | 145 |
| 146 // Calback used by |SelectClientCertificates|. |
| 147 // If the certificate request could be processed successfully, |matches| will |
| 148 // contain the list of matching certificates (maybe empty) and |error_message| |
| 149 // will be empty. If an error occurred, |matches| will be null and |
| 150 // |error_message| contain an error message. |
| 151 void SelectClientCertificatesCallback( |
| 152 const std::string& extension_id, |
| 153 const SelectCertificatesCallback& callback, |
| 154 scoped_ptr<net::CertificateList> matches, |
| 155 const std::string& error_message); |
| 156 |
122 // Callback used by |RegisterPublicKey|. | 157 // Callback used by |RegisterPublicKey|. |
123 // Updates the old |platform_keys| read from the StateStore and writes the | 158 // Updates the old |platform_keys| read from the StateStore and writes the |
124 // updated value back to the StateStore. | 159 // updated value back to the StateStore. |
125 void RegisterPublicKeyGotPlatformKeys( | 160 void RegisterPublicKeyGotPlatformKeys( |
126 const std::string& extension_id, | 161 const std::string& extension_id, |
127 const std::string& public_key_spki_der, | 162 const std::string& public_key_spki_der, |
128 const base::Callback<void(bool)>& callback, | 163 const base::Callback<void(bool)>& callback, |
129 scoped_ptr<base::ListValue> platform_keys); | 164 scoped_ptr<base::ListValue> platform_keys); |
130 | 165 |
131 // Callback used by |ReadValidityAndInvalidateKey|. | 166 // Callback used by |ReadValidityAndInvalidateKey|. |
(...skipping 15 matching lines...) Expand all Loading... |
147 content::BrowserContext* browser_context_; | 182 content::BrowserContext* browser_context_; |
148 extensions::StateStore* state_store_; | 183 extensions::StateStore* state_store_; |
149 base::WeakPtrFactory<PlatformKeysService> weak_factory_; | 184 base::WeakPtrFactory<PlatformKeysService> weak_factory_; |
150 | 185 |
151 DISALLOW_COPY_AND_ASSIGN(PlatformKeysService); | 186 DISALLOW_COPY_AND_ASSIGN(PlatformKeysService); |
152 }; | 187 }; |
153 | 188 |
154 } // namespace chromeos | 189 } // namespace chromeos |
155 | 190 |
156 #endif // CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_PLATFORM_KEYS_SERVICE_H_ | 191 #endif // CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_PLATFORM_KEYS_SERVICE_H_ |
OLD | NEW |