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
tcs_wrap_OIAP(struct tcsd_thread_data * data)31 tcs_wrap_OIAP(struct tcsd_thread_data *data)
32 {
33 TCS_CONTEXT_HANDLE hContext;
34 TCS_AUTHHANDLE authHandle;
35 TCPA_NONCE n0;
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 if ((result = ctx_verify_context(hContext)))
42 goto done;
43
44 LogDebugFn("thread %ld context %x", THREAD_ID, hContext);
45
46 MUTEX_LOCK(tcsp_lock);
47
48 result = auth_mgr_oiap(hContext, &authHandle, &n0);
49
50 MUTEX_UNLOCK(tcsp_lock);
51
52 if (result == TSS_SUCCESS) {
53 initData(&data->comm, 2);
54 if (setData(TCSD_PACKET_TYPE_UINT32, 0, &authHandle, 0, &data->comm)) {
55 return TCSERR(TSS_E_INTERNAL_ERROR);
56 }
57 if (setData(TCSD_PACKET_TYPE_NONCE, 1, &n0, 0, &data->comm)) {
58 return TCSERR(TSS_E_INTERNAL_ERROR);
59 }
60 } else
61 done: initData(&data->comm, 0);
62
63 data->comm.hdr.u.result = result;
64 return TSS_SUCCESS;
65 }
66
67 TSS_RESULT
tcs_wrap_OSAP(struct tcsd_thread_data * data)68 tcs_wrap_OSAP(struct tcsd_thread_data *data)
69 {
70 TCS_CONTEXT_HANDLE hContext;
71 TCPA_ENTITY_TYPE entityType;
72 UINT32 entityValue;
73 TCPA_NONCE nonceOddOSAP;
74
75 TCS_AUTHHANDLE authHandle;
76 TCPA_NONCE nonceEven;
77 TCPA_NONCE nonceEvenOSAP;
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 if ((result = ctx_verify_context(hContext)))
84 goto done;
85
86 LogDebugFn("thread %ld context %x", THREAD_ID, hContext);
87
88 if (getData(TCSD_PACKET_TYPE_UINT16, 1, &entityType, 0, &data->comm))
89 return TCSERR(TSS_E_INTERNAL_ERROR);
90 if (getData(TCSD_PACKET_TYPE_UINT32, 2, &entityValue, 0, &data->comm))
91 return TCSERR(TSS_E_INTERNAL_ERROR);
92 if (getData(TCSD_PACKET_TYPE_NONCE, 3, &nonceOddOSAP, 0, &data->comm))
93 return TCSERR(TSS_E_INTERNAL_ERROR);
94
95 MUTEX_LOCK(tcsp_lock);
96
97 result = auth_mgr_osap(hContext, entityType, entityValue, nonceOddOSAP,
98 &authHandle, &nonceEven, &nonceEvenOSAP);
99
100 MUTEX_UNLOCK(tcsp_lock);
101
102 if (result == TSS_SUCCESS) {
103 initData(&data->comm, 3);
104 if (setData(TCSD_PACKET_TYPE_UINT32, 0, &authHandle, 0, &data->comm)) {
105 return TCSERR(TSS_E_INTERNAL_ERROR);
106 }
107 if (setData(TCSD_PACKET_TYPE_NONCE, 1, &nonceEven, 0, &data->comm)) {
108 return TCSERR(TSS_E_INTERNAL_ERROR);
109 }
110 if (setData(TCSD_PACKET_TYPE_NONCE, 2, &nonceEvenOSAP, 0, &data->comm)) {
111 return TCSERR(TSS_E_INTERNAL_ERROR);
112 }
113 } else
114 done: initData(&data->comm, 0);
115
116 data->comm.hdr.u.result = result;
117
118 return TSS_SUCCESS;
119 }
120