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