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

Side by Side Diff: chromeos/attestation/attestation_flow.cc

Issue 20873002: Added support for the content protection profile to AttestationFlow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 4 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 | Annotate | Revision Log
OLDNEW
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 #include "chromeos/attestation/attestation_flow.h" 5 #include "chromeos/attestation/attestation_flow.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "chromeos/cryptohome/async_method_caller.h" 8 #include "chromeos/cryptohome/async_method_caller.h"
9 #include "chromeos/dbus/cryptohome_client.h" 9 #include "chromeos/dbus/cryptohome_client.h"
10 10
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 if (!callback.is_null()) 52 if (!callback.is_null())
53 callback.Run(result, data); 53 callback.Run(result, data);
54 } 54 }
55 55
56 AttestationKeyType GetKeyTypeForProfile( 56 AttestationKeyType GetKeyTypeForProfile(
57 AttestationCertificateProfile profile) { 57 AttestationCertificateProfile profile) {
58 switch (profile) { 58 switch (profile) {
59 case PROFILE_ENTERPRISE_MACHINE_CERTIFICATE: 59 case PROFILE_ENTERPRISE_MACHINE_CERTIFICATE:
60 return KEY_DEVICE; 60 return KEY_DEVICE;
61 case PROFILE_ENTERPRISE_USER_CERTIFICATE: 61 case PROFILE_ENTERPRISE_USER_CERTIFICATE:
62 case PROFILE_CONTENT_PROTECTION_CERTIFICATE:
62 return KEY_USER; 63 return KEY_USER;
63 } 64 }
64 NOTREACHED(); 65 NOTREACHED();
65 return KEY_USER; 66 return KEY_USER;
66 } 67 }
67 68
68 std::string GetKeyNameForProfile( 69 std::string GetKeyNameForProfile(AttestationCertificateProfile profile,
69 AttestationCertificateProfile profile) { 70 const std::string& origin) {
70 switch (profile) { 71 switch (profile) {
71 case PROFILE_ENTERPRISE_MACHINE_CERTIFICATE: 72 case PROFILE_ENTERPRISE_MACHINE_CERTIFICATE:
72 return kEnterpriseMachineKey; 73 return kEnterpriseMachineKey;
73 case PROFILE_ENTERPRISE_USER_CERTIFICATE: 74 case PROFILE_ENTERPRISE_USER_CERTIFICATE:
74 return kEnterpriseUserKey; 75 return kEnterpriseUserKey;
76 case PROFILE_CONTENT_PROTECTION_CERTIFICATE:
77 return std::string(kContentProtectionKeyPrefix) + origin;
75 } 78 }
76 NOTREACHED(); 79 NOTREACHED();
77 return ""; 80 return "";
78 } 81 }
79 82
80 int GetCertificateOptionsForProfile(
81 AttestationCertificateProfile profile) {
82 switch (profile) {
83 case PROFILE_ENTERPRISE_MACHINE_CERTIFICATE:
84 return CERTIFICATE_INCLUDE_STABLE_ID | CERTIFICATE_INCLUDE_DEVICE_STATE;
85 case PROFILE_ENTERPRISE_USER_CERTIFICATE:
86 return CERTIFICATE_INCLUDE_DEVICE_STATE;
87 }
88 NOTREACHED();
89 return CERTIFICATE_OPTION_NONE;
90 }
91
92 } // namespace 83 } // namespace
93 84
94 AttestationFlow::AttestationFlow(cryptohome::AsyncMethodCaller* async_caller, 85 AttestationFlow::AttestationFlow(cryptohome::AsyncMethodCaller* async_caller,
95 CryptohomeClient* cryptohome_client, 86 CryptohomeClient* cryptohome_client,
96 scoped_ptr<ServerProxy> server_proxy) 87 scoped_ptr<ServerProxy> server_proxy)
97 : async_caller_(async_caller), 88 : async_caller_(async_caller),
98 cryptohome_client_(cryptohome_client), 89 cryptohome_client_(cryptohome_client),
99 server_proxy_(server_proxy.Pass()), 90 server_proxy_(server_proxy.Pass()),
100 weak_factory_(this) { 91 weak_factory_(this) {
101 } 92 }
102 93
103 AttestationFlow::~AttestationFlow() { 94 AttestationFlow::~AttestationFlow() {
104 } 95 }
105 96
106 void AttestationFlow::GetCertificate( 97 void AttestationFlow::GetCertificate(
107 AttestationCertificateProfile certificate_profile, 98 AttestationCertificateProfile certificate_profile,
99 const std::string& user_email,
100 const std::string& request_origin,
108 bool force_new_key, 101 bool force_new_key,
109 const CertificateCallback& callback) { 102 const CertificateCallback& callback) {
110 // If this device has not enrolled with the Privacy CA, we need to do that 103 // If this device has not enrolled with the Privacy CA, we need to do that
111 // first. Once enrolled we can proceed with the certificate request. 104 // first. Once enrolled we can proceed with the certificate request.
112 base::Closure do_cert_request = base::Bind( 105 base::Closure do_cert_request = base::Bind(
113 &AttestationFlow::StartCertificateRequest, 106 &AttestationFlow::StartCertificateRequest,
114 weak_factory_.GetWeakPtr(), 107 weak_factory_.GetWeakPtr(),
115 certificate_profile, 108 certificate_profile,
109 user_email,
110 request_origin,
116 force_new_key, 111 force_new_key,
117 callback); 112 callback);
118 base::Closure on_enroll_failure = base::Bind(callback, false, ""); 113 base::Closure on_enroll_failure = base::Bind(callback, false, "");
119 base::Closure do_enroll = base::Bind(&AttestationFlow::StartEnroll, 114 base::Closure do_enroll = base::Bind(&AttestationFlow::StartEnroll,
120 weak_factory_.GetWeakPtr(), 115 weak_factory_.GetWeakPtr(),
121 on_enroll_failure, 116 on_enroll_failure,
122 do_cert_request); 117 do_cert_request);
123 cryptohome_client_->TpmAttestationIsEnrolled(base::Bind( 118 cryptohome_client_->TpmAttestationIsEnrolled(base::Bind(
124 &DBusBoolRedirectCallback, 119 &DBusBoolRedirectCallback,
125 do_cert_request, // If enrolled, proceed with cert request. 120 do_cert_request, // If enrolled, proceed with cert request.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 return; 184 return;
190 } 185 }
191 186
192 // Enrollment has successfully completed, we can move on to whatever is next. 187 // Enrollment has successfully completed, we can move on to whatever is next.
193 if (!next_task.is_null()) 188 if (!next_task.is_null())
194 next_task.Run(); 189 next_task.Run();
195 } 190 }
196 191
197 void AttestationFlow::StartCertificateRequest( 192 void AttestationFlow::StartCertificateRequest(
198 AttestationCertificateProfile certificate_profile, 193 AttestationCertificateProfile certificate_profile,
194 const std::string& user_email,
195 const std::string& request_origin,
199 bool generate_new_key, 196 bool generate_new_key,
200 const CertificateCallback& callback) { 197 const CertificateCallback& callback) {
201 AttestationKeyType key_type = GetKeyTypeForProfile(certificate_profile); 198 AttestationKeyType key_type = GetKeyTypeForProfile(certificate_profile);
202 std::string key_name = GetKeyNameForProfile(certificate_profile); 199 std::string key_name = GetKeyNameForProfile(certificate_profile,
200 request_origin);
203 if (generate_new_key) { 201 if (generate_new_key) {
204 // Get the attestation service to create a Privacy CA certificate request. 202 // Get the attestation service to create a Privacy CA certificate request.
205 async_caller_->AsyncTpmAttestationCreateCertRequest( 203 async_caller_->AsyncTpmAttestationCreateCertRequest(
206 GetCertificateOptionsForProfile(certificate_profile), 204 certificate_profile,
205 user_email,
206 request_origin,
207 base::Bind(&AttestationFlow::SendCertificateRequestToPCA, 207 base::Bind(&AttestationFlow::SendCertificateRequestToPCA,
208 weak_factory_.GetWeakPtr(), 208 weak_factory_.GetWeakPtr(),
209 key_type, 209 key_type,
210 key_name, 210 key_name,
211 callback)); 211 callback));
212 } else { 212 } else {
213 // If the key already exists, query the existing certificate. 213 // If the key already exists, query the existing certificate.
214 base::Closure on_key_exists = base::Bind( 214 base::Closure on_key_exists = base::Bind(
215 &AttestationFlow::GetExistingCertificate, 215 &AttestationFlow::GetExistingCertificate,
216 weak_factory_.GetWeakPtr(), 216 weak_factory_.GetWeakPtr(),
217 key_type, 217 key_type,
218 key_name, 218 key_name,
219 callback); 219 callback);
220 // If the key does not exist, call this method back with |generate_new_key| 220 // If the key does not exist, call this method back with |generate_new_key|
221 // set to true. 221 // set to true.
222 base::Closure on_key_not_exists = base::Bind( 222 base::Closure on_key_not_exists = base::Bind(
223 &AttestationFlow::StartCertificateRequest, 223 &AttestationFlow::StartCertificateRequest,
224 weak_factory_.GetWeakPtr(), 224 weak_factory_.GetWeakPtr(),
225 certificate_profile, 225 certificate_profile,
226 user_email,
227 request_origin,
226 true, 228 true,
227 callback); 229 callback);
228 cryptohome_client_->TpmAttestationDoesKeyExist( 230 cryptohome_client_->TpmAttestationDoesKeyExist(
229 key_type, 231 key_type,
230 key_name, 232 key_name,
231 base::Bind(&DBusBoolRedirectCallback, 233 base::Bind(&DBusBoolRedirectCallback,
232 on_key_exists, 234 on_key_exists,
233 on_key_not_exists, 235 on_key_not_exists,
234 base::Bind(callback, false, ""))); 236 base::Bind(callback, false, "")));
235 } 237 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 const std::string& key_name, 285 const std::string& key_name,
284 const CertificateCallback& callback) { 286 const CertificateCallback& callback) {
285 cryptohome_client_->TpmAttestationGetCertificate( 287 cryptohome_client_->TpmAttestationGetCertificate(
286 key_type, 288 key_type,
287 key_name, 289 key_name,
288 base::Bind(&DBusDataMethodCallback, callback)); 290 base::Bind(&DBusDataMethodCallback, callback));
289 } 291 }
290 292
291 } // namespace attestation 293 } // namespace attestation
292 } // namespace chromeos 294 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/attestation/attestation_flow.h ('k') | chromeos/attestation/attestation_flow_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698