~ubuntu-branches/ubuntu/karmic/trousers/karmic

« back to all changes in this revision

Viewing changes to src/tcs/rpc/tcstp/rpc_ek.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2008-01-23 22:03:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080123220300-fhtqja3c0oq0gp6z
Tags: 0.3.1-4
* Added patch from Aaron M. Ucko <ucko@debian.org> to allow trousers to
  build successfully on amd64, and presumably also other 64-bit
  architectures (Closes: #457400).
* Including udev rule for /dev/tpm from William Lima
  <wlima.amadeus@gmail.com> as suggested by David Smith <dds@google.com>
  (Closes: #459682).
* Added lintian overrides.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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-2007
 
8
 *
 
9
 */
 
10
 
 
11
#include <stdlib.h>
 
12
#include <stdio.h>
 
13
#include <syslog.h>
 
14
#include <string.h>
 
15
#include <netdb.h>
 
16
 
 
17
#include "trousers/tss.h"
 
18
#include "trousers_types.h"
 
19
#include "tcs_tsp.h"
 
20
#include "tcs_utils.h"
 
21
#include "tcs_int_literals.h"
 
22
#include "capabilities.h"
 
23
#include "tcslog.h"
 
24
#include "tcsd_wrap.h"
 
25
#include "tcsd.h"
 
26
#include "tcs_utils.h"
 
27
#include "rpc_tcstp_tcs.h"
 
28
 
 
29
 
 
30
TSS_RESULT
 
31
tcs_wrap_CreateEndorsementKeyPair(struct tcsd_thread_data *data)
 
32
{
 
33
        TCS_CONTEXT_HANDLE hContext;
 
34
        TCPA_NONCE antiReplay;
 
35
        UINT32 eKPtrSize;
 
36
        BYTE *eKPtr;
 
37
        UINT32 eKSize;
 
38
        BYTE* eK;
 
39
        TCPA_DIGEST checksum;
 
40
        TSS_RESULT result;
 
41
 
 
42
        if (getData(TCSD_PACKET_TYPE_UINT32, 0, &hContext, 0, &data->comm))
 
43
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
44
 
 
45
        LogDebugFn("thread %zd context %x", THREAD_ID, hContext);
 
46
 
 
47
        if (getData(TCSD_PACKET_TYPE_NONCE, 1, &antiReplay, 0, &data->comm))
 
48
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
49
 
 
50
        if (getData(TCSD_PACKET_TYPE_UINT32, 2, &eKPtrSize, 0, &data->comm))
 
51
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
52
 
 
53
        eKPtr = calloc(1, eKPtrSize);
 
54
        if (eKPtr == NULL) {
 
55
                LogError("malloc of %u bytes failed.", eKPtrSize);
 
56
                return TCSERR(TSS_E_OUTOFMEMORY);
 
57
        }
 
58
        if (getData(TCSD_PACKET_TYPE_PBYTE, 3, eKPtr, eKPtrSize, &data->comm)) {
 
59
                free(eKPtr);
 
60
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
61
        }
 
62
 
 
63
        MUTEX_LOCK(tcsp_lock);
 
64
 
 
65
        result = TCSP_CreateEndorsementKeyPair_Internal(hContext, antiReplay, eKPtrSize, eKPtr,
 
66
                                                        &eKSize, &eK, &checksum);
 
67
 
 
68
        MUTEX_UNLOCK(tcsp_lock);
 
69
 
 
70
        free(eKPtr);
 
71
 
 
72
        if (result == TSS_SUCCESS) {
 
73
                initData(&data->comm, 3);
 
74
                if (setData(TCSD_PACKET_TYPE_UINT32, 0, &eKSize, 0, &data->comm)) {
 
75
                        free(eK);
 
76
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
77
                }
 
78
                if (setData(TCSD_PACKET_TYPE_PBYTE, 1, eK, eKSize, &data->comm)) {
 
79
                        free(eK);
 
80
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
81
                }
 
82
                free(eK);
 
83
                if (setData(TCSD_PACKET_TYPE_DIGEST, 2, &checksum, 0, &data->comm)) {
 
84
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
85
                }
 
86
        } else
 
87
                initData(&data->comm, 0);
 
88
 
 
89
        data->comm.hdr.u.result = result;
 
90
        return TSS_SUCCESS;
 
91
}
 
92
 
 
93
TSS_RESULT
 
94
tcs_wrap_ReadPubek(struct tcsd_thread_data *data)
 
95
{
 
96
        TCS_CONTEXT_HANDLE hContext;
 
97
        TCPA_NONCE antiReplay;
 
98
        UINT32 pubEKSize;
 
99
        BYTE *pubEK;
 
100
        TCPA_DIGEST checksum;
 
101
        TSS_RESULT result;
 
102
 
 
103
        if (getData(TCSD_PACKET_TYPE_UINT32, 0, &hContext, 0, &data->comm))
 
104
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
105
 
 
106
        LogDebugFn("thread %zd context %x", THREAD_ID, hContext);
 
107
 
 
108
        if (getData(TCSD_PACKET_TYPE_NONCE, 1, &antiReplay, 0, &data->comm))
 
109
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
110
 
 
111
        MUTEX_LOCK(tcsp_lock);
 
112
 
 
113
        result = TCSP_ReadPubek_Internal(hContext, antiReplay, &pubEKSize, &pubEK, &checksum);
 
114
 
 
115
        MUTEX_UNLOCK(tcsp_lock);
 
116
 
 
117
        if (result == TSS_SUCCESS) {
 
118
                initData(&data->comm, 3);
 
119
                if (setData(TCSD_PACKET_TYPE_UINT32, 0, &pubEKSize, 0, &data->comm)) {
 
120
                        free(pubEK);
 
121
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
122
                }
 
123
                if (setData(TCSD_PACKET_TYPE_PBYTE, 1, pubEK, pubEKSize, &data->comm)) {
 
124
                        free(pubEK);
 
125
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
126
                }
 
127
                free(pubEK);
 
128
                if (setData(TCSD_PACKET_TYPE_DIGEST, 2, &checksum, 0, &data->comm)) {
 
129
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
130
                }
 
131
        } else
 
132
                initData(&data->comm, 0);
 
133
 
 
134
        data->comm.hdr.u.result = result;
 
135
        return TSS_SUCCESS;
 
136
}
 
137
 
 
138
TSS_RESULT
 
139
tcs_wrap_OwnerReadPubek(struct tcsd_thread_data *data)
 
140
{
 
141
        TCS_CONTEXT_HANDLE hContext;
 
142
        UINT32 pubEKSize;
 
143
        BYTE *pubEK;
 
144
        TSS_RESULT result;
 
145
        TPM_AUTH auth;
 
146
 
 
147
        if (getData(TCSD_PACKET_TYPE_UINT32, 0, &hContext, 0, &data->comm))
 
148
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
149
 
 
150
        LogDebugFn("thread %zd context %x", THREAD_ID, hContext);
 
151
 
 
152
        if (getData(TCSD_PACKET_TYPE_AUTH, 1, &auth, 0, &data->comm))
 
153
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
154
 
 
155
        MUTEX_LOCK(tcsp_lock);
 
156
 
 
157
        result = TCSP_OwnerReadPubek_Internal(hContext, &auth, &pubEKSize, &pubEK);
 
158
 
 
159
        MUTEX_UNLOCK(tcsp_lock);
 
160
 
 
161
        if (result == TSS_SUCCESS) {
 
162
                initData(&data->comm, 3);
 
163
                if (setData(TCSD_PACKET_TYPE_AUTH, 0, &auth, 0, &data->comm)) {
 
164
                        free(pubEK);
 
165
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
166
                }
 
167
                if (setData(TCSD_PACKET_TYPE_UINT32, 1, &pubEKSize, 0, &data->comm)) {
 
168
                        free(pubEK);
 
169
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
170
                }
 
171
                if (setData(TCSD_PACKET_TYPE_PBYTE, 2, pubEK, pubEKSize, &data->comm)) {
 
172
                        free(pubEK);
 
173
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
174
                }
 
175
                free(pubEK);
 
176
        } else
 
177
                initData(&data->comm, 0);
 
178
 
 
179
        data->comm.hdr.u.result = result;
 
180
        return TSS_SUCCESS;
 
181
}
 
182
 
 
183
TSS_RESULT
 
184
tcs_wrap_DisablePubekRead(struct tcsd_thread_data *data)
 
185
{
 
186
        TCS_CONTEXT_HANDLE hContext;
 
187
        TSS_RESULT result;
 
188
        TPM_AUTH auth;
 
189
 
 
190
        if (getData(TCSD_PACKET_TYPE_UINT32, 0, &hContext, 0, &data->comm))
 
191
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
192
 
 
193
        LogDebugFn("thread %zd context %x", THREAD_ID, hContext);
 
194
 
 
195
        if (getData(TCSD_PACKET_TYPE_AUTH, 1, &auth, 0, &data->comm))
 
196
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
197
 
 
198
        MUTEX_LOCK(tcsp_lock);
 
199
 
 
200
        result = TCSP_DisablePubekRead_Internal(hContext, &auth);
 
201
 
 
202
        MUTEX_UNLOCK(tcsp_lock);
 
203
 
 
204
        if (result == TSS_SUCCESS) {
 
205
                initData(&data->comm, 1);
 
206
                if (setData(TCSD_PACKET_TYPE_AUTH, 0, &auth, 0, &data->comm)) {
 
207
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
208
                }
 
209
        } else
 
210
                initData(&data->comm, 0);
 
211
 
 
212
        data->comm.hdr.u.result = result;
 
213
        return TSS_SUCCESS;
 
214
}
 
215
 
 
216
TSS_RESULT
 
217
tcs_wrap_CreateRevocableEndorsementKeyPair(struct tcsd_thread_data *data)
 
218
{
 
219
        TCS_CONTEXT_HANDLE hContext;
 
220
        TPM_NONCE antiReplay;
 
221
        UINT32 eKPtrSize;
 
222
        BYTE *eKPtr;
 
223
        TSS_BOOL genResetAuth;
 
224
        TPM_DIGEST eKResetAuth;
 
225
        UINT32 eKSize;
 
226
        BYTE* eK;
 
227
        TPM_DIGEST checksum;
 
228
        TSS_RESULT result;
 
229
 
 
230
        if (getData(TCSD_PACKET_TYPE_UINT32, 0, &hContext, 0, &data->comm))
 
231
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
232
 
 
233
        LogDebugFn("thread %zd context %x", THREAD_ID, hContext);
 
234
 
 
235
        if (getData(TCSD_PACKET_TYPE_NONCE, 1, &antiReplay, 0, &data->comm))
 
236
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
237
 
 
238
        if (getData(TCSD_PACKET_TYPE_UINT32, 2, &eKPtrSize, 0, &data->comm))
 
239
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
240
 
 
241
        eKPtr = calloc(1, eKPtrSize);
 
242
        if (eKPtr == NULL) {
 
243
                LogError("malloc of %d bytes failed.", eKPtrSize);
 
244
                return TCSERR(TSS_E_OUTOFMEMORY);
 
245
        }
 
246
        if (getData(TCSD_PACKET_TYPE_PBYTE, 3, eKPtr, eKPtrSize, &data->comm)) {
 
247
                free(eKPtr);
 
248
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
249
        }
 
250
 
 
251
        if (getData(TCSD_PACKET_TYPE_BOOL, 4, &genResetAuth, 0, &data->comm)) {
 
252
                free(eKPtr);
 
253
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
254
        }
 
255
 
 
256
        if (getData(TCSD_PACKET_TYPE_DIGEST, 5, &eKResetAuth, 0, &data->comm)) {
 
257
                free(eKPtr);
 
258
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
259
        }
 
260
 
 
261
        MUTEX_LOCK(tcsp_lock);
 
262
 
 
263
        result = TCSP_CreateRevocableEndorsementKeyPair_Internal(hContext, antiReplay,
 
264
                        eKPtrSize, eKPtr, genResetAuth, &eKResetAuth, &eKSize, &eK, &checksum);
 
265
 
 
266
        MUTEX_UNLOCK(tcsp_lock);
 
267
 
 
268
        free(eKPtr);
 
269
 
 
270
        if (result == TSS_SUCCESS) {
 
271
                initData(&data->comm, 4);
 
272
                if (setData(TCSD_PACKET_TYPE_DIGEST, 0, &eKResetAuth, 0, &data->comm)) {
 
273
                        free(eK);
 
274
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
275
                }
 
276
                if (setData(TCSD_PACKET_TYPE_UINT32, 1, &eKSize, 0, &data->comm)) {
 
277
                        free(eK);
 
278
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
279
                }
 
280
                if (setData(TCSD_PACKET_TYPE_PBYTE, 2, eK, eKSize, &data->comm)) {
 
281
                        free(eK);
 
282
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
283
                }
 
284
                free(eK);
 
285
                if (setData(TCSD_PACKET_TYPE_DIGEST, 3, &checksum, 0, &data->comm)) {
 
286
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
287
                }
 
288
        } else
 
289
                initData(&data->comm, 0);
 
290
 
 
291
        data->comm.hdr.u.result = result;
 
292
 
 
293
        return TSS_SUCCESS;
 
294
}
 
295
 
 
296
TSS_RESULT
 
297
tcs_wrap_RevokeEndorsementKeyPair(struct tcsd_thread_data *data)
 
298
{
 
299
        TCS_CONTEXT_HANDLE hContext;
 
300
        TPM_DIGEST eKResetAuth;
 
301
        TSS_RESULT result;
 
302
 
 
303
        if (getData(TCSD_PACKET_TYPE_UINT32, 0, &hContext, 0, &data->comm))
 
304
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
305
 
 
306
        LogDebugFn("thread %zd context %x", THREAD_ID, hContext);
 
307
 
 
308
        if (getData(TCSD_PACKET_TYPE_DIGEST, 1, &eKResetAuth, 0, &data->comm))
 
309
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
310
 
 
311
        MUTEX_LOCK(tcsp_lock);
 
312
 
 
313
        result = TCSP_RevokeEndorsementKeyPair_Internal(hContext, eKResetAuth);
 
314
 
 
315
        MUTEX_UNLOCK(tcsp_lock);
 
316
 
 
317
        initData(&data->comm, 0);
 
318
 
 
319
        data->comm.hdr.u.result = result;
 
320
 
 
321
        return TSS_SUCCESS;
 
322
}
 
323