Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(757)

Side by Side Diff: chrome/browser/chromeos/platform_keys/platform_keys.h

Issue 884073002: Implement chrome.platformKeys.getKeyPair(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cert_impl2
Patch Set: Rebased. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
15 #include "net/ssl/ssl_client_cert_type.h" 16 #include "net/ssl/ssl_client_cert_type.h"
16 17
17 namespace content { 18 namespace content {
18 class BrowserContext; 19 class BrowserContext;
19 } 20 }
20 21
21 namespace net {
22 class X509Certificate;
23 typedef std::vector<scoped_refptr<X509Certificate> > CertificateList;
24 }
25
26 namespace chromeos { 22 namespace chromeos {
27 23
28 namespace platform_keys { 24 namespace platform_keys {
29 25
30 // A token is a store for keys or certs and can provide cryptographic 26 // A token is a store for keys or certs and can provide cryptographic
31 // operations. 27 // operations.
32 // ChromeOS provides itself a user token and conditionally a system wide token, 28 // ChromeOS provides itself a user token and conditionally a system wide token,
33 // thus these tokens use static identifiers. The platform keys API is designed 29 // thus these tokens use static identifiers. The platform keys API is designed
34 // to support arbitrary other tokens in the future, which could then use 30 // to support arbitrary other tokens in the future, which could then use
35 // run-time generated IDs. 31 // run-time generated IDs.
36 extern const char kTokenIdUser[]; 32 extern const char kTokenIdUser[];
37 extern const char kTokenIdSystem[]; 33 extern const char kTokenIdSystem[];
38 34
39 // Supported hash algorithms. 35 // Supported hash algorithms.
40 enum HashAlgorithm { 36 enum HashAlgorithm {
37 HASH_ALGORITHM_NONE,
Ryan Sleevi 2015/02/03 01:44:49 Needs documentation about expected behaviours (you
pneubeck (no reviews) 2015/02/05 10:41:57 Done.
41 HASH_ALGORITHM_SHA1, 38 HASH_ALGORITHM_SHA1,
42 HASH_ALGORITHM_SHA256, 39 HASH_ALGORITHM_SHA256,
43 HASH_ALGORITHM_SHA384, 40 HASH_ALGORITHM_SHA384,
44 HASH_ALGORITHM_SHA512 41 HASH_ALGORITHM_SHA512
45 }; 42 };
46 43
47 struct ClientCertificateRequest { 44 struct ClientCertificateRequest {
48 ClientCertificateRequest(); 45 ClientCertificateRequest();
49 ~ClientCertificateRequest(); 46 ~ClientCertificateRequest();
50 47
51 // The list of the types of certificates requested, sorted in order of the 48 // The list of the types of certificates requested, sorted in order of the
52 // server's preference. 49 // server's preference.
53 std::vector<net::SSLClientCertType> certificate_key_types; 50 std::vector<net::SSLClientCertType> certificate_key_types;
54 51
55 // List of distinguished names of certificate authorities allowed by the 52 // List of distinguished names of certificate authorities allowed by the
56 // server. Each entry must be a DER-encoded X.509 DistinguishedName. 53 // server. Each entry must be a DER-encoded X.509 DistinguishedName.
57 std::vector<std::string> certificate_authorities; 54 std::vector<std::string> certificate_authorities;
58 }; 55 };
59 56
57 struct PublicKeyInfo {
Ryan Sleevi 2015/02/03 01:44:50 NEeds documentation
pneubeck (no reviews) 2015/02/03 20:15:00 changed the name to SPKI and documented it.
58 PublicKeyInfo();
59 ~PublicKeyInfo();
60
61 std::vector<char> public_key_spki_der;
Ryan Sleevi 2015/02/03 01:44:50 Why |char| and not |uint8_t| ?
pneubeck (no reviews) 2015/02/03 10:48:18 Generated API code uses vector<char>, the code tha
62 net::X509Certificate::PublicKeyType key_type;
63
64 // For RSA a public exponent of 65537 is assumed, so there is no member for
65 // that.
Ryan Sleevi 2015/02/03 01:44:50 This doesn't always hold true
pneubeck (no reviews) 2015/02/03 10:48:18 Is it acceptable to restrict it to 65537 if I impl
66
67 // Set if |key_type| equals kPublicKeyTypeRSA.
68 unsigned int modulus_length_bits;
Ryan Sleevi 2015/02/03 01:44:50 This is a weird interface then, as ec keys have a
pneubeck (no reviews) 2015/02/03 20:15:00 changed the name to key_size_bits
69 };
70
60 namespace subtle { 71 namespace subtle {
61 // Functions of this namespace shouldn't be called directly from the context of 72 // Functions of this namespace shouldn't be called directly from the context of
62 // an extension. Instead use PlatformKeysService which enforces restrictions 73 // an extension. Instead use PlatformKeysService which enforces restrictions
63 // upon extensions. 74 // upon extensions.
64 75
65 typedef base::Callback<void(const std::string& public_key_spki_der, 76 typedef base::Callback<void(const std::string& public_key_spki_der,
66 const std::string& error_message)> 77 const std::string& error_message)>
67 GenerateKeyCallback; 78 GenerateKeyCallback;
68 79
69 // Generates a RSA key pair with |modulus_length_bits|. |token_id| is currently 80 // Generates a RSA key pair with |modulus_length_bits|. |token_id| is currently
70 // ignored, instead the user token associated with |browser_context| is always 81 // ignored, instead the user token associated with |browser_context| is always
71 // used. |callback| will be invoked with the resulting public key or an error. 82 // used. |callback| will be invoked with the resulting public key or an error.
72 void GenerateRSAKey(const std::string& token_id, 83 void GenerateRSAKey(const std::string& token_id,
73 unsigned int modulus_length_bits, 84 unsigned int modulus_length_bits,
74 const GenerateKeyCallback& callback, 85 const GenerateKeyCallback& callback,
75 content::BrowserContext* browser_context); 86 content::BrowserContext* browser_context);
76 87
77 typedef base::Callback<void(const std::string& signature, 88 typedef base::Callback<void(const std::string& signature,
78 const std::string& error_message)> SignCallback; 89 const std::string& error_message)> SignCallback;
79 90
80 // Digests |data| with |hash_algorithm| and afterwards signs the digest with the 91 // Digests |data| with |hash_algorithm| and afterwards signs the digest with the
81 // private key matching |public_key|, if that key is stored in the given token. 92 // private key matching |public_key|, if that key is stored in the given token.
82 // |token_id| is currently ignored, instead the user token associated with 93 // |token_id| is currently ignored, instead the user token associated with
83 // |browser_context| is always used. |public_key| must be the DER encoding of a 94 // |browser_context| is always used. |public_key| must be the DER encoding of a
84 // SubjectPublicKeyInfo. |callback| will be invoked with the signature or an 95 // SubjectPublicKeyInfo. |callback| will be invoked with the signature or an
85 // error message. 96 // error message.
86 // Currently supports RSA keys only. 97 // Currently supports RSA keys only.
98 // If |hash_algorithm| is HASH_ALGORITHM_NONE, |data| will not be hashed before
99 // signing. PKCS#1 v1.5 padding will still be applied.
Ryan Sleevi 2015/02/03 01:44:50 OK, so from a documentation standpoint, it's a lit
pneubeck (no reviews) 2015/02/03 10:48:18 This function is in namespace subtle and an implem
pneubeck (no reviews) 2015/02/05 10:41:57 done. I addressed your comments by clearer documen
87 void Sign(const std::string& token_id, 100 void Sign(const std::string& token_id,
88 const std::string& public_key, 101 const std::string& public_key,
89 HashAlgorithm hash_algorithm, 102 HashAlgorithm hash_algorithm,
90 const std::string& data, 103 const std::string& data,
91 const SignCallback& callback, 104 const SignCallback& callback,
92 content::BrowserContext* browser_context); 105 content::BrowserContext* browser_context);
93 106
94 // If the certificate request could be processed successfully, |matches| will 107 // If the certificate request could be processed successfully, |matches| will
95 // contain the list of matching certificates (maybe empty) and |error_message| 108 // contain the list of matching certificates (maybe empty) and |error_message|
96 // will be empty. If an error occurred, |matches| will be null and 109 // will be empty. If an error occurred, |matches| will be null and
97 // |error_message| contain an error message. 110 // |error_message| contain an error message.
98 typedef base::Callback<void(scoped_ptr<net::CertificateList> matches, 111 typedef base::Callback<void(scoped_ptr<net::CertificateList> matches,
99 const std::string& error_message)> 112 const std::string& error_message)>
100 SelectCertificatesCallback; 113 SelectCertificatesCallback;
101 114
102 // Returns the list of all certificates that match |request|. |callback| will be 115 // Returns the list of all certificates that match |request|. |callback| will be
103 // invoked with these matches or an error message. 116 // invoked with these matches or an error message.
104 void SelectClientCertificates(const ClientCertificateRequest& request, 117 void SelectClientCertificates(const ClientCertificateRequest& request,
105 const SelectCertificatesCallback& callback, 118 const SelectCertificatesCallback& callback,
106 content::BrowserContext* browser_context); 119 content::BrowserContext* browser_context);
107 120
108 } // namespace subtle 121 } // namespace subtle
109 122
123 // Fills |info| with information about the key certified by |certificate|.
124 bool GetPublicKey(scoped_refptr<net::X509Certificate> certificate,
125 PublicKeyInfo* info);
126
110 // If the list of certificates could be successfully retrieved, |certs| will 127 // If the list of certificates could be successfully retrieved, |certs| will
111 // contain the list of available certificates (maybe empty) and |error_message| 128 // contain the list of available certificates (maybe empty) and |error_message|
112 // will be empty. If an error occurred, |certs| will be empty and 129 // will be empty. If an error occurred, |certs| will be empty and
113 // |error_message| contain an error message. 130 // |error_message| contain an error message.
114 typedef base::Callback<void(scoped_ptr<net::CertificateList> certs, 131 typedef base::Callback<void(scoped_ptr<net::CertificateList> certs,
115 const std::string& error_message)> 132 const std::string& error_message)>
116 GetCertificatesCallback; 133 GetCertificatesCallback;
117 134
118 // Returns the list of all certificates with stored private key available from 135 // Returns the list of all certificates with stored private key available from
119 // the given token. |token_id| is currently ignored, instead the user token 136 // the given token. |token_id| is currently ignored, instead the user token
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 // of available tokens is determined, possibly with an error message. 180 // of available tokens is determined, possibly with an error message.
164 // Must be called and calls |callback| on the UI thread. 181 // Must be called and calls |callback| on the UI thread.
165 void GetTokens(const GetTokensCallback& callback, 182 void GetTokens(const GetTokensCallback& callback,
166 content::BrowserContext* browser_context); 183 content::BrowserContext* browser_context);
167 184
168 } // namespace platform_keys 185 } // namespace platform_keys
169 186
170 } // namespace chromeos 187 } // namespace chromeos
171 188
172 #endif // CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_PLATFORM_KEYS_H_ 189 #endif // CHROME_BROWSER_CHROMEOS_PLATFORM_KEYS_PLATFORM_KEYS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698