OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROMEOS_CRYPTOHOME_ASYNC_METHOD_CALLER_H_ | 5 #ifndef CHROMEOS_CRYPTOHOME_ASYNC_METHOD_CALLER_H_ |
6 #define CHROMEOS_CRYPTOHOME_ASYNC_METHOD_CALLER_H_ | 6 #define CHROMEOS_CRYPTOHOME_ASYNC_METHOD_CALLER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
11 #include "chromeos/attestation/attestation_constants.h" | 11 #include "chromeos/attestation/attestation_constants.h" |
12 #include "chromeos/chromeos_export.h" | 12 #include "chromeos/chromeos_export.h" |
13 #include "chromeos/dbus/cryptohome_client.h" | 13 #include "chromeos/dbus/cryptohome_client.h" |
14 #include "third_party/cros_system_api/dbus/service_constants.h" | 14 #include "third_party/cros_system_api/dbus/service_constants.h" |
15 | 15 |
16 namespace cryptohome { | 16 namespace cryptohome { |
17 | 17 |
| 18 class Identification; |
| 19 |
18 // Note: This file is placed in ::cryptohome instead of ::chromeos::cryptohome | 20 // Note: This file is placed in ::cryptohome instead of ::chromeos::cryptohome |
19 // since there is already a namespace ::cryptohome which holds the error code | 21 // since there is already a namespace ::cryptohome which holds the error code |
20 // enum (MountError) and referencing ::chromeos::cryptohome and ::cryptohome | 22 // enum (MountError) and referencing ::chromeos::cryptohome and ::cryptohome |
21 // within the same code is confusing. | 23 // within the same code is confusing. |
22 | 24 |
23 // Flags for the AsyncMount method. | 25 // Flags for the AsyncMount method. |
24 enum MountFlags { | 26 enum MountFlags { |
25 MOUNT_FLAGS_NONE = 0, // Used to explicitly denote that no flags are | 27 MOUNT_FLAGS_NONE = 0, // Used to explicitly denote that no flags are |
26 // set. | 28 // set. |
27 CREATE_IF_MISSING = 1, // Create a cryptohome if it does not exist yet. | 29 CREATE_IF_MISSING = 1, // Create a cryptohome if it does not exist yet. |
28 ENSURE_EPHEMERAL = 1 << 1, // Ensure that the mount is ephemeral. | 30 ENSURE_EPHEMERAL = 1 << 1, // Ensure that the mount is ephemeral. |
29 }; | 31 }; |
30 | 32 |
31 // This class manages calls to Cryptohome service's 'async' methods. | 33 // This class manages calls to Cryptohome service's 'async' methods. |
32 class CHROMEOS_EXPORT AsyncMethodCaller { | 34 class CHROMEOS_EXPORT AsyncMethodCaller { |
33 public: | 35 public: |
34 // A callback type which is called back on the UI thread when the results of | 36 // A callback type which is called back on the UI thread when the results of |
35 // method calls are ready. | 37 // method calls are ready. |
36 typedef base::Callback<void(bool success, MountError return_code)> Callback; | 38 typedef base::Callback<void(bool success, MountError return_code)> Callback; |
37 typedef base::Callback<void(bool success, const std::string& data)> | 39 typedef base::Callback<void(bool success, const std::string& data)> |
38 DataCallback; | 40 DataCallback; |
39 | 41 |
40 virtual ~AsyncMethodCaller() {} | 42 virtual ~AsyncMethodCaller() {} |
41 | 43 |
42 // Asks cryptohomed to asynchronously try to find the cryptohome for | 44 // Asks cryptohomed to asynchronously try to find the cryptohome for |
43 // |user_email| and then use |passhash| to unlock the key. | 45 // |user_id| and then use |passhash| to unlock the key. |
44 // |callback| will be called with status info on completion. | 46 // |callback| will be called with status info on completion. |
45 virtual void AsyncCheckKey(const std::string& user_email, | 47 virtual void AsyncCheckKey(const Identification& user_id, |
46 const std::string& passhash, | 48 const std::string& passhash, |
47 Callback callback) = 0; | 49 Callback callback) = 0; |
48 | 50 |
49 // Asks cryptohomed to asynchronously try to find the cryptohome for | 51 // Asks cryptohomed to asynchronously try to find the cryptohome for |
50 // |user_email| and then change from using |old_hash| to lock the | 52 // |user_id| and then change from using |old_hash| to lock the |
51 // key to using |new_hash|. | 53 // key to using |new_hash|. |
52 // |callback| will be called with status info on completion. | 54 // |callback| will be called with status info on completion. |
53 virtual void AsyncMigrateKey(const std::string& user_email, | 55 virtual void AsyncMigrateKey(const Identification& user_id, |
54 const std::string& old_hash, | 56 const std::string& old_hash, |
55 const std::string& new_hash, | 57 const std::string& new_hash, |
56 Callback callback) = 0; | 58 Callback callback) = 0; |
57 | 59 |
58 // Asks cryptohomed to asynchronously try to find the cryptohome for | 60 // Asks cryptohomed to asynchronously try to find the cryptohome for |
59 // |user_email| and then mount it using |passhash| to unlock the key. | 61 // |user_id| and then mount it using |passhash| to unlock the key. |
60 // The |flags| are a combination of |MountFlags|: | 62 // The |flags| are a combination of |MountFlags|: |
61 // * CREATE_IF_MISSING Controls whether or not cryptohomed is asked to create | 63 // * CREATE_IF_MISSING Controls whether or not cryptohomed is asked to create |
62 // a new cryptohome if one does not exist yet for | 64 // a new cryptohome if one does not exist yet for |
63 // |user_email|. | 65 // |user_id|. |
64 // * ENSURE_EPHEMERAL If |true|, the mounted cryptohome will be backed by | 66 // * ENSURE_EPHEMERAL If |true|, the mounted cryptohome will be backed by |
65 // tmpfs. If |false|, the ephemeral users policy decides | 67 // tmpfs. If |false|, the ephemeral users policy decides |
66 // whether tmpfs or an encrypted directory is used as the | 68 // whether tmpfs or an encrypted directory is used as the |
67 // backend. | 69 // backend. |
68 // |callback| will be called with status info on completion. | 70 // |callback| will be called with status info on completion. |
69 // If the |CREATE_IF_MISSING| flag is not given and no cryptohome exists | 71 // If the |CREATE_IF_MISSING| flag is not given and no cryptohome exists |
70 // for |user_email|, the expected result is | 72 // for |user_id|, the expected result is |
71 // callback.Run(false, kCryptohomeMountErrorUserDoesNotExist). Otherwise, | 73 // callback.Run(false, kCryptohomeMountErrorUserDoesNotExist). Otherwise, |
72 // the normal range of return codes is expected. | 74 // the normal range of return codes is expected. |
73 virtual void AsyncMount(const std::string& user_email, | 75 virtual void AsyncMount(const Identification& user_id, |
74 const std::string& passhash, | 76 const std::string& passhash, |
75 int flags, | 77 int flags, |
76 Callback callback) = 0; | 78 Callback callback) = 0; |
77 | 79 |
78 // Asks cryptohomed to asynchronously try to add another |new_passhash| for | 80 // Asks cryptohomed to asynchronously try to add another |new_passhash| for |
79 // |user_email| using |passhash| to unlock the key. | 81 // |user_id| using |passhash| to unlock the key. |
80 // |callback| will be called with status info on completion. | 82 // |callback| will be called with status info on completion. |
81 virtual void AsyncAddKey(const std::string& user_email, | 83 virtual void AsyncAddKey(const Identification& user_id, |
82 const std::string& passhash, | 84 const std::string& passhash, |
83 const std::string& new_passhash, | 85 const std::string& new_passhash, |
84 Callback callback) = 0; | 86 Callback callback) = 0; |
85 | 87 |
86 // Asks cryptohomed to asynchronously to mount a tmpfs for guest mode. | 88 // Asks cryptohomed to asynchronously to mount a tmpfs for guest mode. |
87 // |callback| will be called with status info on completion. | 89 // |callback| will be called with status info on completion. |
88 virtual void AsyncMountGuest(Callback callback) = 0; | 90 virtual void AsyncMountGuest(Callback callback) = 0; |
89 | 91 |
90 // Asks cryptohomed to asynchrounously try to find the cryptohome for | 92 // Asks cryptohomed to asynchrounously try to find the cryptohome for |
91 // |public_mount_id| and then mount it using a passhash derived from | 93 // |public_mount_id| and then mount it using a passhash derived from |
92 // |public_mount_id| and a secret. See AsyncMount for possible values for | 94 // |public_mount_id| and a secret. See AsyncMount for possible values for |
93 // |flags|. | 95 // |flags|. |
94 virtual void AsyncMountPublic(const std::string& public_mount_id, | 96 virtual void AsyncMountPublic(const Identification& public_mount_id, |
95 int flags, | 97 int flags, |
96 Callback callback) = 0; | 98 Callback callback) = 0; |
97 | 99 |
98 // Asks cryptohomed to asynchronously try to find the cryptohome for | 100 // Asks cryptohomed to asynchronously try to find the cryptohome for |
99 // |user_email| and then nuke it. | 101 // |user_id| and then nuke it. |
100 virtual void AsyncRemove(const std::string& user_email, | 102 virtual void AsyncRemove(const Identification& user_id, |
101 Callback callback) = 0; | 103 Callback callback) = 0; |
102 | 104 |
103 // Asks cryptohomed to asynchronously create an attestation enrollment | 105 // Asks cryptohomed to asynchronously create an attestation enrollment |
104 // request. On success the data sent to |callback| is a request to be sent | 106 // request. On success the data sent to |callback| is a request to be sent |
105 // to the Privacy CA of type |pca_type|. | 107 // to the Privacy CA of type |pca_type|. |
106 virtual void AsyncTpmAttestationCreateEnrollRequest( | 108 virtual void AsyncTpmAttestationCreateEnrollRequest( |
107 chromeos::attestation::PrivacyCAType pca_type, | 109 chromeos::attestation::PrivacyCAType pca_type, |
108 const DataCallback& callback) = 0; | 110 const DataCallback& callback) = 0; |
109 | 111 |
110 // Asks cryptohomed to asynchronously finish an attestation enrollment. | 112 // Asks cryptohomed to asynchronously finish an attestation enrollment. |
111 // |pca_response| is the response to the enrollment request emitted by the | 113 // |pca_response| is the response to the enrollment request emitted by the |
112 // Privacy CA of type |pca_type|. | 114 // Privacy CA of type |pca_type|. |
113 virtual void AsyncTpmAttestationEnroll( | 115 virtual void AsyncTpmAttestationEnroll( |
114 chromeos::attestation::PrivacyCAType pca_type, | 116 chromeos::attestation::PrivacyCAType pca_type, |
115 const std::string& pca_response, | 117 const std::string& pca_response, |
116 const Callback& callback) = 0; | 118 const Callback& callback) = 0; |
117 | 119 |
118 // Asks cryptohomed to asynchronously create an attestation certificate | 120 // Asks cryptohomed to asynchronously create an attestation certificate |
119 // request according to |certificate_profile|. Some profiles require that the | 121 // request according to |certificate_profile|. Some profiles require that the |
120 // |user_id| of the currently active user and an identifier of the | 122 // |user_id| of the currently active user and an identifier of the |
121 // |request_origin| be provided. On success the data sent to |callback| is a | 123 // |request_origin| be provided. On success the data sent to |callback| is a |
122 // request to be sent to the Privacy CA of type |pca_type|. The | 124 // request to be sent to the Privacy CA of type |pca_type|. The |
123 // |request_origin| may be sent to the Privacy CA but the |user_id| will never | 125 // |request_origin| may be sent to the Privacy CA but the |user_id| will never |
124 // be sent. | 126 // be sent. |
125 virtual void AsyncTpmAttestationCreateCertRequest( | 127 virtual void AsyncTpmAttestationCreateCertRequest( |
126 chromeos::attestation::PrivacyCAType pca_type, | 128 chromeos::attestation::PrivacyCAType pca_type, |
127 chromeos::attestation::AttestationCertificateProfile certificate_profile, | 129 chromeos::attestation::AttestationCertificateProfile certificate_profile, |
128 const std::string& user_id, | 130 const Identification& user_id, |
129 const std::string& request_origin, | 131 const std::string& request_origin, |
130 const DataCallback& callback) = 0; | 132 const DataCallback& callback) = 0; |
131 | 133 |
132 // Asks cryptohomed to asynchronously finish an attestation certificate | 134 // Asks cryptohomed to asynchronously finish an attestation certificate |
133 // request. On success the data sent to |callback| is a certificate chain | 135 // request. On success the data sent to |callback| is a certificate chain |
134 // in PEM format. |pca_response| is the response to the certificate request | 136 // in PEM format. |pca_response| is the response to the certificate request |
135 // emitted by the Privacy CA. |key_type| determines whether the certified key | 137 // emitted by the Privacy CA. |key_type| determines whether the certified key |
136 // is to be associated with the current user. |key_name| is a name for the | 138 // is to be associated with the current user. |key_name| is a name for the |
137 // key. If |key_type| is KEY_USER, a |user_id| must be provided. Otherwise | 139 // key. If |key_type| is KEY_USER, a |user_id| must be provided. Otherwise |
138 // |user_id| is ignored. For normal GAIA users the |user_id| is a canonical | 140 // |user_id| is ignored. For normal GAIA users the |user_id| is |
139 // email address. | 141 // a GaiaId-derived string (see AccountId::GetGaiaIdKey). |
140 virtual void AsyncTpmAttestationFinishCertRequest( | 142 virtual void AsyncTpmAttestationFinishCertRequest( |
141 const std::string& pca_response, | 143 const std::string& pca_response, |
142 chromeos::attestation::AttestationKeyType key_type, | 144 chromeos::attestation::AttestationKeyType key_type, |
143 const std::string& user_id, | 145 const Identification& user_id, |
144 const std::string& key_name, | 146 const std::string& key_name, |
145 const DataCallback& callback) = 0; | 147 const DataCallback& callback) = 0; |
146 | 148 |
147 // Asks cryptohomed to asynchronously register the attestation key specified | 149 // Asks cryptohomed to asynchronously register the attestation key specified |
148 // by |key_type| and |key_name|. If |key_type| is KEY_USER, a |user_id| must | 150 // by |key_type| and |key_name|. If |key_type| is KEY_USER, a |user_id| must |
149 // be provided. Otherwise |user_id| is ignored. For normal GAIA users the | 151 // be provided. Otherwise |user_id| is ignored. For normal GAIA users the |
150 // |user_id| is a canonical email address. | 152 // |user_id| is a GaiaId-derived string (see AccountId::GetGaiaIdKey). |
151 virtual void TpmAttestationRegisterKey( | 153 virtual void TpmAttestationRegisterKey( |
152 chromeos::attestation::AttestationKeyType key_type, | 154 chromeos::attestation::AttestationKeyType key_type, |
153 const std::string& user_id, | 155 const Identification& user_id, |
154 const std::string& key_name, | 156 const std::string& key_name, |
155 const Callback& callback) = 0; | 157 const Callback& callback) = 0; |
156 | 158 |
157 // Asks cryptohomed to asynchronously sign an enterprise challenge with the | 159 // Asks cryptohomed to asynchronously sign an enterprise challenge with the |
158 // key specified by |key_type| and |key_name|. The |domain| and |device_id| | 160 // key specified by |key_type| and |key_name|. The |domain| and |device_id| |
159 // parameters will be included in the challenge response. |challenge| must be | 161 // parameters will be included in the challenge response. |challenge| must be |
160 // a valid enterprise challenge. On success, the data sent to |callback| is | 162 // a valid enterprise challenge. On success, the data sent to |callback| is |
161 // the challenge response. If |key_type| is KEY_USER, a |user_id| must be | 163 // the challenge response. If |key_type| is KEY_USER, a |user_id| must be |
162 // provided. Otherwise |user_id| is ignored. For normal GAIA users the | 164 // provided. Otherwise |user_id| is ignored. For normal GAIA users the |
163 // |user_id| is a canonical email address. | 165 // |user_id| is a GaiaId-derived string (see AccountId::GetGaiaIdKey). |
164 virtual void TpmAttestationSignEnterpriseChallenge( | 166 virtual void TpmAttestationSignEnterpriseChallenge( |
165 chromeos::attestation::AttestationKeyType key_type, | 167 chromeos::attestation::AttestationKeyType key_type, |
166 const std::string& user_id, | 168 const Identification& user_id, |
167 const std::string& key_name, | 169 const std::string& key_name, |
168 const std::string& domain, | 170 const std::string& domain, |
169 const std::string& device_id, | 171 const std::string& device_id, |
170 chromeos::attestation::AttestationChallengeOptions options, | 172 chromeos::attestation::AttestationChallengeOptions options, |
171 const std::string& challenge, | 173 const std::string& challenge, |
172 const DataCallback& callback) = 0; | 174 const DataCallback& callback) = 0; |
173 | 175 |
174 // Asks cryptohomed to asynchronously sign a simple challenge with the key | 176 // Asks cryptohomed to asynchronously sign a simple challenge with the key |
175 // specified by |key_type| and |key_name|. |challenge| can be any arbitrary | 177 // specified by |key_type| and |key_name|. |challenge| can be any arbitrary |
176 // set of bytes. On success, the data sent to |callback| is the challenge | 178 // set of bytes. On success, the data sent to |callback| is the challenge |
177 // response. If |key_type| is KEY_USER, a |user_id| must be provided. | 179 // response. If |key_type| is KEY_USER, a |user_id| must be provided. |
178 // Otherwise |user_id| is ignored. For normal GAIA users the |user_id| is a | 180 // Otherwise |user_id| is ignored. For normal GAIA users the |user_id| is a |
179 // canonical email address. | 181 // GaiaId-derived string (see AccountId::GetGaiaIdKey). |
180 virtual void TpmAttestationSignSimpleChallenge( | 182 virtual void TpmAttestationSignSimpleChallenge( |
181 chromeos::attestation::AttestationKeyType key_type, | 183 chromeos::attestation::AttestationKeyType key_type, |
182 const std::string& user_id, | 184 const Identification& user_id, |
183 const std::string& key_name, | 185 const std::string& key_name, |
184 const std::string& challenge, | 186 const std::string& challenge, |
185 const DataCallback& callback) = 0; | 187 const DataCallback& callback) = 0; |
186 | 188 |
187 // Asks cryptohome to asynchronously retrieve a string associated with given | 189 // Asks cryptohome to asynchronously retrieve a string associated with given |
188 // |user| that would be used in mount path instead of |user|. | 190 // |user_id| that would be used in mount path instead of |user_id|. |
189 // On success the data is sent to |callback|. | 191 // On success the data is sent to |callback|. |
190 virtual void AsyncGetSanitizedUsername( | 192 virtual void AsyncGetSanitizedUsername(const Identification& user_id, |
191 const std::string& user, | 193 const DataCallback& callback) = 0; |
192 const DataCallback& callback) = 0; | |
193 | 194 |
194 // Creates the global AsyncMethodCaller instance. | 195 // Creates the global AsyncMethodCaller instance. |
195 static void Initialize(); | 196 static void Initialize(); |
196 | 197 |
197 // Similar to Initialize(), but can inject an alternative | 198 // Similar to Initialize(), but can inject an alternative |
198 // AsyncMethodCaller such as MockAsyncMethodCaller for testing. | 199 // AsyncMethodCaller such as MockAsyncMethodCaller for testing. |
199 // The injected object will be owned by the internal pointer and deleted | 200 // The injected object will be owned by the internal pointer and deleted |
200 // by Shutdown(). | 201 // by Shutdown(). |
201 static void InitializeForTesting(AsyncMethodCaller* async_method_caller); | 202 static void InitializeForTesting(AsyncMethodCaller* async_method_caller); |
202 | 203 |
203 // Destroys the global AsyncMethodCaller instance if it exists. | 204 // Destroys the global AsyncMethodCaller instance if it exists. |
204 static void Shutdown(); | 205 static void Shutdown(); |
205 | 206 |
206 // Returns a pointer to the global AsyncMethodCaller instance. | 207 // Returns a pointer to the global AsyncMethodCaller instance. |
207 // Initialize() should already have been called. | 208 // Initialize() should already have been called. |
208 static AsyncMethodCaller* GetInstance(); | 209 static AsyncMethodCaller* GetInstance(); |
209 }; | 210 }; |
210 | 211 |
211 } // namespace cryptohome | 212 } // namespace cryptohome |
212 | 213 |
213 #endif // CHROMEOS_CRYPTOHOME_ASYNC_METHOD_CALLER_H_ | 214 #endif // CHROMEOS_CRYPTOHOME_ASYNC_METHOD_CALLER_H_ |
OLD | NEW |