~ubuntu-branches/ubuntu/jaunty/trousers/jaunty

« back to all changes in this revision

Viewing changes to src/tspi/rpc/tcstp/rpc_audit.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. 2007
 
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 "tsplog.h"
 
20
#include "hosttable.h"
 
21
#include "tcsd_wrap.h"
 
22
#include "rpc_tcstp_tsp.h"
 
23
 
 
24
 
 
25
TSS_RESULT
 
26
RPC_SetOrdinalAuditStatus_TP(struct host_table_entry *hte,
 
27
                             TPM_AUTH *ownerAuth,       /* in/out */
 
28
                             UINT32 ulOrdinal,          /* in */
 
29
                             TSS_BOOL bAuditState)      /* in */
 
30
{
 
31
        TSS_RESULT result;
 
32
 
 
33
        initData(&hte->comm, 4);
 
34
        hte->comm.hdr.u.ordinal = TCSD_ORD_SETORDINALAUDITSTATUS;
 
35
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
36
 
 
37
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
38
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
39
        if (setData(TCSD_PACKET_TYPE_UINT32, 1, &ulOrdinal, 0, &hte->comm))
 
40
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
41
        if (setData(TCSD_PACKET_TYPE_BOOL, 2, &bAuditState, 0, &hte->comm))
 
42
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
43
        if (setData(TCSD_PACKET_TYPE_AUTH, 3, ownerAuth, 0, &hte->comm))
 
44
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
45
 
 
46
        result = sendTCSDPacket(hte);
 
47
 
 
48
        if (result == TSS_SUCCESS)
 
49
                result = hte->comm.hdr.u.result;
 
50
 
 
51
        if (result == TSS_SUCCESS) {
 
52
                if (getData(TCSD_PACKET_TYPE_AUTH, 0, ownerAuth, 0, &hte->comm))
 
53
                        result = TSPERR(TSS_E_INTERNAL_ERROR);
 
54
        }
 
55
 
 
56
        return result;
 
57
}
 
58
 
 
59
TSS_RESULT
 
60
RPC_GetAuditDigest_TP(struct host_table_entry *hte,
 
61
                      UINT32 startOrdinal,              /* in */
 
62
                      TPM_DIGEST *auditDigest,          /* out */
 
63
                      UINT32 *counterValueSize, /* out */
 
64
                      BYTE **counterValue,              /* out */
 
65
                      TSS_BOOL *more,                   /* out */
 
66
                      UINT32 *ordSize,                  /* out */
 
67
                      UINT32 **ordList)         /* out */
 
68
{
 
69
        TSS_RESULT result;
 
70
 
 
71
        initData(&hte->comm, 2);
 
72
        hte->comm.hdr.u.ordinal = TCSD_ORD_GETAUDITDIGEST;
 
73
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
74
 
 
75
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
76
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
77
        if (setData(TCSD_PACKET_TYPE_UINT32, 1, &startOrdinal, 0, &hte->comm))
 
78
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
79
 
 
80
        result = sendTCSDPacket(hte);
 
81
 
 
82
        if (result == TSS_SUCCESS)
 
83
                result = hte->comm.hdr.u.result;
 
84
 
 
85
        if (result == TSS_SUCCESS) {
 
86
                if (getData(TCSD_PACKET_TYPE_DIGEST, 0, auditDigest, 0, &hte->comm)) {
 
87
                        result = TSPERR(TSS_E_INTERNAL_ERROR);
 
88
                        goto done;
 
89
                }
 
90
                if (getData(TCSD_PACKET_TYPE_UINT32, 1, counterValueSize, 0, &hte->comm)) {
 
91
                        result = TSPERR(TSS_E_INTERNAL_ERROR);
 
92
                        goto done;
 
93
                }
 
94
                *counterValue = (BYTE *)malloc(*counterValueSize);
 
95
                if (*counterValue == NULL) {
 
96
                        LogError("malloc of %u bytes failed.", *counterValueSize);
 
97
                        result = TSPERR(TSS_E_OUTOFMEMORY);
 
98
                        goto done;
 
99
                }
 
100
                if (getData(TCSD_PACKET_TYPE_PBYTE, 2, *counterValue, *counterValueSize, &hte->comm)) {
 
101
                        free(*counterValue);
 
102
                        result = TSPERR(TSS_E_INTERNAL_ERROR);
 
103
                        goto done;
 
104
                }
 
105
                if (getData(TCSD_PACKET_TYPE_BOOL, 3, more, 0, &hte->comm)) {
 
106
                        free(*counterValue);
 
107
                        result = TSPERR(TSS_E_INTERNAL_ERROR);
 
108
                        goto done;
 
109
                }
 
110
                if (getData(TCSD_PACKET_TYPE_UINT32, 4, ordSize, 0, &hte->comm)) {
 
111
                        free(*counterValue);
 
112
                        result = TSPERR(TSS_E_INTERNAL_ERROR);
 
113
                        goto done;
 
114
                }
 
115
                *ordList = (UINT32 *)malloc(*ordSize * sizeof(UINT32));
 
116
                if (*ordList == NULL) {
 
117
                        LogError("malloc of %u bytes failed.", *ordSize);
 
118
                        free(*counterValue);
 
119
                        result = TSPERR(TSS_E_OUTOFMEMORY);
 
120
                        goto done;
 
121
                }
 
122
                if (getData(TCSD_PACKET_TYPE_PBYTE, 5, *ordList, *ordSize * sizeof(UINT32), &hte->comm)) {
 
123
                        free(*counterValue);
 
124
                        free(*ordList);
 
125
                        result = TSPERR(TSS_E_INTERNAL_ERROR);
 
126
                        goto done;
 
127
                }
 
128
        }
 
129
 
 
130
done:
 
131
        return result;
 
132
}
 
