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

« back to all changes in this revision

Viewing changes to src/tcs/rpc/tcstp/rpc_tick.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_ReadCurrentTicks(struct tcsd_thread_data *data)
 
32
{
 
33
        TCS_CONTEXT_HANDLE hContext;
 
34
        UINT32 pulCurrentTime;
 
35
        BYTE *prgbCurrentTime;
 
36
        TSS_RESULT result;
 
37
 
 
38
        if (getData(TCSD_PACKET_TYPE_UINT32, 0, &hContext, 0, &data->comm))
 
39
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
40
 
 
41
        LogDebugFn("thread %zd context %x", THREAD_ID, hContext);
 
42
 
 
43
        MUTEX_LOCK(tcsp_lock);
 
44
 
 
45
        result = TCSP_ReadCurrentTicks_Internal(hContext, &pulCurrentTime, &prgbCurrentTime);
 
46
 
 
47
        MUTEX_UNLOCK(tcsp_lock);
 
48
 
 
49
        if (result == TSS_SUCCESS) {
 
50
                initData(&data->comm, 2);
 
51
                if (setData(TCSD_PACKET_TYPE_UINT32, 0, &pulCurrentTime, 0, &data->comm)) {
 
52
                        free(prgbCurrentTime);
 
53
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
54
                }
 
55
                if (setData(TCSD_PACKET_TYPE_PBYTE, 1, prgbCurrentTime, pulCurrentTime,
 
56
                            &data->comm)) {
 
57
                        free(prgbCurrentTime);
 
58
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
59
                }
 
60
                free(prgbCurrentTime);
 
61
        } else
 
62
                initData(&data->comm, 0);
 
63
 
 
64
        data->comm.hdr.u.result = result;
 
65
        return TSS_SUCCESS;
 
66
}
 
67
 
 
68
TSS_RESULT
 
69
tcs_wrap_TickStampBlob(struct tcsd_thread_data *data)
 
70
{
 
71
        TCS_CONTEXT_HANDLE hContext;
 
72
        TCS_KEY_HANDLE hKey;
 
73
        TPM_AUTH auth, *pAuth;
 
74
        TPM_NONCE nonce;
 
75
        TPM_DIGEST digest;
 
76
        UINT32 sigSize, tcSize, i;
 
77
        BYTE *sig, *tc;
 
78
        TSS_RESULT result;
 
79
 
 
80
        if (getData(TCSD_PACKET_TYPE_UINT32, 0, &hContext, 0, &data->comm))
 
81
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
82
 
 
83
        LogDebugFn("thread %zd context %x", THREAD_ID, hContext);
 
84
 
 
85
        if (getData(TCSD_PACKET_TYPE_UINT32, 1, &hKey, 0, &data->comm))
 
86
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
87
        if (getData(TCSD_PACKET_TYPE_NONCE, 2, &nonce, 0, &data->comm))
 
88
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
89
        if (getData(TCSD_PACKET_TYPE_DIGEST, 3, &digest, 0, &data->comm))
 
90
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
91
        if (getData(TCSD_PACKET_TYPE_AUTH, 4, &auth, 0, &data->comm))
 
92
                pAuth = NULL;
 
93
        else
 
94
                pAuth = &auth;
 
95
 
 
96
        MUTEX_LOCK(tcsp_lock);
 
97
 
 
98
        result = TCSP_TickStampBlob_Internal(hContext, hKey, &nonce, &digest, pAuth, &sigSize, &sig,
 
99
                                             &tcSize, &tc);
 
100
 
 
101
        MUTEX_UNLOCK(tcsp_lock);
 
102
 
 
103
        if (result == TSS_SUCCESS) {
 
104
                initData(&data->comm, 5);
 
105
                i = 0;
 
106
                if (pAuth) {
 
107
                        if (setData(TCSD_PACKET_TYPE_AUTH, 0, pAuth, 0, &data->comm)) {
 
108
                                free(sig);
 
109
                                free(tc);
 
110
                                return TCSERR(TSS_E_INTERNAL_ERROR);
 
111
                        }
 
112
                }
 
113
                if (setData(TCSD_PACKET_TYPE_UINT32, i++, &sigSize, 0, &data->comm)) {
 
114
                        free(sig);
 
115
                        free(tc);
 
116
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
117
                }
 
118
                if (setData(TCSD_PACKET_TYPE_PBYTE, i++, sig, sigSize, &data->comm)) {
 
119
                        free(sig);
 
120
                        free(tc);
 
121
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
122
                }
 
123
                if (setData(TCSD_PACKET_TYPE_UINT32, i++, &tcSize, 0, &data->comm)) {
 
124
                        free(sig);
 
125
                        free(tc);
 
126
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
127
                }
 
128
                if (setData(TCSD_PACKET_TYPE_PBYTE, i++, tc, tcSize, &data->comm)) {
 
129
                        free(sig);
 
130
                        free(tc);
 
131
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
132
                }
 
133
        } else
 
134
                initData(&data->comm, 0);
 
135
 
 
136
        data->comm.hdr.u.result = result;
 
137
        return TSS_SUCCESS;
 
138
}