1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
/*
* The Initial Developer of the Original Code is Intel Corporation.
* Portions created by Intel Corporation are Copyright (C) 2007 Intel Corporation.
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the Common Public License as published by
* IBM Corporation; either version 1 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Common Public License for more details.
*
* You should have received a copy of the Common Public License
* along with this program; if not, a copy can be viewed at
* http://www.opensource.org/licenses/cpl1.0.php.
*
* trousers - An open source TCG Software Stack
*
* Author: james.xu@intel.com Rossey.liu@intel.com
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include "trousers/tss.h"
#include "trousers_types.h"
#include "tcs_tsp.h"
#include "tcsps.h"
#include "tcs_utils.h"
#include "tcs_int_literals.h"
#include "capabilities.h"
#include "tcslog.h"
#include "req_mgr.h"
#include "tcsd_wrap.h"
#include "tcsd.h"
TSS_RESULT
TCSP_NV_DefineOrReleaseSpace_Internal(TCS_CONTEXT_HANDLE hContext, /* in */
UINT32 cPubInfoSize, /* in */
BYTE* pPubInfo, /* in */
TPM_ENCAUTH encAuth, /* in */
TPM_AUTH* pAuth) /* in, out */
{
UINT64 offset = 0;
UINT32 paramSize;
TSS_RESULT result;
BYTE txBlob[TSS_TPM_TXBLOB_SIZE];
LogDebugFn("Enter");
if ((result = ctx_verify_context(hContext)))
return result;
if (pAuth) {
if ((result = auth_mgr_check(hContext, &pAuth->AuthHandle)))
goto done;
}
if ((result = tpm_rqu_build(TPM_ORD_NV_DefineSpace, &offset, txBlob, cPubInfoSize, pPubInfo,
TPM_ENCAUTH_SIZE, encAuth.authdata, pAuth)))
return result;
LogDebug("req_mgr_submit_req (oldOffset=%" PRIu64 ")", offset);
if ((result = req_mgr_submit_req(txBlob)))
goto done;
result = UnloadBlob_Header(txBlob, ¶mSize);
LogDebug("UnloadBlob (paramSize=%u) result=%u", paramSize, result);
if (!result) {
result = tpm_rsp_parse(TPM_ORD_NV_DefineSpace, txBlob, paramSize, pAuth);
}
done:
LogDebug("Leaving DefineSpace with result:%u", result);
auth_mgr_release_auth(pAuth, NULL, hContext);
return result;
}
TSS_RESULT
TCSP_NV_WriteValue_Internal(TCS_CONTEXT_HANDLE hContext, /* in */
TSS_NV_INDEX hNVStore, /* in */
UINT32 offset, /* in */
UINT32 ulDataLength, /* in */
BYTE * rgbDataToWrite, /* in */
TPM_AUTH * privAuth) /* in, out */
{
UINT64 off_set = 0;
UINT32 paramSize;
TSS_RESULT result;
BYTE txBlob[TSS_TPM_TXBLOB_SIZE];
LogDebugFn("Enter");
if ( (result = ctx_verify_context(hContext)))
return result;
if (privAuth) {
if ((result = auth_mgr_check(hContext, &privAuth->AuthHandle)))
goto done;
}
if ((result = tpm_rqu_build(TPM_ORD_NV_WriteValue, &off_set, txBlob, hNVStore, offset,
ulDataLength, rgbDataToWrite, privAuth)))
return result;
LogDebug("req_mgr_submit_req (oldOffset=%" PRIu64 ")", off_set);
if ((result = req_mgr_submit_req(txBlob)))
goto done;
result = UnloadBlob_Header(txBlob, ¶mSize);
LogDebug("UnloadBlob (paramSize=%u) result=%u", paramSize, result);
if (!result) {
result = tpm_rsp_parse(TPM_ORD_NV_WriteValue, txBlob, paramSize, privAuth);
}
done:
LogDebug("Leaving NVWriteValue with result:%u", result);
auth_mgr_release_auth(privAuth, NULL, hContext);
return result;
}
TSS_RESULT
TCSP_NV_WriteValueAuth_Internal(TCS_CONTEXT_HANDLE hContext, /* in */
TSS_NV_INDEX hNVStore, /* in */
UINT32 offset, /* in */
UINT32 ulDataLength, /* in */
BYTE * rgbDataToWrite, /* in */
TPM_AUTH * NVAuth) /* in, out */
{
UINT64 off_set = 0;
UINT32 paramSize;
TSS_RESULT result;
BYTE txBlob[TSS_TPM_TXBLOB_SIZE];
LogDebugFn("Enter");
if ((result = ctx_verify_context(hContext)))
return result;
if ((result = auth_mgr_check(hContext, &NVAuth->AuthHandle)))
goto done;
if ((result = tpm_rqu_build(TPM_ORD_NV_WriteValueAuth, &off_set, txBlob, hNVStore, offset,
ulDataLength, rgbDataToWrite, NVAuth)))
return result;
LogDebug("req_mgr_submit_req (oldOffset=%" PRIu64 ")", off_set);
if ((result = req_mgr_submit_req(txBlob)))
goto done;
result = UnloadBlob_Header(txBlob, ¶mSize);
LogDebug("UnloadBlob (paramSize=%u) result=%u", paramSize, result);
if (!result) {
result = tpm_rsp_parse(TPM_ORD_NV_WriteValueAuth, txBlob, paramSize, NVAuth);
}
done:
LogDebug("Leaving NVWriteValueAuth with result:%u", result);
auth_mgr_release_auth(NVAuth, NULL, hContext);
return result;
}
TSS_RESULT
TCSP_NV_ReadValue_Internal(TCS_CONTEXT_HANDLE hContext, /* in */
TSS_NV_INDEX hNVStore, /* in */
UINT32 offset, /* in */
UINT32 * pulDataLength, /* in, out */
TPM_AUTH * privAuth, /* in, out */
BYTE ** rgbDataRead) /* out */
{
UINT64 off_set = 0;
UINT32 paramSize;
TSS_RESULT result;
BYTE txBlob[TSS_TPM_TXBLOB_SIZE];
LogDebugFn("Enter");
if ((result = ctx_verify_context(hContext)))
return result;
if (privAuth) {
if ((result = auth_mgr_check(hContext, &privAuth->AuthHandle)))
goto done;
}
if ((result = tpm_rqu_build(TPM_ORD_NV_ReadValue, &off_set, txBlob, hNVStore, offset,
*pulDataLength, privAuth)))
return result;
LogDebug("req_mgr_submit_req (oldOffset=%" PRIu64 ")", off_set);
if ((result = req_mgr_submit_req(txBlob)))
goto done;
result = UnloadBlob_Header(txBlob, ¶mSize);
LogDebug("UnloadBlob (paramSize=%u) result=%u", paramSize, result);
if (!result) {
result = tpm_rsp_parse(TPM_ORD_NV_ReadValue, txBlob, paramSize, pulDataLength,
rgbDataRead, privAuth, NULL);
}
done:
LogDebug("Leaving NVReadValue with result:%u", result);
auth_mgr_release_auth(privAuth, NULL, hContext);
return result;
}
TSS_RESULT
TCSP_NV_ReadValueAuth_Internal(TCS_CONTEXT_HANDLE hContext, /* in */
TSS_NV_INDEX hNVStore, /* in */
UINT32 offset, /* in */
UINT32 * pulDataLength, /* in, out */
TPM_AUTH * NVAuth, /* in, out */
BYTE ** rgbDataRead) /* out */
{
UINT64 off_set = 0;
UINT32 paramSize;
TSS_RESULT result;
BYTE txBlob[TSS_TPM_TXBLOB_SIZE];
LogDebugFn("Enter");
if ((result = ctx_verify_context(hContext)))
return result;
if ((result = auth_mgr_check(hContext, &NVAuth->AuthHandle)))
goto done;
if ((result = tpm_rqu_build(TPM_ORD_NV_ReadValueAuth, &off_set, txBlob, hNVStore, offset,
*pulDataLength, NVAuth)))
return result;
LogDebug("req_mgr_submit_req (oldOffset=%" PRIu64 ")", off_set);
if ((result = req_mgr_submit_req(txBlob)))
goto done;
result = UnloadBlob_Header(txBlob, ¶mSize);
LogDebug("UnloadBlob (paramSize=%u) result=%u", paramSize, result);
if (!result) {
result = tpm_rsp_parse(TPM_ORD_NV_ReadValueAuth, txBlob, paramSize, pulDataLength,
rgbDataRead, NVAuth, NULL);
}
done:
LogDebug("Leaving NVReadValueAuth with result:%u", result);
auth_mgr_release_auth(NVAuth, NULL, hContext);
return result;
}
|