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_Quote_TP(struct host_table_entry * hte,TCS_KEY_HANDLE keyHandle,TCPA_NONCE * antiReplay,UINT32 pcrDataSizeIn,BYTE * pcrDataIn,TPM_AUTH * privAuth,UINT32 * pcrDataSizeOut,BYTE ** pcrDataOut,UINT32 * sigSize,BYTE ** sig)29 RPC_Quote_TP(struct host_table_entry *hte,
30 TCS_KEY_HANDLE keyHandle, /* in */
31 TCPA_NONCE *antiReplay, /* in */
32 UINT32 pcrDataSizeIn, /* in */
33 BYTE * pcrDataIn, /* in */
34 TPM_AUTH * privAuth, /* in, out */
35 UINT32 * pcrDataSizeOut, /* out */
36 BYTE ** pcrDataOut, /* out */
37 UINT32 * sigSize, /* out */
38 BYTE ** sig) /* out */
39 {
40 TSS_RESULT result;
41 int i;
42
43 initData(&hte->comm, 6);
44
45 hte->comm.hdr.u.ordinal = TCSD_ORD_QUOTE;
46 LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
47
48 if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
49 return TSPERR(TSS_E_INTERNAL_ERROR);
50 if (setData(TCSD_PACKET_TYPE_UINT32, 1, &keyHandle, 0, &hte->comm))
51 return TSPERR(TSS_E_INTERNAL_ERROR);
52 if (setData(TCSD_PACKET_TYPE_NONCE, 2, antiReplay, 0, &hte->comm))
53 return TSPERR(TSS_E_INTERNAL_ERROR);
54 if (setData(TCSD_PACKET_TYPE_UINT32, 3, &pcrDataSizeIn, 0, &hte->comm))
55 return TSPERR(TSS_E_INTERNAL_ERROR);
56 if (setData(TCSD_PACKET_TYPE_PBYTE, 4, pcrDataIn, pcrDataSizeIn, &hte->comm))
57 return TSPERR(TSS_E_INTERNAL_ERROR);
58
59 if (privAuth) {
60 if (setData(TCSD_PACKET_TYPE_AUTH, 5, privAuth, 0, &hte->comm))
61 return TSPERR(TSS_E_INTERNAL_ERROR);
62 }
63
64 result = sendTCSDPacket(hte);
65
66 if (result == TSS_SUCCESS)
67 result = hte->comm.hdr.u.result;
68
69 if (result == TSS_SUCCESS) {
70 i = 0;
71 if (privAuth) {
72 if (getData(TCSD_PACKET_TYPE_AUTH, i++, privAuth, 0, &hte->comm)) {
73 result = TSPERR(TSS_E_INTERNAL_ERROR);
74 goto done;
75 }
76 }
77 if (getData(TCSD_PACKET_TYPE_UINT32, i++, pcrDataSizeOut, 0, &hte->comm)) {
78 result = TSPERR(TSS_E_INTERNAL_ERROR);
79 goto done;
80 }
81
82 *pcrDataOut = (BYTE *) malloc(*pcrDataSizeOut);
83 if (*pcrDataOut == NULL) {
84 LogError("malloc of %u bytes failed.", *pcrDataSizeOut);
85 result = TSPERR(TSS_E_OUTOFMEMORY);
86 goto done;
87 }
88 if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *pcrDataOut, *pcrDataSizeOut, &hte->comm)) {
89 free(*pcrDataOut);
90 result = TSPERR(TSS_E_INTERNAL_ERROR);
91 goto done;
92 }
93 if (getData(TCSD_PACKET_TYPE_UINT32, i++, sigSize, 0, &hte->comm)) {
94 free(*pcrDataOut);
95 result = TSPERR(TSS_E_INTERNAL_ERROR);
96 goto done;
97 }
98 *sig = (BYTE *) malloc(*sigSize);
99 if (*sig == NULL) {
100 LogError("malloc of %u bytes failed.", *sigSize);
101 free(*pcrDataOut);
102 result = TSPERR(TSS_E_OUTOFMEMORY);
103 goto done;
104 }
105 if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *sig, *sigSize, &hte->comm)) {
106 free(*pcrDataOut);
107 free(*sig);
108 result = TSPERR(TSS_E_INTERNAL_ERROR);
109 }
110 }
111
112 done:
113 return result;
114 }
115