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
|
/*
* Licensed Materials - Property of IBM
*
* trousers - An open source TCG Software Stack
*
* (C) Copyright International Business Machines Corp. 2004
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include "trousers/tss.h"
#include "trousers_types.h"
#include "tcs_tsp.h"
#include "tcsps.h"
#include "tcs_utils.h"
#include "tcs_int_literals.h"
#include "capabilities.h"
#include "tcslog.h"
#include "req_mgr.h"
#include "tcsd_wrap.h"
#include "tcsd.h"
TSS_RESULT
TCSP_CreateMigrationBlob_Internal(TCS_CONTEXT_HANDLE hContext, /* in */
TCS_KEY_HANDLE parentHandle, /* in */
TSS_MIGRATE_SCHEME migrationType, /* in */
UINT32 MigrationKeyAuthSize, /* in */
BYTE * MigrationKeyAuth, /* in */
UINT32 encDataSize, /* in */
BYTE * encData, /* in */
TPM_AUTH * parentAuth, /* in, out */
TPM_AUTH * entityAuth, /* in, out */
UINT32 * randomSize, /* out */
BYTE ** random, /* out */
UINT32 * outDataSize, /* out */
BYTE ** outData) /* out */
{
UINT64 offset = 0;
UINT32 paramSize;
TSS_RESULT result;
TCPA_KEY_HANDLE keyHandle;
BYTE txBlob[TSS_TPM_TXBLOB_SIZE];
LogDebug("Entering TPM_CreateMigrationBlob");
if ((result = ctx_verify_context(hContext)))
goto done;
if (parentAuth != NULL) {
if ((result = auth_mgr_check(hContext, &parentAuth->AuthHandle)))
goto done;
}
if ((result = auth_mgr_check(hContext, &entityAuth->AuthHandle)))
goto done;
if ((result = ensureKeyIsLoaded(hContext, parentHandle, &keyHandle)))
goto done;
switch (migrationType) {
case TSS_MS_MIGRATE:
migrationType = TCPA_MS_MIGRATE;
break;
case TSS_MS_REWRAP:
migrationType = TCPA_MS_REWRAP;
break;
case TSS_MS_MAINT:
migrationType = TCPA_MS_MAINT;
break;
default:
/* Let the TPM return an error */
break;
}
if ((result = tpm_rqu_build(TPM_ORD_CreateMigrationBlob, &offset, txBlob, keyHandle,
migrationType, MigrationKeyAuthSize, MigrationKeyAuth,
encDataSize, encData, parentAuth, entityAuth)))
return result;
if ((result = req_mgr_submit_req(txBlob)))
goto done;
result = UnloadBlob_Header(txBlob, ¶mSize);
if (result == TSS_SUCCESS) {
result = tpm_rsp_parse(TPM_ORD_CreateMigrationBlob, txBlob, paramSize, randomSize,
random, outDataSize, outData, parentAuth, entityAuth);
}
LogResult("TPM_CreateMigrationBlob", result);
done:
auth_mgr_release_auth(entityAuth, parentAuth, hContext);
return result;
}
TSS_RESULT
TCSP_ConvertMigrationBlob_Internal(TCS_CONTEXT_HANDLE hContext, /* in */
TCS_KEY_HANDLE parentHandle, /* in */
UINT32 inDataSize, /* in */
BYTE * inData, /* in */
UINT32 randomSize, /* in */
BYTE * random, /* in */
TPM_AUTH * parentAuth, /* in, out */
UINT32 * outDataSize, /* out */
BYTE ** outData) /* out */
{
TSS_RESULT result;
UINT32 paramSize;
UINT64 offset = 0;
TCPA_KEY_HANDLE keySlot;
BYTE txBlob[TSS_TPM_TXBLOB_SIZE];
LogDebug("ConvertMigBlob");
if ((result = ctx_verify_context(hContext)))
goto done;
if (parentAuth != NULL) {
LogDebug("Auth Used");
if ((result = auth_mgr_check(hContext, &parentAuth->AuthHandle)))
goto done;
} else {
LogDebug("No Auth");
}
if ((result = ensureKeyIsLoaded(hContext, parentHandle, &keySlot)))
goto done;
if ((result = tpm_rqu_build(TPM_ORD_ConvertMigrationBlob, &offset, txBlob, keySlot,
inDataSize, inData, randomSize, random, parentAuth)))
return result;
if ((result = req_mgr_submit_req(txBlob)))
goto done;
offset = 10;
result = UnloadBlob_Header(txBlob, ¶mSize);
if (!result) {
result = tpm_rsp_parse(TPM_ORD_ConvertMigrationBlob, txBlob, paramSize, outDataSize,
outData, parentAuth, NULL);
}
LogResult("***Leaving ConvertMigrationBlob with result ", result);
done:
auth_mgr_release_auth(parentAuth, NULL, hContext);
return result;
}
TSS_RESULT
TCSP_AuthorizeMigrationKey_Internal(TCS_CONTEXT_HANDLE hContext, /* in */
TSS_MIGRATE_SCHEME migrateScheme, /* in */
UINT32 MigrationKeySize, /* in */
BYTE * MigrationKey, /* in */
TPM_AUTH * ownerAuth, /* in, out */
UINT32 * MigrationKeyAuthSize, /* out */
BYTE ** MigrationKeyAuth) /* out */
{
TSS_RESULT result;
UINT32 paramSize;
UINT64 offset = 0;
//TCPA_MIGRATIONKEYAUTH container;
BYTE txBlob[TSS_TPM_TXBLOB_SIZE];
LogDebug("TCSP_AuthorizeMigrationKey");
if ((result = ctx_verify_context(hContext)))
goto done;
if ((result = auth_mgr_check(hContext, &ownerAuth->AuthHandle)))
goto done;
switch (migrateScheme) {
case TSS_MS_MIGRATE:
migrateScheme = TCPA_MS_MIGRATE;
break;
case TSS_MS_REWRAP:
migrateScheme = TCPA_MS_REWRAP;
break;
case TSS_MS_MAINT:
migrateScheme = TCPA_MS_MAINT;
break;
#ifdef TSS_BUILD_CMK
case TSS_MS_RESTRICT_MIGRATE:
migrateScheme = TPM_MS_RESTRICT_MIGRATE;
break;
case TSS_MS_RESTRICT_APPROVE_DOUBLE:
migrateScheme = TPM_MS_RESTRICT_APPROVE_DOUBLE;
break;
#endif
default:
/* Let the TPM return an error */
break;
}
if ((result = tpm_rqu_build(TPM_ORD_AuthorizeMigrationKey, &offset, txBlob, migrateScheme,
MigrationKeySize, MigrationKey, ownerAuth)))
return result;
if ((result = req_mgr_submit_req(txBlob)))
goto done;
result = UnloadBlob_Header(txBlob, ¶mSize);
if (!result) {
result = tpm_rsp_parse(TPM_ORD_AuthorizeMigrationKey, txBlob, paramSize,
MigrationKeyAuthSize, MigrationKeyAuth, ownerAuth);
}
LogDebugFn("TPM_AuthorizeMigrationKey result: 0x%x", result);
done:
auth_mgr_release_auth(ownerAuth, NULL, hContext);
return result;
}
|