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_CreateMaintenanceArchive_TP(struct host_table_entry * hte,TSS_BOOL generateRandom,TPM_AUTH * ownerAuth,UINT32 * randomSize,BYTE ** random,UINT32 * archiveSize,BYTE ** archive)29 RPC_CreateMaintenanceArchive_TP(struct host_table_entry *hte,
30 TSS_BOOL generateRandom, /* in */
31 TPM_AUTH * ownerAuth, /* in, out */
32 UINT32 * randomSize, /* out */
33 BYTE ** random, /* out */
34 UINT32 * archiveSize, /* out */
35 BYTE ** archive /* out */
36 ) {
37 TSS_RESULT result;
38
39 initData(&hte->comm, 3);
40 hte->comm.hdr.u.ordinal = TCSD_ORD_CREATEMAINTENANCEARCHIVE;
41 LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
42
43 if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
44 return TSPERR(TSS_E_INTERNAL_ERROR);
45 if (setData(TCSD_PACKET_TYPE_BOOL, 1, &generateRandom, 0, &hte->comm))
46 return TSPERR(TSS_E_INTERNAL_ERROR);
47 if (setData(TCSD_PACKET_TYPE_AUTH, 2, ownerAuth, 0, &hte->comm))
48 return TSPERR(TSS_E_INTERNAL_ERROR);
49
50 result = sendTCSDPacket(hte);
51
52 if (result == TSS_SUCCESS)
53 result = hte->comm.hdr.u.result;
54
55 if (result == TSS_SUCCESS) {
56 if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm))
57 result = TSPERR(TSS_E_INTERNAL_ERROR);
58 if (getData(TCSD_PACKET_TYPE_UINT32, 1, randomSize, 0, &hte->comm))
59 result = TSPERR(TSS_E_INTERNAL_ERROR);
60
61 if (*randomSize > 0) {
62 *random = malloc(*randomSize);
63 if (*random == NULL) {
64 LogError("malloc of %u bytes failed.", *randomSize);
65 result = TSPERR(TSS_E_OUTOFMEMORY);
66 goto done;
67 }
68
69 if (getData(TCSD_PACKET_TYPE_PBYTE, 2, *random, *randomSize, &hte->comm)) {
70 free(*random);
71 result = TSPERR(TSS_E_INTERNAL_ERROR);
72 goto done;
73 }
74 } else {
75 *random = NULL;
76 }
77
78 /* Assume all elements are in the list, even when *randomSize == 0. */
79 if (getData(TCSD_PACKET_TYPE_UINT32, 3, archiveSize, 0, &hte->comm))
80 result = TSPERR(TSS_E_INTERNAL_ERROR);
81
82 if (*archiveSize > 0) {
83 *archive = malloc(*archiveSize);
84 if (*archive == NULL) {
85 free(*random);
86 LogError("malloc of %u bytes failed.", *archiveSize);
87 result = TSPERR(TSS_E_OUTOFMEMORY);
88 goto done;
89 }
90
91 if (getData(TCSD_PACKET_TYPE_PBYTE, 4, *archive, *archiveSize, &hte->comm)) {
92 free(*random);
93 free(*archive);
94 result = TSPERR(TSS_E_INTERNAL_ERROR);
95 goto done;
96 }
97 } else {
98 *archive = NULL;
99 }
100 }
101 done:
102 return result;
103 }
104
105 TSS_RESULT
RPC_LoadMaintenanceArchive_TP(struct host_table_entry * hte,UINT32 dataInSize,BYTE * dataIn,TPM_AUTH * ownerAuth,UINT32 * dataOutSize,BYTE ** dataOut)106 RPC_LoadMaintenanceArchive_TP(struct host_table_entry *hte,
107 UINT32 dataInSize, /* in */
108 BYTE * dataIn, /* in */
109 TPM_AUTH * ownerAuth, /* in, out */
110 UINT32 * dataOutSize, /* out */
111 BYTE ** dataOut /* out */
112 ) {
113 TSS_RESULT result;
114
115 initData(&hte->comm, 4);
116 hte->comm.hdr.u.ordinal = TCSD_ORD_LOADMAINTENANCEARCHIVE;
117 LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
118
119 if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
120 return TSPERR(TSS_E_INTERNAL_ERROR);
121 if (setData(TCSD_PACKET_TYPE_UINT32, 1, &dataInSize, 0, &hte->comm))
122 return TSPERR(TSS_E_INTERNAL_ERROR);
123 if (setData(TCSD_PACKET_TYPE_PBYTE, 2, &dataIn, dataInSize, &hte->comm))
124 return TSPERR(TSS_E_INTERNAL_ERROR);
125 if (setData(TCSD_PACKET_TYPE_AUTH, 3, ownerAuth, 0, &hte->comm))
126 return TSPERR(TSS_E_INTERNAL_ERROR);
127
128 result = sendTCSDPacket(hte);
129
130 if (result == TSS_SUCCESS)
131 result = hte->comm.hdr.u.result;
132
133 if (result == TSS_SUCCESS) {
134 if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm))
135 result = TSPERR(TSS_E_INTERNAL_ERROR);
136 if (getData(TCSD_PACKET_TYPE_UINT32, 1, dataOutSize, 0, &hte->comm))
137 result = TSPERR(TSS_E_INTERNAL_ERROR);
138
139 if (*dataOutSize > 0) {
140 *dataOut = malloc(*dataOutSize);
141 if (*dataOut == NULL) {
142 LogError("malloc of %u bytes failed.", *dataOutSize);
143 result = TSPERR(TSS_E_OUTOFMEMORY);
144 goto done;
145 }
146
147 if (getData(TCSD_PACKET_TYPE_PBYTE, 2, *dataOut, *dataOutSize, &hte->comm)) {
148 free(*dataOut);
149 result = TSPERR(TSS_E_INTERNAL_ERROR);
150 goto done;
151 }
152 } else {
153 *dataOut = NULL;
154 }
155 }
156 done:
157 return result;
158 }
159
160 TSS_RESULT
RPC_KillMaintenanceFeature_TP(struct host_table_entry * hte,TPM_AUTH * ownerAuth)161 RPC_KillMaintenanceFeature_TP(struct host_table_entry *hte,
162 TPM_AUTH * ownerAuth /* in , out */
163 ) {
164 TSS_RESULT result;
165
166 initData(&hte->comm, 2);
167 hte->comm.hdr.u.ordinal = TCSD_ORD_KILLMAINTENANCEFEATURE;
168 LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
169
170 if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
171 return TSPERR(TSS_E_INTERNAL_ERROR);
172 if (setData(TCSD_PACKET_TYPE_AUTH, 1, ownerAuth, 0, &hte->comm))
173 return TSPERR(TSS_E_INTERNAL_ERROR);
174
175 result = sendTCSDPacket(hte);
176
177 if (result == TSS_SUCCESS)
178 result = hte->comm.hdr.u.result;
179
180 if (result == TSS_SUCCESS) {
181 if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm))
182 result = TSPERR(TSS_E_INTERNAL_ERROR);
183 }
184
185 return result;
186 }
187
188 TSS_RESULT
RPC_LoadManuMaintPub_TP(struct host_table_entry * hte,TCPA_NONCE antiReplay,UINT32 PubKeySize,BYTE * PubKey,TCPA_DIGEST * checksum)189 RPC_LoadManuMaintPub_TP(struct host_table_entry *hte,
190 TCPA_NONCE antiReplay, /* in */
191 UINT32 PubKeySize, /* in */
192 BYTE * PubKey, /* in */
193 TCPA_DIGEST * checksum /* out */
194 ) {
195 TSS_RESULT result;
196
197 initData(&hte->comm, 4);
198 hte->comm.hdr.u.ordinal = TCSD_ORD_LOADMANUFACTURERMAINTENANCEPUB;
199 LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
200
201 if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
202 return TSPERR(TSS_E_INTERNAL_ERROR);
203 if (setData(TCSD_PACKET_TYPE_NONCE, 1, &antiReplay, 0, &hte->comm))
204 return TSPERR(TSS_E_INTERNAL_ERROR);
205 if (setData(TCSD_PACKET_TYPE_UINT32, 2, &PubKeySize, 0, &hte->comm))
206 return TSPERR(TSS_E_INTERNAL_ERROR);
207 if (setData(TCSD_PACKET_TYPE_PBYTE, 3, PubKey, PubKeySize, &hte->comm))
208 return TSPERR(TSS_E_INTERNAL_ERROR);
209
210 result = sendTCSDPacket(hte);
211
212 if (result == TSS_SUCCESS)
213 result = hte->comm.hdr.u.result;
214
215 if (result == TSS_SUCCESS) {
216 if (getData(TCSD_PACKET_TYPE_DIGEST, 0, checksum, 0, &hte->comm))
217 result = TSPERR(TSS_E_INTERNAL_ERROR);
218 }
219
220 return result;
221 }
222
223 TSS_RESULT
RPC_ReadManuMaintPub_TP(struct host_table_entry * hte,TCPA_NONCE antiReplay,TCPA_DIGEST * checksum)224 RPC_ReadManuMaintPub_TP(struct host_table_entry *hte,
225 TCPA_NONCE antiReplay, /* in */
226 TCPA_DIGEST * checksum /* out */
227 ) {
228 TSS_RESULT result;
229
230 initData(&hte->comm, 2);
231 hte->comm.hdr.u.ordinal = TCSD_ORD_READMANUFACTURERMAINTENANCEPUB;
232 LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
233
234 if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
235 return TSPERR(TSS_E_INTERNAL_ERROR);
236 if (setData(TCSD_PACKET_TYPE_NONCE, 1, &antiReplay, 0, &hte->comm))
237 return TSPERR(TSS_E_INTERNAL_ERROR);
238
239 result = sendTCSDPacket(hte);
240
241 if (result == TSS_SUCCESS)
242 result = hte->comm.hdr.u.result;
243
244 if (result == TSS_SUCCESS) {
245 if (getData(TCSD_PACKET_TYPE_DIGEST, 0, checksum, 0, &hte->comm))
246 result = TSPERR(TSS_E_INTERNAL_ERROR);
247 }
248
249 return result;
250 }
251