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 | 15 |
16 namespace content { | 16 namespace content { |
17 class BrowserContext; | 17 class BrowserContext; |
18 } | 18 } |
19 | 19 |
20 namespace net { | 20 namespace net { |
21 class X509Certificate; | 21 class X509Certificate; |
22 typedef std::vector<scoped_refptr<X509Certificate> > CertificateList; | 22 typedef std::vector<scoped_refptr<X509Certificate> > CertificateList; |
23 } | 23 } |
24 | 24 |
25 namespace chromeos { | 25 namespace chromeos { |
26 | 26 |
27 namespace platform_keys { | 27 namespace platform_keys { |
28 | 28 |
| 29 // Supported hash algorithms. |
| 30 enum HashAlgorithm { |
| 31 HASH_ALGORITHM_SHA1, |
| 32 HASH_ALGORITHM_SHA256, |
| 33 HASH_ALGORITHM_SHA384, |
| 34 HASH_ALGORITHM_SHA512 |
| 35 }; |
| 36 |
29 namespace subtle { | 37 namespace subtle { |
30 // Functions of this namespace shouldn't be called directly from the context of | 38 // Functions of this namespace shouldn't be called directly from the context of |
31 // an extension. Instead use PlatformKeysService which enforces restrictions | 39 // an extension. Instead use PlatformKeysService which enforces restrictions |
32 // upon extensions. | 40 // upon extensions. |
33 | 41 |
34 typedef base::Callback<void(const std::string& public_key_spki_der, | 42 typedef base::Callback<void(const std::string& public_key_spki_der, |
35 const std::string& error_message)> | 43 const std::string& error_message)> |
36 GenerateKeyCallback; | 44 GenerateKeyCallback; |
37 | 45 |
38 // Generates a RSA key pair with |modulus_length_bits|. |token_id| is currently | 46 // Generates a RSA key pair with |modulus_length_bits|. |token_id| is currently |
39 // ignored, instead the user token associated with |browser_context| is always | 47 // ignored, instead the user token associated with |browser_context| is always |
40 // used. |callback| will be invoked with the resulting public key or an error. | 48 // used. |callback| will be invoked with the resulting public key or an error. |
41 void GenerateRSAKey(const std::string& token_id, | 49 void GenerateRSAKey(const std::string& token_id, |
42 unsigned int modulus_length_bits, | 50 unsigned int modulus_length_bits, |
43 const GenerateKeyCallback& callback, | 51 const GenerateKeyCallback& callback, |
44 content::BrowserContext* browser_context); | 52 content::BrowserContext* browser_context); |
45 | 53 |
46 typedef base::Callback<void(const std::string& signature, | 54 typedef base::Callback<void(const std::string& signature, |
47 const std::string& error_message)> SignCallback; | 55 const std::string& error_message)> SignCallback; |
48 | 56 |
49 // Signs |data| with the private key matching |public_key|, if that key is | 57 // Digests |data| with |hash_algorithm| and afterwards signs the digest with the |
50 // stored in the given token. |token_id| is currently ignored, instead the user | 58 // private key matching |public_key|, if that key is stored in the given token. |
51 // token associated with |browser_context| is always used. |public_key| must be | 59 // |token_id| is currently ignored, instead the user token associated with |
52 // the DER encoding of a SubjectPublicKeyInfo. |callback| will be invoked with | 60 // |browser_context| is always used. |public_key| must be the DER encoding of a |
53 // the signature or an error message. | 61 // SubjectPublicKeyInfo. |callback| will be invoked with the signature or an |
| 62 // error message. |
54 // Currently supports RSA keys only. | 63 // Currently supports RSA keys only. |
55 void Sign(const std::string& token_id, | 64 void Sign(const std::string& token_id, |
56 const std::string& public_key, | 65 const std::string& public_key, |
| 66 HashAlgorithm hash_algorithm, |
57 const std::string& data, | 67 const std::string& data, |
58 const SignCallback& callback, | 68 const SignCallback& callback, |
59 content::BrowserContext* browser_context); | 69 content::BrowserContext* browser_context); |
60 | 70 |
61 } // namespace subtle | 71 } // namespace subtle |
62 | 72 |
63 // If the list of certificates could be successfully retrieved, |certs| will | 73 // If the list of certificates could be successfully retrieved, |certs| will |
64 // contain the list of available certificates (maybe empty) and |error_message| | 74 // contain the list of available certificates (maybe empty) and |error_message| |
65 // will be empty. If an error occurred, |certs| will be empty and | 75 // will be empty. If an error occurred, |certs| will be empty and |
66 // |error_message| contain an error message. | 76 // |error_message| contain an error message. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 void RemoveCertificate(const std::string& token_id, | 113 void RemoveCertificate(const std::string& token_id, |
104 scoped_refptr<net::X509Certificate> certificate, | 114 scoped_refptr<net::X509Certificate> certificate, |
105 const RemoveCertificateCallback& callback, | 115 const RemoveCertificateCallback& callback, |
106 content::BrowserContext* browser_context); | 116 content::BrowserContext* browser_context); |
107 | 117 |
108 } // namespace platform_keys | 118 } // namespace platform_keys |
109 | 119 |
110 } // namespace chromeos | 120 } // namespace chromeos |
111 | 121 |
112 #endif // CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_PLATFORM_KEYS_H_ | 122 #endif // CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_PLATFORM_KEYS_H_ |
OLD | NEW |