3
* Licensed Materials - Property of IBM
5
* trousers - An open source TCG Software Stack
7
* (C) Copyright International Business Machines Corp. 2004-2007
16
#include "trousers/tss.h"
17
#include "trousers/trousers.h"
18
#include "trousers_types.h"
19
#include "spi_utils.h"
20
#include "capabilities.h"
22
#include "hosttable.h"
23
#include "tcsd_wrap.h"
25
#include "rpc_tcstp_tsp.h"
29
RPC_LoadKeyByBlob_TP(struct host_table_entry *hte,
30
TCS_KEY_HANDLE hUnwrappingKey, /* in */
31
UINT32 cWrappedKeyBlobSize, /* in */
32
BYTE * rgbWrappedKeyBlob, /* in */
33
TPM_AUTH * pAuth, /* in, out */
34
TCS_KEY_HANDLE * phKeyTCSI, /* out */
35
TCS_KEY_HANDLE * phKeyHMAC) /* out */
40
initData(&hte->comm, 5);
41
hte->comm.hdr.u.ordinal = TCSD_ORD_LOADKEYBYBLOB;
42
LogDebugFn("IN: TCS Context: 0x%x", hte->tcsContext);
44
if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
45
return TSPERR(TSS_E_INTERNAL_ERROR);
46
if (setData(TCSD_PACKET_TYPE_UINT32, 1, &hUnwrappingKey, 0, &hte->comm))
47
return TSPERR(TSS_E_INTERNAL_ERROR);
48
if (setData(TCSD_PACKET_TYPE_UINT32, 2, &cWrappedKeyBlobSize, 0, &hte->comm))
49
return TSPERR(TSS_E_INTERNAL_ERROR);
50
if (setData(TCSD_PACKET_TYPE_PBYTE, 3, rgbWrappedKeyBlob, cWrappedKeyBlobSize, &hte->comm))
51
return TSPERR(TSS_E_INTERNAL_ERROR);
54
if (setData(TCSD_PACKET_TYPE_AUTH, 4, pAuth, 0, &hte->comm))
55
return TSPERR(TSS_E_INTERNAL_ERROR);
58
result = sendTCSDPacket(hte);
60
if (result == TSS_SUCCESS)
61
result = hte->comm.hdr.u.result;
63
if (result == TSS_SUCCESS) {
66
if (getData(TCSD_PACKET_TYPE_AUTH, i++, pAuth, 0, &hte->comm))
67
result = TSPERR(TSS_E_INTERNAL_ERROR);
69
if (getData(TCSD_PACKET_TYPE_UINT32, i++, phKeyTCSI, 0, &hte->comm))
70
result = TSPERR(TSS_E_INTERNAL_ERROR);
71
if (getData(TCSD_PACKET_TYPE_UINT32, i++, phKeyHMAC, 0, &hte->comm))
72
result = TSPERR(TSS_E_INTERNAL_ERROR);
74
LogDebugFn("OUT: TCS key handle: 0x%x, TPM key slot: 0x%x", *phKeyTCSI,
82
RPC_EvictKey_TP(struct host_table_entry *hte,
83
TCS_KEY_HANDLE hKey) /* in */
87
initData(&hte->comm, 2);
88
hte->comm.hdr.u.ordinal = TCSD_ORD_EVICTKEY;
89
LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
91
if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
92
return TSPERR(TSS_E_INTERNAL_ERROR);
93
if (setData(TCSD_PACKET_TYPE_UINT32, 1, &hKey, 0, &hte->comm))
94
return TSPERR(TSS_E_INTERNAL_ERROR);
96
result = sendTCSDPacket(hte);
98
if (result == TSS_SUCCESS)
99
result = hte->comm.hdr.u.result;
105
RPC_CreateWrapKey_TP(struct host_table_entry *hte,
106
TCS_KEY_HANDLE hWrappingKey, /* in */
107
TCPA_ENCAUTH *KeyUsageAuth, /* in */
108
TCPA_ENCAUTH *KeyMigrationAuth, /* in */
109
UINT32 keyInfoSize, /* in */
110
BYTE * keyInfo, /* in */
111
UINT32 * keyDataSize, /* out */
112
BYTE ** keyData, /* out */
113
TPM_AUTH * pAuth) /* in, out */
117
initData(&hte->comm, 7);
118
hte->comm.hdr.u.ordinal = TCSD_ORD_CREATEWRAPKEY;
119
LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
121
if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
122
return TSPERR(TSS_E_INTERNAL_ERROR);
123
if (setData(TCSD_PACKET_TYPE_UINT32, 1, &hWrappingKey, 0, &hte->comm))
124
return TSPERR(TSS_E_INTERNAL_ERROR);
125
if (setData(TCSD_PACKET_TYPE_ENCAUTH, 2, KeyUsageAuth, 0, &hte->comm))
126
return TSPERR(TSS_E_INTERNAL_ERROR);
127
if (setData(TCSD_PACKET_TYPE_ENCAUTH, 3, KeyMigrationAuth, 0, &hte->comm))
128
return TSPERR(TSS_E_INTERNAL_ERROR);
129
if (setData(TCSD_PACKET_TYPE_UINT32, 4, &keyInfoSize, 0, &hte->comm))
130
return TSPERR(TSS_E_INTERNAL_ERROR);
131
if (setData(TCSD_PACKET_TYPE_PBYTE, 5, keyInfo, keyInfoSize, &hte->comm))
132
return TSPERR(TSS_E_INTERNAL_ERROR);
134
if (setData(TCSD_PACKET_TYPE_AUTH, 6, pAuth, 0, &hte->comm))
135
return TSPERR(TSS_E_INTERNAL_ERROR);
138
result = sendTCSDPacket(hte);
140
if (result == TSS_SUCCESS)
141
result = hte->comm.hdr.u.result;
143
if (result == TSS_SUCCESS) {
144
if (getData(TCSD_PACKET_TYPE_UINT32, 0, keyDataSize, 0, &hte->comm)) {
145
result = TSPERR(TSS_E_INTERNAL_ERROR);
148
*keyData = (BYTE *) malloc(*keyDataSize);
149
if (*keyData == NULL) {
150
LogError("malloc of %u bytes failed.", *keyDataSize);
151
result = TSPERR(TSS_E_OUTOFMEMORY);
154
if (getData(TCSD_PACKET_TYPE_PBYTE, 1, *keyData, *keyDataSize, &hte->comm)) {
156
result = TSPERR(TSS_E_INTERNAL_ERROR);
160
if (getData(TCSD_PACKET_TYPE_AUTH, 2, pAuth, 0, &hte->comm)) {
162
result = TSPERR(TSS_E_INTERNAL_ERROR);
173
RPC_GetPubKey_TP(struct host_table_entry *hte,
174
TCS_KEY_HANDLE hKey, /* in */
175
TPM_AUTH * pAuth, /* in, out */
176
UINT32 * pcPubKeySize, /* out */
177
BYTE ** prgbPubKey) /* out */
182
initData(&hte->comm, 3);
183
hte->comm.hdr.u.ordinal = TCSD_ORD_GETPUBKEY;
184
LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
186
if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
187
return TSPERR(TSS_E_INTERNAL_ERROR);
188
if (setData(TCSD_PACKET_TYPE_UINT32, 1, &hKey, 0, &hte->comm))
189
return TSPERR(TSS_E_INTERNAL_ERROR);
191
if (setData(TCSD_PACKET_TYPE_AUTH, 2, pAuth, 0, &hte->comm))
192
return TSPERR(TSS_E_INTERNAL_ERROR);
195
result = sendTCSDPacket(hte);
197
if (result == TSS_SUCCESS)
198
result = hte->comm.hdr.u.result;
201
if (result == TSS_SUCCESS) {
203
if (getData(TCSD_PACKET_TYPE_AUTH, i++, pAuth, 0, &hte->comm)) {
204
result = TSPERR(TSS_E_INTERNAL_ERROR);
208
if (getData(TCSD_PACKET_TYPE_UINT32, i++, pcPubKeySize, 0, &hte->comm)) {
209
result = TSPERR(TSS_E_INTERNAL_ERROR);
213
*prgbPubKey = (BYTE *) malloc(*pcPubKeySize);
214
if (*prgbPubKey == NULL) {
215
LogError("malloc of %u bytes failed.", *pcPubKeySize);
216
result = TSPERR(TSS_E_OUTOFMEMORY);
219
if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *prgbPubKey, *pcPubKeySize, &hte->comm)) {
221
result = TSPERR(TSS_E_INTERNAL_ERROR);
230
RPC_TerminateHandle_TP(struct host_table_entry *hte,
231
TCS_AUTHHANDLE handle) /* in */
235
initData(&hte->comm, 2);
236
hte->comm.hdr.u.ordinal = TCSD_ORD_TERMINATEHANDLE;
237
LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
239
if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
240
return TSPERR(TSS_E_INTERNAL_ERROR);
241
if (setData(TCSD_PACKET_TYPE_UINT32, 1, &handle, 0, &hte->comm))
242
return TSPERR(TSS_E_INTERNAL_ERROR);
244
result = sendTCSDPacket(hte);
246
if (result == TSS_SUCCESS)
247
result = hte->comm.hdr.u.result;
253
RPC_OwnerReadInternalPub_TP(struct host_table_entry *hte,
254
TCS_KEY_HANDLE hKey, /* in */
255
TPM_AUTH * pOwnerAuth, /* in, out */
256
UINT32 * punPubKeySize, /* out */
257
BYTE ** ppbPubKeyData) /* out */
261
initData(&hte->comm, 3);
262
hte->comm.hdr.u.ordinal = TCSD_ORD_OWNERREADINTERNALPUB;
263
LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
265
if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
266
return TSPERR(TSS_E_INTERNAL_ERROR);
267
if (setData(TCSD_PACKET_TYPE_UINT32, 1, &hKey, 0, &hte->comm))
268
return TSPERR(TSS_E_INTERNAL_ERROR);
269
if (pOwnerAuth != NULL) {
270
if (setData(TCSD_PACKET_TYPE_AUTH, 2, pOwnerAuth, 0, &hte->comm))
271
return TSPERR(TSS_E_INTERNAL_ERROR);
274
result = sendTCSDPacket(hte);
276
if (result == TSS_SUCCESS)
277
result = hte->comm.hdr.u.result;
279
if (result == TSS_SUCCESS) {
280
if (getData(TCSD_PACKET_TYPE_AUTH, 0, pOwnerAuth, 0, &hte->comm))
281
result = TSPERR(TSS_E_INTERNAL_ERROR);
282
if (getData(TCSD_PACKET_TYPE_UINT32, 1, punPubKeySize, 0, &hte->comm))
283
result = TSPERR(TSS_E_INTERNAL_ERROR);
285
*ppbPubKeyData = (BYTE *) malloc(*punPubKeySize);
286
if (*ppbPubKeyData == NULL) {
287
LogError("malloc of %u bytes failed.", *punPubKeySize);
288
return TSPERR(TSS_E_OUTOFMEMORY);
290
if (getData(TCSD_PACKET_TYPE_PBYTE, 2, *ppbPubKeyData, *punPubKeySize,
292
free(*ppbPubKeyData);
293
result = TSPERR(TSS_E_INTERNAL_ERROR);
300
/* TSS 1.2-only interfaces */
301
#ifdef TSS_BUILD_TSS12
303
RPC_KeyControlOwner_TP(struct host_table_entry *hte, // in
304
TCS_KEY_HANDLE hKey, // in
305
UINT32 ulPublicInfoLength, // in
306
BYTE* rgbPublicInfo, // in
307
UINT32 attribName, // in
308
TSS_BOOL attribValue, // in
309
TPM_AUTH* pOwnerAuth, // in, out
310
TSS_UUID* pUuidData) // out
315
initData(&hte->comm, 7);
316
hte->comm.hdr.u.ordinal = TCSD_ORD_KEYCONTROLOWNER;
317
LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
319
if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
320
return TSPERR(TSS_E_INTERNAL_ERROR);
321
if (setData(TCSD_PACKET_TYPE_UINT32, 1, &hKey, 0, &hte->comm))
322
return TSPERR(TSS_E_INTERNAL_ERROR);
323
if (setData(TCSD_PACKET_TYPE_UINT32, 2, &ulPublicInfoLength, 0, &hte->comm))
324
return TSPERR(TSS_E_INTERNAL_ERROR);
325
if (setData(TCSD_PACKET_TYPE_PBYTE, 3, rgbPublicInfo, ulPublicInfoLength, &hte->comm))
326
return TSPERR(TSS_E_INTERNAL_ERROR);
327
if (setData(TCSD_PACKET_TYPE_UINT32, 4, &attribName, 0, &hte->comm))
328
return TSPERR(TSS_E_INTERNAL_ERROR);
329
if (setData(TCSD_PACKET_TYPE_BOOL, 5, &attribValue, 0, &hte->comm))
330
return TSPERR(TSS_E_INTERNAL_ERROR);
331
if (pOwnerAuth != NULL) {
332
if (setData(TCSD_PACKET_TYPE_AUTH, 6, pOwnerAuth, 0, &hte->comm))
333
return TSPERR(TSS_E_INTERNAL_ERROR);
336
result = sendTCSDPacket(hte);
338
if (result == TSS_SUCCESS)
339
result = hte->comm.hdr.u.result;
341
if (result == TSS_SUCCESS) {
342
if (getData(TCSD_PACKET_TYPE_AUTH, 0, pOwnerAuth, 0, &hte->comm))
343
result = TSPERR(TSS_E_INTERNAL_ERROR);
344
if (getData(TCSD_PACKET_TYPE_UUID, 1, pUuidData, 0, &hte->comm))
345
result = TSPERR(TSS_E_INTERNAL_ERROR);