rpc_pcr_extend.c revision 1.1.1.1
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
30TSS_RESULT
31tcs_wrap_Extend(struct tcsd_thread_data *data)
32{
33	TCS_CONTEXT_HANDLE hContext;
34	UINT32 pcrIndex;
35	TCPA_DIGEST inDigest;
36	TSS_RESULT result;
37	TCPA_DIGEST outDigest;
38
39	if (getData(TCSD_PACKET_TYPE_UINT32, 0, &hContext, 0, &data->comm))
40		return TCSERR(TSS_E_INTERNAL_ERROR);
41
42	LogDebugFn("thread %ld context %x", THREAD_ID, hContext);
43
44	if (getData(TCSD_PACKET_TYPE_UINT32, 1, &pcrIndex, 0, &data->comm))
45		return TCSERR(TSS_E_INTERNAL_ERROR);
46	if (getData(TCSD_PACKET_TYPE_DIGEST, 2, &inDigest, 0, &data->comm))
47		return TCSERR(TSS_E_INTERNAL_ERROR);
48
49	MUTEX_LOCK(tcsp_lock);
50
51	result = TCSP_Extend_Internal(hContext, pcrIndex, inDigest, &outDigest);
52
53	MUTEX_UNLOCK(tcsp_lock);
54
55	if (result == TSS_SUCCESS) {
56		initData(&data->comm, 1);
57		if (setData(TCSD_PACKET_TYPE_DIGEST, 0, &outDigest, 0, &data->comm)) {
58			return TCSERR(TSS_E_INTERNAL_ERROR);
59		}
60	} else
61		initData(&data->comm, 0);
62
63	data->comm.hdr.u.result = result;
64	return TSS_SUCCESS;
65}
66
67TSS_RESULT
68tcs_wrap_PcrRead(struct tcsd_thread_data *data)
69{
70	TCS_CONTEXT_HANDLE hContext;
71	UINT32 pcrIndex;
72	TCPA_DIGEST digest;
73	TSS_RESULT result;
74
75	if (getData(TCSD_PACKET_TYPE_UINT32, 0, &hContext, 0, &data->comm))
76		return TCSERR(TSS_E_INTERNAL_ERROR);
77
78	LogDebugFn("thread %ld context %x", THREAD_ID, hContext);
79
80	if (getData(TCSD_PACKET_TYPE_UINT32, 1, &pcrIndex, 0, &data->comm))
81		return TCSERR(TSS_E_INTERNAL_ERROR);
82
83	MUTEX_LOCK(tcsp_lock);
84
85	result = TCSP_PcrRead_Internal(hContext, pcrIndex, &digest);
86
87	MUTEX_UNLOCK(tcsp_lock);
88
89	if (result == TSS_SUCCESS) {
90		initData(&data->comm, 1);
91		if (setData(TCSD_PACKET_TYPE_DIGEST, 0, &digest, 0, &data->comm)) {
92			return TCSERR(TSS_E_INTERNAL_ERROR);
93		}
94	} else
95		initData(&data->comm, 0);
96
97	data->comm.hdr.u.result = result;
98	return TSS_SUCCESS;
99}
100
101TSS_RESULT
102tcs_wrap_PcrReset(struct tcsd_thread_data *data)
103{
104	TCS_CONTEXT_HANDLE hContext;
105	UINT32 pcrDataSizeIn;
106	BYTE *pcrDataIn;
107	TSS_RESULT result;
108
109	if (getData(TCSD_PACKET_TYPE_UINT32, 0, &hContext, 0, &data->comm))
110		return TCSERR(TSS_E_INTERNAL_ERROR);
111
112	LogDebugFn("thread %ld context %x", THREAD_ID, hContext);
113
114	if (getData(TCSD_PACKET_TYPE_UINT32, 1, &pcrDataSizeIn, 0, &data->comm))
115		return TCSERR(TSS_E_INTERNAL_ERROR);
116
117	pcrDataIn = (BYTE *)malloc(pcrDataSizeIn);
118	if (pcrDataIn == NULL) {
119		LogError("malloc of %u bytes failed.", pcrDataSizeIn);
120		return TCSERR(TSS_E_OUTOFMEMORY);
121	}
122	if (getData(TCSD_PACKET_TYPE_PBYTE, 2, pcrDataIn, pcrDataSizeIn, &data->comm)) {
123		free(pcrDataIn);
124		return TCSERR(TSS_E_INTERNAL_ERROR);
125	}
126
127	MUTEX_LOCK(tcsp_lock);
128
129	result = TCSP_PcrReset_Internal(hContext, pcrDataSizeIn, pcrDataIn);
130
131	MUTEX_UNLOCK(tcsp_lock);
132	free(pcrDataIn);
133
134	initData(&data->comm, 0);
135	data->comm.hdr.u.result = result;
136
137	return result;
138}
139
140