xref: /netbsd-src/crypto/external/cpl/trousers/dist/src/tspi/rpc/tcstp/rpc_changeauth.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_ChangeAuth_TP(struct host_table_entry * hte,TCS_KEY_HANDLE parentHandle,TCPA_PROTOCOL_ID protocolID,TCPA_ENCAUTH * newAuth,TCPA_ENTITY_TYPE entityType,UINT32 encDataSize,BYTE * encData,TPM_AUTH * ownerAuth,TPM_AUTH * entityAuth,UINT32 * outDataSize,BYTE ** outData)29 RPC_ChangeAuth_TP(struct host_table_entry *hte,
30 			       TCS_KEY_HANDLE parentHandle,	/* in */
31 			       TCPA_PROTOCOL_ID protocolID,	/* in */
32 			       TCPA_ENCAUTH *newAuth,	/* in */
33 			       TCPA_ENTITY_TYPE entityType,	/* in */
34 			       UINT32 encDataSize,	/* in */
35 			       BYTE * encData,	/* in */
36 			       TPM_AUTH * ownerAuth,	/* in, out */
37 			       TPM_AUTH * entityAuth,	/* in, out */
38 			       UINT32 * outDataSize,	/* out */
39 			       BYTE ** outData)	/* out */
40 {
41 	TSS_RESULT result;
42 
43 	initData(&hte->comm, 9);
44 	hte->comm.hdr.u.ordinal = TCSD_ORD_CHANGEAUTH;
45 	LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
46 
47 	if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
48 		return TSPERR(TSS_E_INTERNAL_ERROR);
49 	if (setData(TCSD_PACKET_TYPE_UINT32, 1, &parentHandle, 0, &hte->comm))
50 		return TSPERR(TSS_E_INTERNAL_ERROR);
51 	if (setData(TCSD_PACKET_TYPE_UINT16, 2, &protocolID, 0, &hte->comm))
52 		return TSPERR(TSS_E_INTERNAL_ERROR);
53 	if (setData(TCSD_PACKET_TYPE_ENCAUTH, 3, newAuth, 0, &hte->comm))
54 		return TSPERR(TSS_E_INTERNAL_ERROR);
55 	if (setData(TCSD_PACKET_TYPE_UINT16, 4, &entityType, 0, &hte->comm))
56 		return TSPERR(TSS_E_INTERNAL_ERROR);
57 	if (setData(TCSD_PACKET_TYPE_UINT32, 5, &encDataSize, 0, &hte->comm))
58 		return TSPERR(TSS_E_INTERNAL_ERROR);
59 	if (setData(TCSD_PACKET_TYPE_PBYTE, 6, encData, encDataSize, &hte->comm))
60 		return TSPERR(TSS_E_INTERNAL_ERROR);
61 	if (setData(TCSD_PACKET_TYPE_AUTH, 7, ownerAuth, 0, &hte->comm))
62 		return TSPERR(TSS_E_INTERNAL_ERROR);
63 	if (setData(TCSD_PACKET_TYPE_AUTH, 8, entityAuth, 0, &hte->comm))
64 		return TSPERR(TSS_E_INTERNAL_ERROR);
65 
66 	result = sendTCSDPacket(hte);
67 
68 	if (result == TSS_SUCCESS)
69 		result = hte->comm.hdr.u.result;
70 
71 	if (result == TSS_SUCCESS) {
72 		if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm)) {
73 			result = TSPERR(TSS_E_INTERNAL_ERROR);
74 			goto done;
75 		}
76 		if (getData(TCSD_PACKET_TYPE_AUTH, 1, entityAuth, 0, &hte->comm)) {
77 			result = TSPERR(TSS_E_INTERNAL_ERROR);
78 			goto done;
79 		}
80 		if (getData(TCSD_PACKET_TYPE_UINT32, 2, outDataSize, 0, &hte->comm)) {
81 			result = TSPERR(TSS_E_INTERNAL_ERROR);
82 			goto done;
83 		}
84 
85 		*outData = (BYTE *) malloc(*outDataSize);
86 		if (*outData == NULL) {
87 			LogError("malloc of %u bytes failed.", *outDataSize);
88 			result = TSPERR(TSS_E_OUTOFMEMORY);
89 			goto done;
90 		}
91 		if (getData(TCSD_PACKET_TYPE_PBYTE, 3, *outData, *outDataSize, &hte->comm)) {
92 			free(*outData);
93 			result = TSPERR(TSS_E_INTERNAL_ERROR);
94 		}
95 	}
96 
97 done:
98 	return result;
99 }
100 
101 TSS_RESULT
RPC_ChangeAuthOwner_TP(struct host_table_entry * hte,TCPA_PROTOCOL_ID protocolID,TCPA_ENCAUTH * newAuth,TCPA_ENTITY_TYPE entityType,TPM_AUTH * ownerAuth)102 RPC_ChangeAuthOwner_TP(struct host_table_entry *hte,
103 				    TCPA_PROTOCOL_ID protocolID,	/* in */
104 				    TCPA_ENCAUTH *newAuth,	/* in */
105 				    TCPA_ENTITY_TYPE entityType,	/* in */
106 				    TPM_AUTH * ownerAuth	/* in, out */
107     ) {
108 	TSS_RESULT result;
109 
110 	initData(&hte->comm, 5);
111 	hte->comm.hdr.u.ordinal = TCSD_ORD_CHANGEAUTHOWNER;
112 	LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
113 
114 	if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
115 		return TSPERR(TSS_E_INTERNAL_ERROR);
116 	if (setData(TCSD_PACKET_TYPE_UINT16, 1, &protocolID, 0, &hte->comm))
117 		return TSPERR(TSS_E_INTERNAL_ERROR);
118 	if (setData(TCSD_PACKET_TYPE_ENCAUTH, 2, newAuth, 0, &hte->comm))
119 		return TSPERR(TSS_E_INTERNAL_ERROR);
120 	if (setData(TCSD_PACKET_TYPE_UINT16, 3, &entityType, 0, &hte->comm))
121 		return TSPERR(TSS_E_INTERNAL_ERROR);
122 	if (setData(TCSD_PACKET_TYPE_AUTH, 4, ownerAuth, 0, &hte->comm))
123 		return TSPERR(TSS_E_INTERNAL_ERROR);
124 
125 	result = sendTCSDPacket(hte);
126 
127 	if (result == TSS_SUCCESS)
128 		result = hte->comm.hdr.u.result;
129 
130 	if (hte->comm.hdr.u.result == TSS_SUCCESS) {
131 		if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm))
132 			result = TSPERR(TSS_E_INTERNAL_ERROR);
133 	}
134 
135 	return result;
136 }
137 
138 TSS_RESULT
RPC_ChangeAuthAsymStart_TP(struct host_table_entry * hte,TCS_KEY_HANDLE idHandle,TCPA_NONCE antiReplay,UINT32 KeySizeIn,BYTE * KeyDataIn,TPM_AUTH * pAuth,UINT32 * KeySizeOut,BYTE ** KeyDataOut,UINT32 * CertifyInfoSize,BYTE ** CertifyInfo,UINT32 * sigSize,BYTE ** sig,TCS_KEY_HANDLE * ephHandle)139 RPC_ChangeAuthAsymStart_TP(struct host_table_entry *hte,
140 					TCS_KEY_HANDLE idHandle,	/* in */
141 					TCPA_NONCE antiReplay,	/* in */
142 					UINT32 KeySizeIn,	/* in */
143 					BYTE * KeyDataIn,	/* in */
144 					TPM_AUTH * pAuth,	/* in, out */
145 					UINT32 * KeySizeOut,	/* out */
146 					BYTE ** KeyDataOut,	/* out */
147 					UINT32 * CertifyInfoSize,	/* out */
148 					BYTE ** CertifyInfo,	/* out */
149 					UINT32 * sigSize,	/* out */
150 					BYTE ** sig,	/* out */
151 					TCS_KEY_HANDLE * ephHandle	/* out */
152     ) {
153 	return TSPERR(TSS_E_NOTIMPL);
154 }
155 
156 TSS_RESULT
RPC_ChangeAuthAsymFinish_TP(struct host_table_entry * hte,TCS_KEY_HANDLE parentHandle,TCS_KEY_HANDLE ephHandle,TCPA_ENTITY_TYPE entityType,TCPA_HMAC newAuthLink,UINT32 newAuthSize,BYTE * encNewAuth,UINT32 encDataSizeIn,BYTE * encDataIn,TPM_AUTH * ownerAuth,UINT32 * encDataSizeOut,BYTE ** encDataOut,TCPA_SALT_NONCE * saltNonce,TCPA_DIGEST * changeProof)157 RPC_ChangeAuthAsymFinish_TP(struct host_table_entry *hte,
158 					 TCS_KEY_HANDLE parentHandle,	/* in */
159 					 TCS_KEY_HANDLE ephHandle,	/* in */
160 					 TCPA_ENTITY_TYPE entityType,	/* in */
161 					 TCPA_HMAC newAuthLink,	/* in */
162 					 UINT32 newAuthSize,	/* in */
163 					 BYTE * encNewAuth,	/* in */
164 					 UINT32 encDataSizeIn,	/* in */
165 					 BYTE * encDataIn,	/* in */
166 					 TPM_AUTH * ownerAuth,	/* in, out */
167 					 UINT32 * encDataSizeOut,	/* out */
168 					 BYTE ** encDataOut,	/* out */
169 					 TCPA_SALT_NONCE * saltNonce,	/* out */
170 					 TCPA_DIGEST * changeProof	/* out */
171     ) {
172 	return TSPERR(TSS_E_NOTIMPL);
173 }
174