-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathattestation_task.cc
244 lines (216 loc) · 8.78 KB
/
attestation_task.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Asynchronous attestation tasks.
#include "cryptohome/attestation_task.h"
#include <string>
#include <brillo/secure_blob.h>
#include "cryptohome/attestation.h"
using brillo::SecureBlob;
namespace cryptohome {
AttestationTask::AttestationTask(AttestationTaskObserver* observer,
Attestation* attestation,
int sequence_id)
: MountTask(observer, NULL, sequence_id),
attestation_(attestation) {
}
AttestationTask::~AttestationTask() {}
CreateEnrollRequestTask::CreateEnrollRequestTask(
AttestationTaskObserver* observer,
Attestation* attestation,
Attestation::PCAType pca_type,
int sequence_id)
: AttestationTask(observer, attestation, sequence_id),
pca_type_(pca_type) {}
CreateEnrollRequestTask::~CreateEnrollRequestTask() {}
void CreateEnrollRequestTask::Run() {
result()->set_return_status(FALSE);
if (attestation_) {
SecureBlob pca_request;
bool status = attestation_->CreateEnrollRequest(pca_type_, &pca_request);
result()->set_return_status(status);
result()->set_return_data(pca_request);
}
Notify();
}
EnrollTask::EnrollTask(AttestationTaskObserver* observer,
Attestation* attestation,
Attestation::PCAType pca_type,
const SecureBlob& pca_response,
int sequence_id)
: AttestationTask(observer, attestation, sequence_id),
pca_type_(pca_type),
pca_response_(pca_response) {
}
EnrollTask::~EnrollTask() {}
void EnrollTask::Run() {
result()->set_return_status(FALSE);
if (attestation_) {
bool status = attestation_->Enroll(pca_type_, pca_response_);
result()->set_return_status(status);
}
Notify();
}
CreateCertRequestTask::CreateCertRequestTask(AttestationTaskObserver* observer,
Attestation* attestation,
Attestation::PCAType pca_type,
CertificateProfile profile,
const std::string& username,
const std::string& origin,
int sequence_id)
: AttestationTask(observer, attestation, sequence_id),
pca_type_(pca_type),
profile_(profile),
username_(username),
origin_(origin) {
}
CreateCertRequestTask::~CreateCertRequestTask() {}
void CreateCertRequestTask::Run() {
result()->set_return_status(FALSE);
if (attestation_) {
SecureBlob pca_request;
bool status = attestation_->CreateCertRequest(pca_type_,
profile_,
username_,
origin_,
&pca_request);
result()->set_return_status(status);
result()->set_return_data(pca_request);
}
Notify();
}
FinishCertRequestTask::FinishCertRequestTask(AttestationTaskObserver* observer,
Attestation* attestation,
const SecureBlob& pca_response,
bool is_user_specific,
const std::string& username,
const std::string& key_name,
int sequence_id)
: AttestationTask(observer, attestation, sequence_id),
pca_response_(pca_response),
is_user_specific_(is_user_specific),
username_(username),
key_name_(key_name) {
}
FinishCertRequestTask::~FinishCertRequestTask() {}
void FinishCertRequestTask::Run() {
result()->set_return_status(FALSE);
if (attestation_) {
SecureBlob cert;
bool status = attestation_->FinishCertRequest(pca_response_,
is_user_specific_,
username_,
key_name_,
&cert);
result()->set_return_status(status);
result()->set_return_data(cert);
}
Notify();
}
SignChallengeTask::SignChallengeTask(AttestationTaskObserver* observer,
Attestation* attestation,
bool is_user_specific,
const std::string& username,
const std::string& key_name,
const SecureBlob& challenge,
int sequence_id)
: AttestationTask(observer, attestation, sequence_id),
challenge_type_(kSimpleChallengeType),
is_user_specific_(is_user_specific),
username_(username),
key_name_(key_name),
challenge_(challenge) {
}
SignChallengeTask::SignChallengeTask(AttestationTaskObserver* observer,
Attestation* attestation,
Attestation::VAType va_type,
bool is_user_specific,
const std::string& username,
const std::string& key_name,
const std::string& domain,
const SecureBlob& device_id,
bool include_signed_public_key,
const SecureBlob& challenge,
const std::string& key_name_for_spkac,
int sequence_id)
: AttestationTask(observer, attestation, sequence_id),
challenge_type_(kEnterpriseVaChallengeType),
va_type_(va_type),
is_user_specific_(is_user_specific),
username_(username),
key_name_(key_name),
domain_(domain),
device_id_(device_id),
include_signed_public_key_(include_signed_public_key),
challenge_(challenge),
key_name_for_spkac_(key_name_for_spkac) {}
SignChallengeTask::~SignChallengeTask() {}
void SignChallengeTask::Run() {
result()->set_return_status(FALSE);
if (!attestation_) {
Notify();
return;
}
SecureBlob response;
bool status = false;
switch (challenge_type_) {
case kSimpleChallengeType:
status = attestation_->SignSimpleChallenge(is_user_specific_,
username_,
key_name_,
challenge_,
&response);
break;
case kEnterpriseChallengeType:
status = attestation_->SignEnterpriseChallenge(is_user_specific_,
username_,
key_name_,
domain_,
device_id_,
include_signed_public_key_,
challenge_,
&response);
break;
case kEnterpriseVaChallengeType:
status = attestation_->SignEnterpriseVaChallenge(
va_type_,
is_user_specific_,
username_,
key_name_,
domain_,
device_id_,
include_signed_public_key_,
challenge_,
key_name_for_spkac_,
&response);
break;
}
result()->set_return_status(status);
result()->set_return_data(response);
Notify();
}
RegisterKeyTask::RegisterKeyTask(AttestationTaskObserver* observer,
Attestation* attestation,
bool is_user_specific,
const std::string& username,
const std::string& key_name,
int sequence_id)
: AttestationTask(observer, attestation, sequence_id),
is_user_specific_(is_user_specific),
username_(username),
key_name_(key_name) {
}
RegisterKeyTask::~RegisterKeyTask() {}
void RegisterKeyTask::Run() {
result()->set_return_status(FALSE);
if (attestation_) {
bool status = attestation_->RegisterKey(is_user_specific_,
username_,
key_name_,
false); // include_certificates
result()->set_return_status(status);
}
Notify();
}
} // namespace cryptohome