xref: /netbsd-src/crypto/external/cpl/trousers/dist/src/tspi/rpc/tcstp/rpc_caps_tpm.c (revision 2d5f7628c5531eb583b9313ac2fd1cf8582b4479)
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_GetTPMCapability_TP(struct host_table_entry * hte,TCPA_CAPABILITY_AREA capArea,UINT32 subCapSize,BYTE * subCap,UINT32 * respSize,BYTE ** resp)29 RPC_GetTPMCapability_TP(struct host_table_entry *hte,
30 		      TCPA_CAPABILITY_AREA capArea,	/* in */
31 		      UINT32 subCapSize,		/* in */
32 		      BYTE * subCap,			/* in */
33 		      UINT32 * respSize,		/* out */
34 		      BYTE ** resp)			/* out */
35 {
36 	TSS_RESULT result;
37 
38 	initData(&hte->comm, 4);
39 	hte->comm.hdr.u.ordinal = TCSD_ORD_GETCAPABILITY;
40 	LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
41 
42 	if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
43 		return TSPERR(TSS_E_INTERNAL_ERROR);
44 	if (setData(TCSD_PACKET_TYPE_UINT32, 1, &capArea, 0, &hte->comm))
45 		return TSPERR(TSS_E_INTERNAL_ERROR);
46 	if (setData(TCSD_PACKET_TYPE_UINT32, 2, &subCapSize, 0, &hte->comm))
47 		return TSPERR(TSS_E_INTERNAL_ERROR);
48 	if (setData(TCSD_PACKET_TYPE_PBYTE, 3, subCap, subCapSize, &hte->comm))
49 		return TSPERR(TSS_E_INTERNAL_ERROR);
50 
51 	result = sendTCSDPacket(hte);
52 
53 	if (result == TSS_SUCCESS)
54 		result = hte->comm.hdr.u.result;
55 
56 	if (result == TSS_SUCCESS) {
57 		if (getData(TCSD_PACKET_TYPE_UINT32, 0, respSize, 0, &hte->comm)) {
58 			result = TSPERR(TSS_E_INTERNAL_ERROR);
59 			goto done;
60 		}
61 
62 		*resp = (BYTE *) malloc(*respSize);
63 		if (*resp == NULL) {
64 			LogError("malloc of %u bytes failed.", *respSize);
65 			result = TSPERR(TSS_E_OUTOFMEMORY);
66 			goto done;
67 		}
68 		if (getData(TCSD_PACKET_TYPE_PBYTE, 1, *resp, *respSize, &hte->comm)) {
69 			free(*resp);
70 			result = TSPERR(TSS_E_INTERNAL_ERROR);
71 		}
72 	}
73 
74 done:
75 	return result;
76 }
77 
78 TSS_RESULT
RPC_GetCapabilitySigned_TP(struct host_table_entry * hte,TCS_KEY_HANDLE keyHandle,TCPA_NONCE antiReplay,TCPA_CAPABILITY_AREA capArea,UINT32 subCapSize,BYTE * subCap,TPM_AUTH * privAuth,TCPA_VERSION * Version,UINT32 * respSize,BYTE ** resp,UINT32 * sigSize,BYTE ** sig)79 RPC_GetCapabilitySigned_TP(struct host_table_entry *hte,
80 					TCS_KEY_HANDLE keyHandle,	/* in */
81 					TCPA_NONCE antiReplay,	/* in */
82 					TCPA_CAPABILITY_AREA capArea,	/* in */
83 					UINT32 subCapSize,	/* in */
84 					BYTE * subCap,	/* in */
85 					TPM_AUTH * privAuth,	/* in, out */
86 					TCPA_VERSION * Version,	/* out */
87 					UINT32 * respSize,	/* out */
88 					BYTE ** resp,	/* out */
89 					UINT32 * sigSize,	/* out */
90 					BYTE ** sig)	/* out */
91 {
92 	return TSPERR(TSS_E_NOTIMPL);
93 }
94 
95 TSS_RESULT
RPC_GetCapabilityOwner_TP(struct host_table_entry * hte,TPM_AUTH * pOwnerAuth,TCPA_VERSION * pVersion,UINT32 * pNonVolatileFlags,UINT32 * pVolatileFlags)96 RPC_GetCapabilityOwner_TP(struct host_table_entry *hte,
97 				       TPM_AUTH * pOwnerAuth,	/* out */
98 				       TCPA_VERSION * pVersion,	/* out */
99 				       UINT32 * pNonVolatileFlags,	/* out */
100 				       UINT32 * pVolatileFlags)	/* out */
101 {
102 	TSS_RESULT result;
103 
104 	initData(&hte->comm, 2);
105 	hte->comm.hdr.u.ordinal = TCSD_ORD_GETCAPABILITYOWNER;
106 	LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
107 
108 	if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
109 		return TSPERR(TSS_E_INTERNAL_ERROR);
110 	if (setData(TCSD_PACKET_TYPE_AUTH, 1, pOwnerAuth, 0, &hte->comm))
111 		return TSPERR(TSS_E_INTERNAL_ERROR);
112 
113 	result = sendTCSDPacket(hte);
114 
115 	if (result == TSS_SUCCESS)
116 		result = hte->comm.hdr.u.result;
117 
118 	if (result == TSS_SUCCESS) {
119 		if (getData(TCSD_PACKET_TYPE_VERSION, 0, pVersion, 0, &hte->comm))
120 			result = TSPERR(TSS_E_INTERNAL_ERROR);
121 		if (getData(TCSD_PACKET_TYPE_UINT32, 1, pNonVolatileFlags, 0, &hte->comm))
122 			result = TSPERR(TSS_E_INTERNAL_ERROR);
123 		if (getData(TCSD_PACKET_TYPE_UINT32, 2, pVolatileFlags, 0, &hte->comm))
124 			result = TSPERR(TSS_E_INTERNAL_ERROR);
125 		if (getData(TCSD_PACKET_TYPE_AUTH, 3, pOwnerAuth, 0, &hte->comm))
126 			result = TSPERR(TSS_E_INTERNAL_ERROR);
127 	}
128 
129 	return result;
130 }
131 
132 TSS_RESULT
RPC_SetCapability_TP(struct host_table_entry * hte,TCPA_CAPABILITY_AREA capArea,UINT32 subCapSize,BYTE * subCap,UINT32 valueSize,BYTE * value,TPM_AUTH * pOwnerAuth)133 RPC_SetCapability_TP(struct host_table_entry *hte,
134 		      TCPA_CAPABILITY_AREA capArea,	/* in */
135 		      UINT32 subCapSize,	/* in */
136 		      BYTE * subCap,	/* in */
137 		      UINT32 valueSize,	/* in */
138 		      BYTE * value,	/* in */
139 		      TPM_AUTH * pOwnerAuth)	/* in, out */
140 {
141 	TSS_RESULT result;
142 
143 	initData(&hte->comm, 7);
144 	hte->comm.hdr.u.ordinal = TCSD_ORD_SETCAPABILITY;
145 	LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
146 
147 	if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
148 		return TSPERR(TSS_E_INTERNAL_ERROR);
149 	if (setData(TCSD_PACKET_TYPE_UINT32, 1, &capArea, 0, &hte->comm))
150 		return TSPERR(TSS_E_INTERNAL_ERROR);
151 	if (setData(TCSD_PACKET_TYPE_UINT32, 2, &subCapSize, 0, &hte->comm))
152 		return TSPERR(TSS_E_INTERNAL_ERROR);
153 	if (setData(TCSD_PACKET_TYPE_PBYTE, 3, subCap, subCapSize, &hte->comm))
154 		return TSPERR(TSS_E_INTERNAL_ERROR);
155 	if (setData(TCSD_PACKET_TYPE_UINT32, 4, &valueSize, 0, &hte->comm))
156 		return TSPERR(TSS_E_INTERNAL_ERROR);
157 	if (setData(TCSD_PACKET_TYPE_PBYTE, 5, value, valueSize, &hte->comm))
158 		return TSPERR(TSS_E_INTERNAL_ERROR);
159 	if (pOwnerAuth) {
160 		if (setData(TCSD_PACKET_TYPE_AUTH, 6, pOwnerAuth, 0, &hte->comm))
161 			return TSPERR(TSS_E_INTERNAL_ERROR);
162 	}
163 
164 	result = sendTCSDPacket(hte);
165 
166 	if (result == TSS_SUCCESS)
167 		result = hte->comm.hdr.u.result;
168 
169 	if (result == TSS_SUCCESS) {
170 		if (getData(TCSD_PACKET_TYPE_AUTH, 0, pOwnerAuth, 0, &hte->comm))
171 			result = TSPERR(TSS_E_INTERNAL_ERROR);
172 	}
173 
174 	return result;
175 }
176