Chromium Code Reviews| 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_ATTESTATION_ATTESTATION_FLOW_H_ | 5 #ifndef CHROMEOS_ATTESTATION_ATTESTATION_FLOW_H_ |
| 6 #define CHROMEOS_ATTESTATION_ATTESTATION_FLOW_H_ | 6 #define CHROMEOS_ATTESTATION_ATTESTATION_FLOW_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 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/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/time/time.h" | |
| 14 #include "chromeos/attestation/attestation_constants.h" | 15 #include "chromeos/attestation/attestation_constants.h" |
| 15 #include "chromeos/chromeos_export.h" | 16 #include "chromeos/chromeos_export.h" |
| 16 #include "chromeos/dbus/dbus_method_call_status.h" | 17 #include "chromeos/dbus/dbus_method_call_status.h" |
| 17 #include "third_party/cros_system_api/dbus/service_constants.h" | 18 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 18 | 19 |
| 19 class AccountId; | 20 class AccountId; |
| 20 | 21 |
| 22 namespace base { | |
| 23 | |
|
achuithb
2016/12/05 19:53:59
remove newline
| |
| 24 class TickClock; | |
| 25 | |
|
achuithb
2016/12/05 19:53:59
remove newline
| |
| 26 } // namespace base | |
|
achuithb
2016/12/05 19:53:59
drop comment.
| |
| 27 | |
| 21 namespace cryptohome { | 28 namespace cryptohome { |
| 22 | 29 |
| 23 class AsyncMethodCaller; | 30 class AsyncMethodCaller; |
| 24 | 31 |
| 25 } // namespace cryptohome | 32 } // namespace cryptohome |
| 26 | 33 |
| 27 namespace chromeos { | 34 namespace chromeos { |
| 28 | 35 |
| 29 class CryptohomeClient; | 36 class CryptohomeClient; |
| 30 | 37 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 41 virtual void SendCertificateRequest(const std::string& request, | 48 virtual void SendCertificateRequest(const std::string& request, |
| 42 const DataCallback& on_response) = 0; | 49 const DataCallback& on_response) = 0; |
| 43 virtual PrivacyCAType GetType(); | 50 virtual PrivacyCAType GetType(); |
| 44 }; | 51 }; |
| 45 | 52 |
| 46 // Implements the message flow for Chrome OS attestation tasks. Generally this | 53 // Implements the message flow for Chrome OS attestation tasks. Generally this |
| 47 // consists of coordinating messages between the Chrome OS attestation service | 54 // consists of coordinating messages between the Chrome OS attestation service |
| 48 // and the Chrome OS Privacy CA server. Sample usage: | 55 // and the Chrome OS Privacy CA server. Sample usage: |
| 49 // AttestationFlow flow(AsyncMethodCaller::GetInstance(), | 56 // AttestationFlow flow(AsyncMethodCaller::GetInstance(), |
| 50 // DBusThreadManager::Get().GetCryptohomeClient(), | 57 // DBusThreadManager::Get().GetCryptohomeClient(), |
| 51 // std::move(my_server_proxy)); | 58 // std::move(my_server_proxy), |
| 59 // base::TimeDelta::Max()); | |
| 52 // AttestationFlow::CertificateCallback callback = base::Bind(&MyCallback); | 60 // AttestationFlow::CertificateCallback callback = base::Bind(&MyCallback); |
| 53 // flow.GetCertificate(ENTERPRISE_USER_CERTIFICATE, false, callback); | 61 // flow.GetCertificate(ENTERPRISE_USER_CERTIFICATE, false, callback); |
| 54 class CHROMEOS_EXPORT AttestationFlow { | 62 class CHROMEOS_EXPORT AttestationFlow { |
| 55 public: | 63 public: |
| 56 typedef base::Callback<void(bool success, | 64 typedef base::Callback<void(bool success, |
| 57 const std::string& pem_certificate_chain)> | 65 const std::string& pem_certificate_chain)> |
| 58 CertificateCallback; | 66 CertificateCallback; |
| 59 | 67 |
| 60 // Returns the attestation key type for a given |certificate_profile|. | 68 // Returns the attestation key type for a given |certificate_profile|. |
| 61 // | 69 // |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 72 // certificate_profile - Specifies what kind of certificate the key is for. | 80 // certificate_profile - Specifies what kind of certificate the key is for. |
| 73 // request_origin - For content protection profiles, certificate requests | 81 // request_origin - For content protection profiles, certificate requests |
| 74 // are origin-specific. This string must uniquely identify | 82 // are origin-specific. This string must uniquely identify |
| 75 // the origin of the request. | 83 // the origin of the request. |
| 76 static std::string GetKeyNameForProfile( | 84 static std::string GetKeyNameForProfile( |
| 77 AttestationCertificateProfile certificate_profile, | 85 AttestationCertificateProfile certificate_profile, |
| 78 const std::string& request_origin); | 86 const std::string& request_origin); |
| 79 | 87 |
| 80 AttestationFlow(cryptohome::AsyncMethodCaller* async_caller, | 88 AttestationFlow(cryptohome::AsyncMethodCaller* async_caller, |
| 81 CryptohomeClient* cryptohome_client, | 89 CryptohomeClient* cryptohome_client, |
| 82 std::unique_ptr<ServerProxy> server_proxy); | 90 std::unique_ptr<ServerProxy> server_proxy, |
| 91 base::TimeDelta preparedness_timeout); | |
| 83 virtual ~AttestationFlow(); | 92 virtual ~AttestationFlow(); |
| 84 | 93 |
| 85 // Gets an attestation certificate for a hardware-protected key. If a key for | 94 // Gets an attestation certificate for a hardware-protected key. If a key for |
| 86 // the given profile does not exist, it will be generated and a certificate | 95 // the given profile does not exist, it will be generated and a certificate |
| 87 // request will be made to the Chrome OS Privacy CA to issue a certificate for | 96 // request will be made to the Chrome OS Privacy CA to issue a certificate for |
| 88 // the key. If the key already exists and |force_new_key| is false, the | 97 // the key. If the key already exists and |force_new_key| is false, the |
| 89 // existing certificate is returned. | 98 // existing certificate is returned. |
| 90 // | 99 // |
| 100 // If the TPM has not been prepared for attestation yet, this method will poll | |
| 101 // the attestation preparedness within the flow's |preparedness_timeout|. | |
| 102 // There is no guarantee than a retry will be made if the timeout is too | |
| 103 // short (e.g. less than 10 seconds). | |
|
achuithb
2016/12/05 19:53:59
It's unusual to reference a param defined in one f
| |
| 104 // | |
| 91 // Parameters | 105 // Parameters |
| 92 // certificate_profile - Specifies what kind of certificate should be | 106 // certificate_profile - Specifies what kind of certificate should be |
| 93 // requested from the CA. | 107 // requested from the CA. |
| 94 // account_id - Identifies the currently active user. This is ignored when | 108 // account_id - Identifies the currently active user. This is ignored when |
| 95 // using the enterprise machine cert profile. | 109 // using the enterprise machine cert profile. |
| 96 // request_origin - For content protection profiles, certificate requests | 110 // request_origin - For content protection profiles, certificate requests |
| 97 // are origin-specific. This string must uniquely identify | 111 // are origin-specific. This string must uniquely identify |
| 98 // the origin of the request. | 112 // the origin of the request. |
| 99 // force_new_key - If set to true, a new key will be generated even if a key | 113 // force_new_key - If set to true, a new key will be generated even if a key |
| 100 // already exists for the profile. The new key will replace | 114 // already exists for the profile. The new key will replace |
| 101 // the existing key on success. | 115 // the existing key on success. |
| 102 // callback - A callback which will be called when the operation completes. | 116 // callback - A callback which will be called when the operation completes. |
| 103 // On success |result| will be true and |data| will contain the | 117 // On success |result| will be true and |data| will contain the |
| 104 // PCA-issued certificate chain in PEM format. | 118 // PCA-issued certificate chain in PEM format. |
| 105 virtual void GetCertificate(AttestationCertificateProfile certificate_profile, | 119 virtual void GetCertificate(AttestationCertificateProfile certificate_profile, |
| 106 const AccountId& account_id, | 120 const AccountId& account_id, |
| 107 const std::string& request_origin, | 121 const std::string& request_origin, |
| 108 bool force_new_key, | 122 bool force_new_key, |
| 109 const CertificateCallback& callback); | 123 const CertificateCallback& callback); |
| 110 | 124 |
| 125 // Sets the tick clock for tests. | |
| 126 void SetTickClockForTest(base::TickClock* tick_clock); | |
| 127 | |
| 111 private: | 128 private: |
| 129 struct RetryData; | |
| 130 | |
| 112 // Asynchronously initiates the attestation enrollment flow. | 131 // Asynchronously initiates the attestation enrollment flow. |
| 132 // If attestation is not ready yet, retry as needed. | |
| 113 // | 133 // |
| 114 // Parameters | 134 // Parameters |
| 115 // on_failure - Called if any failure occurs. | 135 // on_failure - Called if any failure occurs. |
| 136 // next_task - Called on successful enrollment. | |
| 137 void InitiateEnroll(const base::Closure& on_failure, | |
| 138 const base::Closure& next_task); | |
| 139 | |
| 140 // Asynchronously tries to initiate the attestation enrollment flow. | |
| 141 // If attestation is not ready yet, retry as needed. | |
| 142 // | |
| 143 // Parameters | |
| 144 // retry_data - Data to manage retries. | |
| 145 // on_failure - Called if any failure occurs. | |
| 146 // next_task - Called on successful enrollment. | |
| 147 void TryInitiateEnroll(RetryData* retry_data, | |
| 148 const base::Closure& on_failure, | |
| 149 const base::Closure& next_task); | |
| 150 | |
| 151 // Called when atestation is not prepared yet, to re-initiate enrollment | |
|
achuithb
2016/12/05 19:53:59
attestation spelling
| |
| 152 // after a delay. | |
| 153 // | |
| 154 // Parameters | |
| 155 // on_failure - Called if any failure occurs. | |
| 156 // next_task - Called on successful enrollment. | |
| 157 void RetryInitiateEnroll(const base::Closure& on_failure, | |
| 158 const base::Closure& next_task); | |
| 159 | |
| 160 // Called when attestation is prepared, to start the actual enrollment flow. | |
| 161 // | |
| 162 // Parameters | |
| 163 // on_failure - Called if any failure occurs. | |
| 116 // next_task - Called on successful enrollment. | 164 // next_task - Called on successful enrollment. |
| 117 void StartEnroll(const base::Closure& on_failure, | 165 void StartEnroll(const base::Closure& on_failure, |
| 118 const base::Closure& next_task); | 166 const base::Closure& next_task); |
| 119 | 167 |
| 120 // Called when the attestation daemon has finished creating an enrollment | 168 // Called when the attestation daemon has finished creating an enrollment |
| 121 // request for the Privacy CA. The request is asynchronously forwarded as-is | 169 // request for the Privacy CA. The request is asynchronously forwarded as-is |
| 122 // to the PCA. | 170 // to the PCA. |
| 123 // | 171 // |
| 124 // Parameters | 172 // Parameters |
| 125 // on_failure - Called if any failure occurs. | 173 // on_failure - Called if any failure occurs. |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 // Parameters | 264 // Parameters |
| 217 // key_type - The type of the key for which a certificate is requested. | 265 // key_type - The type of the key for which a certificate is requested. |
| 218 // account_id - Identifies the active user. | 266 // account_id - Identifies the active user. |
| 219 // key_name - The name of the key for which a certificate is requested. | 267 // key_name - The name of the key for which a certificate is requested. |
| 220 // callback - Called when the operation completes. | 268 // callback - Called when the operation completes. |
| 221 void GetExistingCertificate(AttestationKeyType key_type, | 269 void GetExistingCertificate(AttestationKeyType key_type, |
| 222 const AccountId& account_id, | 270 const AccountId& account_id, |
| 223 const std::string& key_name, | 271 const std::string& key_name, |
| 224 const CertificateCallback& callback); | 272 const CertificateCallback& callback); |
| 225 | 273 |
| 274 // Handles retries. If |retry_data| indicates that we are done retrying, | |
| 275 // runs |on_giving_up|, otherwise runs |on_retrying| after a delay. | |
| 276 void StillRetrying(RetryData* retry_data, | |
| 277 const base::Closure& on_giving_up, | |
| 278 const base::Closure& on_retrying); | |
| 279 // Handles the end of retries. Deletes |retry_data| and runs |continuation|. | |
| 280 void DoneRetrying(RetryData* retry_data, const base::Closure& continuation); | |
| 281 | |
| 226 cryptohome::AsyncMethodCaller* async_caller_; | 282 cryptohome::AsyncMethodCaller* async_caller_; |
| 227 CryptohomeClient* cryptohome_client_; | 283 CryptohomeClient* cryptohome_client_; |
| 228 std::unique_ptr<ServerProxy> server_proxy_; | 284 std::unique_ptr<ServerProxy> server_proxy_; |
| 229 | 285 |
| 286 base::TimeDelta preparedness_timeout_; | |
| 287 base::TickClock* tick_clock_ = nullptr; | |
| 288 | |
| 230 base::WeakPtrFactory<AttestationFlow> weak_factory_; | 289 base::WeakPtrFactory<AttestationFlow> weak_factory_; |
| 231 | 290 |
| 232 DISALLOW_COPY_AND_ASSIGN(AttestationFlow); | 291 DISALLOW_COPY_AND_ASSIGN(AttestationFlow); |
| 233 }; | 292 }; |
| 234 | 293 |
| 235 } // namespace attestation | 294 } // namespace attestation |
| 236 } // namespace chromeos | 295 } // namespace chromeos |
| 237 | 296 |
| 238 #endif // CHROMEOS_ATTESTATION_ATTESTATION_FLOW_H_ | 297 #endif // CHROMEOS_ATTESTATION_ATTESTATION_FLOW_H_ |
| OLD | NEW |