1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
/*
* Licensed Materials - Property of IBM
*
* trousers - An open source TCG Software Stack
*
* (C) Copyright International Business Machines Corp. 2004
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include "trousers/tss.h"
#include "trousers_types.h"
#include "tcs_tsp.h"
#include "tcsps.h"
#include "tcs_utils.h"
#include "tcs_int_literals.h"
#include "capabilities.h"
#include "tcslog.h"
#include "tcsd_wrap.h"
#include "tcsd.h"
extern struct tcsd_config tcsd_options;
TSS_RESULT
internal_TCSGetCap(TCS_CONTEXT_HANDLE hContext,
TCPA_CAPABILITY_AREA capArea,
UINT32 subCap,
UINT32 * respSize, BYTE ** resp)
{
UINT32 u32value = 0;
UINT64 offset;
TPM_VERSION tcsVersion = INTERNAL_CAP_VERSION;
struct tcsd_config *config = &tcsd_options;
struct platform_class *platClass;
TSS_BOOL bValue = FALSE;
LogDebug("Checking Software Cap of TCS");
switch (capArea) {
case TSS_TCSCAP_ALG:
LogDebug("TSS_TCSCAP_ALG");
switch (subCap) {
case TSS_ALG_RSA:
*respSize = sizeof(TSS_BOOL);
bValue = INTERNAL_CAP_TCS_ALG_RSA;
break;
case TSS_ALG_DES:
*respSize = sizeof(TSS_BOOL);
bValue = INTERNAL_CAP_TCS_ALG_DES;
break;
case TSS_ALG_3DES:
*respSize = sizeof(TSS_BOOL);
bValue = INTERNAL_CAP_TCS_ALG_3DES;
break;
case TSS_ALG_SHA:
*respSize = sizeof(TSS_BOOL);
bValue = INTERNAL_CAP_TCS_ALG_SHA;
break;
case TSS_ALG_AES:
*respSize = sizeof(TSS_BOOL);
bValue = INTERNAL_CAP_TCS_ALG_AES;
break;
case TSS_ALG_HMAC:
*respSize = sizeof(TSS_BOOL);
bValue = INTERNAL_CAP_TCS_ALG_HMAC;
break;
case TSS_ALG_DEFAULT:
*respSize = sizeof(UINT32);
u32value = INTERNAL_CAP_TCS_ALG_DEFAULT;
break;
case TSS_ALG_DEFAULT_SIZE:
*respSize = sizeof(UINT32);
u32value = INTERNAL_CAP_TCS_ALG_DEFAULT_SIZE;
break;
default:
*respSize = 0;
LogDebugFn("Bad subcap");
return TCSERR(TSS_E_BAD_PARAMETER);
}
if ((*resp = malloc(*respSize)) == NULL) {
LogError("malloc of %u bytes failed.", *respSize);
*respSize = 0;
return TCSERR(TSS_E_OUTOFMEMORY);
}
offset = 0;
if (*respSize == sizeof(TSS_BOOL))
*(TSS_BOOL *)(*resp) = bValue;
else
*(UINT32 *)(*resp) = u32value;
break;
case TSS_TCSCAP_VERSION:
LogDebug("TSS_TCSCAP_VERSION");
if ((*resp = calloc(1, sizeof(TSS_VERSION))) == NULL) {
LogError("malloc of %zd bytes failed.", sizeof(TSS_VERSION));
return TCSERR(TSS_E_OUTOFMEMORY);
}
offset = 0;
LoadBlob_VERSION(&offset, *resp, &tcsVersion);
*respSize = sizeof(TSS_VERSION);
break;
case TSS_TCSCAP_PERSSTORAGE:
LogDebug("TSS_TCSCAP_PERSSTORAGE");
if ((*resp = malloc(sizeof(TSS_BOOL))) == NULL) {
LogError("malloc of %zd byte failed.", sizeof(TSS_BOOL));
return TCSERR(TSS_E_OUTOFMEMORY);
}
*(TSS_BOOL *)(*resp) = INTERNAL_CAP_TCS_PERSSTORAGE;
*respSize = sizeof(TSS_BOOL);
break;
case TSS_TCSCAP_CACHING:
LogDebug("TSS_TCSCAP_CACHING");
if (subCap == TSS_TCSCAP_PROP_KEYCACHE)
bValue = INTERNAL_CAP_TCS_CACHING_KEYCACHE;
else if (subCap == TSS_TCSCAP_PROP_AUTHCACHE)
bValue = INTERNAL_CAP_TCS_CACHING_AUTHCACHE;
else {
LogDebugFn("Bad subcap");
return TCSERR(TSS_E_BAD_PARAMETER);
}
if ((*resp = malloc(sizeof(TSS_BOOL))) == NULL) {
LogError("malloc of %zd byte failed.", sizeof(TSS_BOOL));
return TCSERR(TSS_E_OUTOFMEMORY);
}
*respSize = sizeof(TSS_BOOL);
*(TSS_BOOL *)(*resp) = bValue;
break;
case TSS_TCSCAP_MANUFACTURER:
if (subCap == TSS_TCSCAP_PROP_MANUFACTURER_ID) {
if ((*resp = malloc(sizeof(UINT32))) == NULL) {
LogError("malloc of %zd byte failed.", sizeof(UINT32));
return TCSERR(TSS_E_OUTOFMEMORY);
}
*(UINT32 *)(*resp) = INTERNAL_CAP_MANUFACTURER_ID;
*respSize = sizeof(UINT32);
} else if (subCap == TSS_TCSCAP_PROP_MANUFACTURER_STR) {
BYTE str[] = INTERNAL_CAP_MANUFACTURER_STR;
if ((*resp = malloc(INTERNAL_CAP_MANUFACTURER_STR_LEN)) == NULL) {
LogError("malloc of %d bytes failed.",
INTERNAL_CAP_MANUFACTURER_STR_LEN);
return TCSERR(TSS_E_OUTOFMEMORY);
}
memcpy(*resp, str, INTERNAL_CAP_MANUFACTURER_STR_LEN);
*respSize = INTERNAL_CAP_MANUFACTURER_STR_LEN;
} else {
LogDebugFn("Bad subcap");
return TCSERR(TSS_E_BAD_PARAMETER);
}
break;
case TSS_TCSCAP_TRANSPORT:
/* A zero value here means the TSP is asking whether we support transport sessions
* at all */
if (subCap == TSS_TCSCAP_TRANS_EXCLUSIVE || subCap == 0) {
*respSize = sizeof(TSS_BOOL);
if ((*resp = malloc(sizeof(TSS_BOOL))) == NULL) {
LogError("malloc of %zd byte failed.", sizeof(TSS_BOOL));
return TCSERR(TSS_E_OUTOFMEMORY);
}
if (subCap == TSS_TCSCAP_TRANS_EXCLUSIVE)
*(TSS_BOOL *)(*resp) = config->exclusive_transport ? TRUE : FALSE;
else
*(TSS_BOOL *)(*resp) = TRUE;
} else {
LogDebugFn("Bad subcap");
return TCSERR(TSS_E_BAD_PARAMETER);
}
break;
case TSS_TCSCAP_PLATFORM_CLASS:
LogDebug("TSS_TCSCAP_PLATFORM_CLASS");
switch (subCap) {
case TSS_TCSCAP_PROP_HOST_PLATFORM:
/* Return the TSS_PLATFORM_CLASS */
LogDebugFn("TSS_TCSCAP_PROP_HOST_PLATFORM");
platClass = config->host_platform_class;
/* Computes the size of host platform structure */
*respSize = (2 * sizeof(UINT32)) + platClass->classURISize;
*resp = malloc(*respSize);
if (*resp == NULL) {
LogError("malloc of %u bytes failed.", *respSize);
return TCSERR(TSS_E_OUTOFMEMORY);
}
memset(*resp, 0, *respSize);
offset = 0;
LoadBlob_UINT32(&offset, platClass->simpleID, *resp);
LoadBlob_UINT32(&offset, platClass->classURISize, *resp);
memcpy(&(*resp)[offset], platClass->classURI, platClass->classURISize);
LogBlob(*respSize, *resp);
break;
case TSS_TCSCAP_PROP_ALL_PLATFORMS:
/* Return an array of TSS_PLATFORM_CLASSes, when existent */
LogDebugFn("TSS_TCSCAP_PROP_ALL_PLATFORMS");
*respSize = 0;
*resp = NULL;
if ((platClass = config->all_platform_classes) != NULL) {
/* Computes the size of all Platform Structures */
while (platClass != NULL) {
*respSize += (2 * sizeof(UINT32)) + platClass->classURISize;
platClass = platClass->next;
}
*resp = malloc(*respSize);
if (*resp == NULL) {
LogError("malloc of %u bytes failed.", *respSize);
return TCSERR(TSS_E_OUTOFMEMORY);
}
memset(*resp, 0, *respSize);
offset = 0;
/* Concatenates all the structures on the BYTE * resp */
platClass = config->all_platform_classes;
while (platClass != NULL){
LoadBlob_UINT32(&offset, platClass->simpleID, *resp);
LoadBlob_UINT32(&offset, platClass->classURISize, *resp);
memcpy(&(*resp)[offset], platClass->classURI,
platClass->classURISize);
offset += platClass->classURISize;
platClass = platClass->next;
}
LogBlob(*respSize, *resp);
}
break;
default:
LogDebugFn("Bad subcap");
return TCSERR(TSS_E_BAD_PARAMETER);
}
break;
default:
LogDebugFn("Bad cap area");
return TCSERR(TSS_E_BAD_PARAMETER);
}
return TSS_SUCCESS;
}
TSS_RESULT
TCS_GetCapability_Internal(TCS_CONTEXT_HANDLE hContext, /* in */
TCPA_CAPABILITY_AREA capArea, /* in */
UINT32 subCapSize, /* in */
BYTE * subCap, /* in */
UINT32 * respSize, /* out */
BYTE ** resp /* out */
)
{
TSS_RESULT result;
UINT32 ulSubCap;
if ((result = ctx_verify_context(hContext)))
return result;
if (subCapSize == sizeof(UINT32))
ulSubCap = *(UINT32 *)subCap;
else if (subCapSize == 0)
ulSubCap = 0;
else
return TCSERR(TSS_E_BAD_PARAMETER);
return internal_TCSGetCap(hContext, capArea, ulSubCap, respSize, resp);
}
|