133
 
 
134
TSS_RESULT
 
135
RPC_GetAuditDigestSigned_TP(struct host_table_entry *hte,
 
136
                            TCS_KEY_HANDLE keyHandle,           /* in */
 
137
                            TSS_BOOL closeAudit,                /* in */
 
138
                            TPM_NONCE *antiReplay,              /* in */
 
139
                            TPM_AUTH *privAuth,         /* in/out */
 
140
                            UINT32 *counterValueSize,           /* out */
 
141
                            BYTE **counterValue,                /* out */
 
142
                            TPM_DIGEST *auditDigest,            /* out */
 
143
                            TPM_DIGEST *ordinalDigest,          /* out */
 
144
                            UINT32 *sigSize,                    /* out */
 
145
                            BYTE **sig)                 /* out */
 
146
{
 
147
        TSS_RESULT result = TSPERR(TSS_E_INTERNAL_ERROR);
 
148
        TPM_AUTH null_auth;
 
149
        int i;
 
150
 
 
151
        initData(&hte->comm, 5);
 
152
        hte->comm.hdr.u.ordinal = TCSD_ORD_GETAUDITDIGESTSIGNED;
 
153
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
154
 
 
155
        memset(&null_auth, 0, sizeof(TPM_AUTH));
 
156
 
 
157
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
158
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
159
        if (setData(TCSD_PACKET_TYPE_UINT32, 1, &keyHandle, 0, &hte->comm))
 
160
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
161
        if (setData(TCSD_PACKET_TYPE_BOOL, 2, &closeAudit, 0, &hte->comm))
 
162
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
163
        if (setData(TCSD_PACKET_TYPE_NONCE, 3, antiReplay, 0, &hte->comm))
 
164
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
165
        if (privAuth) {
 
166
                if (setData(TCSD_PACKET_TYPE_AUTH, 4, privAuth, 0, &hte->comm))
 
167
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
168
        }
 
169
        else {
 
170
                if (setData(TCSD_PACKET_TYPE_AUTH, 4, &null_auth, 0, &hte->comm))
 
171
                        return TSPERR(TSS_E_INTERNAL_ERROR);
 
172
        }
 
173
 
 
174
        result = sendTCSDPacket(hte);
 
175
 
 
176
        if (result == TSS_SUCCESS)
 
177
                result = hte->comm.hdr.u.result;
 
178
 
 
179
        if (result == TSS_SUCCESS) {
 
180
                i = 0;
 
181
                if (privAuth) {
 
182
                        if (getData(TCSD_PACKET_TYPE_AUTH, i++, privAuth, 0, &hte->comm)) {
 
183
                                result = TSPERR(TSS_E_INTERNAL_ERROR);
 
184
                                goto done;
 
185
                        }
 
186
                }
 
187
                if (getData(TCSD_PACKET_TYPE_UINT32, i++, counterValueSize, 0, &hte->comm)) {
 
188
                        result = TSPERR(TSS_E_INTERNAL_ERROR);
 
189
                        goto done;
 
190
                }
 
191
                *counterValue = (BYTE *)malloc(*counterValueSize);
 
192
                if (*counterValue == NULL) {
 
193
                        LogError("malloc of %u bytes failed.", *counterValueSize);
 
194
                        result = TSPERR(TSS_E_OUTOFMEMORY);
 
195
                        goto done;
 
196
                }
 
197
                if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *counterValue, *counterValueSize, &hte->comm)) {
 
198
                        free(*counterValue);
 
199
                        result = TSPERR(TSS_E_INTERNAL_ERROR);
 
200
                        goto done;
 
201
                }
 
202
                if (getData(TCSD_PACKET_TYPE_DIGEST, i++, auditDigest, 0, &hte->comm)) {
 
203
                        free(*counterValue);
 
204
                        result = TSPERR(TSS_E_INTERNAL_ERROR);
 
205
                        goto done;
 
206
                }
 
207
                if (getData(TCSD_PACKET_TYPE_DIGEST, i++, ordinalDigest, 0, &hte->comm)) {
 
208
                        free(*counterValue);
 
209
                        result = TSPERR(TSS_E_INTERNAL_ERROR);
 
210
                        goto done;
 
211
                }
 
212
                if (getData(TCSD_PACKET_TYPE_UINT32, i++, sigSize, 0, &hte->comm)) {
 
213
                        free(*counterValue);
 
214
                        result = TSPERR(TSS_E_INTERNAL_ERROR);
 
215
                        goto done;
 
216
                }
 
217
                *sig = (BYTE *)malloc(*sigSize);
 
218
                if (*sig == NULL) {
 
219
                        LogError("malloc of %u bytes failed.", *sigSize);
 
220
                        free(*counterValue);
 
221
                        result = TSPERR(TSS_E_OUTOFMEMORY);
 
222
                        goto done;
 
223
                }
 
224
                if (getData(TCSD_PACKET_TYPE_PBYTE, i++, *sig, *sigSize, &hte->comm)) {
 
225
                        free(*counterValue);
 
226
                        free(*sig);
 
227
                        result = TSPERR(TSS_E_INTERNAL_ERROR);
 
228
                        goto done;
 
229
                }
 
230
        }
 
231
 
 
232
done:
 
233
        return result;
 
234
}