1
2 /*
3 * Licensed Materials - Property of IBM
4 *
5 * trousers - An open source TCG Software Stack
6 *
7 * (C) Copyright International Business Machines Corp. 2004-2006
8 *
9 */
10
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include <string.h>
14 #include <assert.h>
15
16 #include "trousers/tss.h"
17 #include "trousers/trousers.h"
18 #include "trousers_types.h"
19 #include "spi_utils.h"
20 #include "capabilities.h"
21 #include "tsplog.h"
22 #include "hosttable.h"
23 #include "tcsd_wrap.h"
24 #include "obj.h"
25 #include "rpc_tcstp_tsp.h"
26
27
28 TSS_RESULT
RPC_Sign_TP(struct host_table_entry * hte,TCS_KEY_HANDLE keyHandle,UINT32 areaToSignSize,BYTE * areaToSign,TPM_AUTH * privAuth,UINT32 * sigSize,BYTE ** sig)29 RPC_Sign_TP(struct host_table_entry *hte,
30 TCS_KEY_HANDLE keyHandle, /* in */
31 UINT32 areaToSignSize, /* in */
32 BYTE * areaToSign, /* in */
33 TPM_AUTH * privAuth, /* in, out */
34 UINT32 * sigSize, /* out */
35 BYTE ** sig /* out */
36 ) {
37 TSS_RESULT result;
38 int i;
39
40 initData(&hte->comm, 5);
41 hte->comm.hdr.u.ordinal = TCSD_ORD_SIGN;
42 LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
43
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, &keyHandle, 0, &hte->comm))
47 return TSPERR(TSS_E_INTERNAL_ERROR);
48 if (setData(TCSD_PACKET_TYPE_UINT32, 2, &areaToSignSize, 0, &hte->comm))
49 return TSPERR(TSS_E_INTERNAL_ERROR);
50 if (setData(TCSD_PACKET_TYPE_PBYTE, 3, areaToSign, areaToSignSize, &hte->comm))
51 return TSPERR(TSS_E_INTERNAL_ERROR);
52
53 if (privAuth) {
54 if (setData(TCSD_PACKET_TYPE_AUTH, 4, privAuth, 0, &hte->comm))
55 return TSPERR(TSS_E_INTERNAL_ERROR);
56 }
57
58 result = sendTCSDPacket(hte);
59
60 if (result == TSS_SUCCESS)
61 result = hte->comm.hdr.u.result;
62
63 if (result == TSS_SUCCESS) {
64 i = 0;
65 if (privAuth) {
66 if (getData(TCSD_PACKET_TYPE_AUTH, i++, privAuth, 0, &hte->comm)) {
67 result = TSPERR(TSS_E_INTERNAL_ERROR);
68 goto done;
69 }
70 }
71 if (getData(TCSD_PACKET_TYPE_UINT32, i++, sigSize, 0, &hte->comm)) {
72 result = TSPERR(TSS_E_INTERNAL_ERROR);
73 goto done;
74 }
75
76 *sig = (BYTE *) malloc(*sigSize);
77 if (*sig == NULL) {
78 LogError("malloc of %u bytes failed.", *sigSize);
79 result = TSPERR(TSS_E_OUTOFMEMORY);
80 goto done;
81 }
82 if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *sig, *sigSize, &hte->comm)) {
83 result = free_tspi(hte->tspContext, *sig);
84 if (result == TSS_SUCCESS)
85 result = TSPERR(TSS_E_INTERNAL_ERROR);
86 else
87 free(*sig);
88 }
89 }
90
91 done:
92 return result;
93 }
94