~ubuntu-branches/ubuntu/hardy/trousers/hardy-proposed

« back to all changes in this revision

Viewing changes to src/tcs/rpc/tcstp/rpc_quote.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-2006
 
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_Quote(struct tcsd_thread_data *data)
 
32
{
 
33
        TCS_CONTEXT_HANDLE hContext;
 
34
        TCS_KEY_HANDLE hKey;
 
35
        TCPA_NONCE antiReplay;
 
36
        UINT32 pcrDataSizeIn;
 
37
        BYTE *pcrDataIn;
 
38
 
 
39
        TPM_AUTH privAuth;
 
40
        TPM_AUTH *pPrivAuth;
 
41
 
 
42
        UINT32 pcrDataSizeOut;
 
43
        BYTE *pcrDataOut;
 
44
        UINT32 sigSize;
 
45
        BYTE *sig;
 
46
        TSS_RESULT result;
 
47
 
 
48
        int i;
 
49
 
 
50
        if (getData(TCSD_PACKET_TYPE_UINT32, 0, &hContext, 0, &data->comm))
 
51
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
52
 
 
53
        LogDebugFn("thread %zd context %x", THREAD_ID, hContext);
 
54
 
 
55
        if (getData(TCSD_PACKET_TYPE_UINT32, 1, &hKey, 0, &data->comm))
 
56
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
57
        if (getData(TCSD_PACKET_TYPE_NONCE, 2, &antiReplay, 0, &data->comm))
 
58
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
59
        if (getData(TCSD_PACKET_TYPE_UINT32, 3, &pcrDataSizeIn, 0, &data->comm))
 
60
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
61
        pcrDataIn = (BYTE *)calloc(1, pcrDataSizeIn);
 
62
        if (pcrDataIn == NULL) {
 
63
                LogError("malloc of %d bytes failed.", pcrDataSizeIn);
 
64
                return TCSERR(TSS_E_OUTOFMEMORY);
 
65
        }
 
66
        if (getData(TCSD_PACKET_TYPE_PBYTE, 4, pcrDataIn, pcrDataSizeIn, &data->comm)) {
 
67
                free(pcrDataIn);
 
68
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
69
        }
 
70
 
 
71
        result = getData(TCSD_PACKET_TYPE_AUTH, 5, &privAuth, 0, &data->comm);
 
72
        if (result == TSS_TCP_RPC_BAD_PACKET_TYPE)
 
73
                pPrivAuth = NULL;
 
74
        else if (result) {
 
75
                free(pcrDataIn);
 
76
                return result;
 
77
        } else
 
78
                pPrivAuth = &privAuth;
 
79
 
 
80
        MUTEX_LOCK(tcsp_lock);
 
81
 
 
82
        result = TCSP_Quote_Internal(hContext, hKey, antiReplay, pcrDataSizeIn, pcrDataIn,
 
83
                                     pPrivAuth, &pcrDataSizeOut, &pcrDataOut, &sigSize, &sig);
 
84
 
 
85
        MUTEX_UNLOCK(tcsp_lock);
 
86
        free(pcrDataIn);
 
87
 
 
88
        if (result == TSS_SUCCESS) {
 
89
                i = 0;
 
90
                initData(&data->comm, 5);
 
91
                if (pPrivAuth != NULL) {
 
92
                        if (setData(TCSD_PACKET_TYPE_AUTH, i++, pPrivAuth, 0, &data->comm)) {
 
93
                                free(pcrDataOut);
 
94
                                free(sig);
 
95
                                return TCSERR(TSS_E_INTERNAL_ERROR);
 
96
                        }
 
97
                }
 
98
                if (setData(TCSD_PACKET_TYPE_UINT32, i++, &pcrDataSizeOut, 0, &data->comm)) {
 
99
                        free(pcrDataOut);
 
100
                        free(sig);
 
101
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
102
                }
 
103
                if (setData(TCSD_PACKET_TYPE_PBYTE, i++, pcrDataOut, pcrDataSizeOut, &data->comm)) {
 
104
                        free(pcrDataOut);
 
105
                        free(sig);
 
106
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
107
                }
 
108
                if (setData(TCSD_PACKET_TYPE_UINT32, i++, &sigSize, 0, &data->comm)) {
 
109
                        free(pcrDataOut);
 
110
                        free(sig);
 
111
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
112
                }
 
113
                if (setData(TCSD_PACKET_TYPE_PBYTE, i++, sig, sigSize, &data->comm)) {
 
114
                        free(pcrDataOut);
 
115
                        free(sig);
 
116
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
117
                }
 
118
 
 
119
                free(pcrDataOut);
 
120
                free(sig);
 
121
        } else
 
122
                initData(&data->comm, 0);
 
123
 
 
124
        data->comm.hdr.u.result = result;
 
125
        return TSS_SUCCESS;
 
126
}