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_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_PLATFORM_KEYS_H_ |
6 #define CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_PLATFORM_KEYS_H_ | 6 #define CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_PLATFORM_KEYS_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/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "net/cert/x509_certificate.h" | |
16 #include "net/ssl/ssl_client_cert_type.h" | 15 #include "net/ssl/ssl_client_cert_type.h" |
17 | 16 |
18 namespace content { | 17 namespace content { |
19 class BrowserContext; | 18 class BrowserContext; |
20 } | 19 } |
21 | 20 |
| 21 namespace net { |
| 22 class X509Certificate; |
| 23 typedef std::vector<scoped_refptr<X509Certificate> > CertificateList; |
| 24 } |
| 25 |
22 namespace chromeos { | 26 namespace chromeos { |
23 | 27 |
24 namespace platform_keys { | 28 namespace platform_keys { |
25 | 29 |
26 // A token is a store for keys or certs and can provide cryptographic | 30 // A token is a store for keys or certs and can provide cryptographic |
27 // operations. | 31 // operations. |
28 // ChromeOS provides itself a user token and conditionally a system wide token, | 32 // ChromeOS provides itself a user token and conditionally a system wide token, |
29 // thus these tokens use static identifiers. The platform keys API is designed | 33 // thus these tokens use static identifiers. The platform keys API is designed |
30 // to support arbitrary other tokens in the future, which could then use | 34 // to support arbitrary other tokens in the future, which could then use |
31 // run-time generated IDs. | 35 // run-time generated IDs. |
32 extern const char kTokenIdUser[]; | 36 extern const char kTokenIdUser[]; |
33 extern const char kTokenIdSystem[]; | 37 extern const char kTokenIdSystem[]; |
34 | 38 |
35 // Supported hash algorithms. | 39 // Supported hash algorithms. |
36 enum HashAlgorithm { | 40 enum HashAlgorithm { |
37 HASH_ALGORITHM_NONE, // The value if no hash function is selected. | |
38 HASH_ALGORITHM_SHA1, | 41 HASH_ALGORITHM_SHA1, |
39 HASH_ALGORITHM_SHA256, | 42 HASH_ALGORITHM_SHA256, |
40 HASH_ALGORITHM_SHA384, | 43 HASH_ALGORITHM_SHA384, |
41 HASH_ALGORITHM_SHA512 | 44 HASH_ALGORITHM_SHA512 |
42 }; | 45 }; |
43 | 46 |
44 struct ClientCertificateRequest { | 47 struct ClientCertificateRequest { |
45 ClientCertificateRequest(); | 48 ClientCertificateRequest(); |
46 ~ClientCertificateRequest(); | 49 ~ClientCertificateRequest(); |
47 | 50 |
(...skipping 19 matching lines...) Expand all Loading... |
67 // ignored, instead the user token associated with |browser_context| is always | 70 // ignored, instead the user token associated with |browser_context| is always |
68 // used. |callback| will be invoked with the resulting public key or an error. | 71 // used. |callback| will be invoked with the resulting public key or an error. |
69 void GenerateRSAKey(const std::string& token_id, | 72 void GenerateRSAKey(const std::string& token_id, |
70 unsigned int modulus_length_bits, | 73 unsigned int modulus_length_bits, |
71 const GenerateKeyCallback& callback, | 74 const GenerateKeyCallback& callback, |
72 content::BrowserContext* browser_context); | 75 content::BrowserContext* browser_context); |
73 | 76 |
74 typedef base::Callback<void(const std::string& signature, | 77 typedef base::Callback<void(const std::string& signature, |
75 const std::string& error_message)> SignCallback; | 78 const std::string& error_message)> SignCallback; |
76 | 79 |
77 // Digests |data|, applies PKCS1 padding and afterwards signs the data with the | 80 // Digests |data| with |hash_algorithm| and afterwards signs the digest with the |
78 // private key matching |params.public_key|. If a non empty token id is provided | 81 // private key matching |public_key|, if that key is stored in the given token. |
79 // and the key is not found in that token, the operation aborts. |callback| will | 82 // |token_id| is currently ignored, instead the user token associated with |
80 // be invoked with the signature or an error message. | 83 // |browser_context| is always used. |public_key| must be the DER encoding of a |
81 void SignRSAPKCS1Digest(const std::string& token_id, | 84 // SubjectPublicKeyInfo. |callback| will be invoked with the signature or an |
82 const std::string& data, | 85 // error message. |
83 const std::string& public_key, | 86 // Currently supports RSA keys only. |
84 HashAlgorithm hash_algorithm, | 87 void Sign(const std::string& token_id, |
85 const SignCallback& callback, | 88 const std::string& public_key, |
86 content::BrowserContext* browser_context); | 89 HashAlgorithm hash_algorithm, |
87 | 90 const std::string& data, |
88 // Applies PKCS1 padding and afterwards signs the data with the private key | 91 const SignCallback& callback, |
89 // matching |params.public_key|. |data| is not digested. If a non empty token id | 92 content::BrowserContext* browser_context); |
90 // is provided and the key is not found in that token, the operation aborts. | |
91 // The size of |data| (number of octets) must be smaller than k - 11, where k | |
92 // is the key size in octets. | |
93 // |callback| will be invoked with the signature or an error message. | |
94 void SignRSAPKCS1Raw(const std::string& token_id, | |
95 const std::string& data, | |
96 const std::string& public_key, | |
97 const SignCallback& callback, | |
98 content::BrowserContext* browser_context); | |
99 | 93 |
100 // If the certificate request could be processed successfully, |matches| will | 94 // If the certificate request could be processed successfully, |matches| will |
101 // contain the list of matching certificates (which may be empty) and | 95 // contain the list of matching certificates (which may be empty) and |
102 // |error_message| will be empty. If an error occurred, |matches| will be null | 96 // |error_message| will be empty. If an error occurred, |matches| will be null |
103 // and |error_message| contain an error message. | 97 // and |error_message| contain an error message. |
104 typedef base::Callback<void(scoped_ptr<net::CertificateList> matches, | 98 typedef base::Callback<void(scoped_ptr<net::CertificateList> matches, |
105 const std::string& error_message)> | 99 const std::string& error_message)> |
106 SelectCertificatesCallback; | 100 SelectCertificatesCallback; |
107 | 101 |
108 // Returns the list of all certificates that match |request|. |callback| will be | 102 // Returns the list of all certificates that match |request|. |callback| will be |
109 // invoked with these matches or an error message. | 103 // invoked with these matches or an error message. |
110 void SelectClientCertificates(const ClientCertificateRequest& request, | 104 void SelectClientCertificates(const ClientCertificateRequest& request, |
111 const SelectCertificatesCallback& callback, | 105 const SelectCertificatesCallback& callback, |
112 content::BrowserContext* browser_context); | 106 content::BrowserContext* browser_context); |
113 | 107 |
114 } // namespace subtle | 108 } // namespace subtle |
115 | 109 |
116 // Obtains information about the public key in |certificate|. | |
117 // If |certificate| contains an RSA key, sets |key_size_bits| to the modulus | |
118 // length, |public_key_spki_der| to the DER encoding of the X.509 Subject Public | |
119 // Key Info, and |key_type| to type RSA and returns true. | |
120 // If |certificate| contains any other key type, or if the public exponent of | |
121 // the RSA key in |certificate| is not F4, returns false and does not update any | |
122 // of the output parameters. | |
123 // All pointer arguments must not be null. | |
124 bool GetPublicKey(const scoped_refptr<net::X509Certificate>& certificate, | |
125 std::string* public_key_spki_der, | |
126 net::X509Certificate::PublicKeyType* key_type, | |
127 size_t* key_size_bits); | |
128 | |
129 // If the list of certificates could be successfully retrieved, |certs| will | 110 // If the list of certificates could be successfully retrieved, |certs| will |
130 // contain the list of available certificates (maybe empty) and |error_message| | 111 // contain the list of available certificates (maybe empty) and |error_message| |
131 // will be empty. If an error occurred, |certs| will be empty and | 112 // will be empty. If an error occurred, |certs| will be empty and |
132 // |error_message| contain an error message. | 113 // |error_message| contain an error message. |
133 typedef base::Callback<void(scoped_ptr<net::CertificateList> certs, | 114 typedef base::Callback<void(scoped_ptr<net::CertificateList> certs, |
134 const std::string& error_message)> | 115 const std::string& error_message)> |
135 GetCertificatesCallback; | 116 GetCertificatesCallback; |
136 | 117 |
137 // Returns the list of all certificates with stored private key available from | 118 // Returns the list of all certificates with stored private key available from |
138 // the given token. |token_id| is currently ignored, instead the user token | 119 // the given token. |token_id| is currently ignored, instead the user token |
139 // associated with |browser_context| is always used. |callback| will be invoked | 120 // associated with |browser_context| is always used. |callback| will be invoked |
140 // with the list of available certificates or an error message. | 121 // with the list of available certificates or an error message. |
141 void GetCertificates(const std::string& token_id, | 122 void GetCertificates(const std::string& token_id, |
142 const GetCertificatesCallback& callback, | 123 const GetCertificatesCallback& callback, |
143 content::BrowserContext* browser_context); | 124 content::BrowserContext* browser_context); |
144 | 125 |
145 // If an error occurred during import, |error_message| will be set to an error | 126 // If an error occurred during import, |error_message| will be set to an error |
146 // message. | 127 // message. |
147 typedef base::Callback<void(const std::string& error_message)> | 128 typedef base::Callback<void(const std::string& error_message)> |
148 ImportCertificateCallback; | 129 ImportCertificateCallback; |
149 | 130 |
150 // Imports |certificate| to the given token if the certified key is already | 131 // Imports |certificate| to the given token if the certified key is already |
151 // stored in this token. Any intermediate of |certificate| will be ignored. | 132 // stored in this token. Any intermediate of |certificate| will be ignored. |
152 // |token_id| is currently ignored, instead the user token associated with | 133 // |token_id| is currently ignored, instead the user token associated with |
153 // |browser_context| is always used. |callback| will be invoked when the import | 134 // |browser_context| is always used. |callback| will be invoked when the import |
154 // is finished, possibly with an error message. | 135 // is finished, possibly with an error message. |
155 void ImportCertificate(const std::string& token_id, | 136 void ImportCertificate(const std::string& token_id, |
156 const scoped_refptr<net::X509Certificate>& certificate, | 137 scoped_refptr<net::X509Certificate> certificate, |
157 const ImportCertificateCallback& callback, | 138 const ImportCertificateCallback& callback, |
158 content::BrowserContext* browser_context); | 139 content::BrowserContext* browser_context); |
159 | 140 |
160 // If an error occurred during removal, |error_message| will be set to an error | 141 // If an error occurred during removal, |error_message| will be set to an error |
161 // message. | 142 // message. |
162 typedef base::Callback<void(const std::string& error_message)> | 143 typedef base::Callback<void(const std::string& error_message)> |
163 RemoveCertificateCallback; | 144 RemoveCertificateCallback; |
164 | 145 |
165 // Removes |certificate| from the given token if present. Any intermediate of | 146 // Removes |certificate| from the given token if present. Any intermediate of |
166 // |certificate| will be ignored. |token_id| is currently ignored, instead the | 147 // |certificate| will be ignored. |token_id| is currently ignored, instead the |
167 // user token associated with |browser_context| is always used. |callback| will | 148 // user token associated with |browser_context| is always used. |callback| will |
168 // be invoked when the removal is finished, possibly with an error message. | 149 // be invoked when the removal is finished, possibly with an error message. |
169 void RemoveCertificate(const std::string& token_id, | 150 void RemoveCertificate(const std::string& token_id, |
170 const scoped_refptr<net::X509Certificate>& certificate, | 151 scoped_refptr<net::X509Certificate> certificate, |
171 const RemoveCertificateCallback& callback, | 152 const RemoveCertificateCallback& callback, |
172 content::BrowserContext* browser_context); | 153 content::BrowserContext* browser_context); |
173 | 154 |
174 // If the list of available tokens could be successfully retrieved, |token_ids| | 155 // If the list of available tokens could be successfully retrieved, |token_ids| |
175 // will contain the token ids. If an error occurs, |token_ids| will be NULL and | 156 // will contain the token ids. If an error occurs, |token_ids| will be NULL and |
176 // |error_message| will be set to an error message. | 157 // |error_message| will be set to an error message. |
177 typedef base::Callback<void(scoped_ptr<std::vector<std::string> > token_ids, | 158 typedef base::Callback<void(scoped_ptr<std::vector<std::string> > token_ids, |
178 const std::string& error_message)> | 159 const std::string& error_message)> |
179 GetTokensCallback; | 160 GetTokensCallback; |
180 | 161 |
181 // Gets the list of available tokens. |callback| will be invoked when the list | 162 // Gets the list of available tokens. |callback| will be invoked when the list |
182 // of available tokens is determined, possibly with an error message. | 163 // of available tokens is determined, possibly with an error message. |
183 // Must be called and calls |callback| on the UI thread. | 164 // Must be called and calls |callback| on the UI thread. |
184 void GetTokens(const GetTokensCallback& callback, | 165 void GetTokens(const GetTokensCallback& callback, |
185 content::BrowserContext* browser_context); | 166 content::BrowserContext* browser_context); |
186 | 167 |
187 } // namespace platform_keys | 168 } // namespace platform_keys |
188 | 169 |
189 } // namespace chromeos | 170 } // namespace chromeos |
190 | 171 |
191 #endif // CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_PLATFORM_KEYS_H_ | 172 #endif // CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_PLATFORM_KEYS_H_ |
OLD | NEW |