blob: b35934f452c23f5b2426c24e6f7c386f5bec63b6 [file] [log] [blame]
Juergen Repp6da95b02019-10-10 11:46:03 +02001/* SPDX-License-Identifier: BSD-2-Clause */
2/*******************************************************************************
3 * Copyright 2018-2019, Fraunhofer SIT sponsored by Infineon Technologies AG
4 * All rights reserved.
5 ******************************************************************************/
6
7#ifdef HAVE_CONFIG_H
8#include <config.h>
9#endif
10
11#include <stdio.h>
12#include <string.h>
13
14#include "tpm_json_deserialize.h"
15#include "ifapi_json_deserialize.h"
16#include "fapi_policy.h"
17#define LOGMODULE fapijson
18#include "util/log.h"
19#include "util/aux_util.h"
20
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +010021static char *tss_const_prefixes[] = { "TPM2_ALG_", "TPM2_", "TPM_", "TPMA_", "POLICY", NULL };
Juergen Repp6da95b02019-10-10 11:46:03 +020022
23/** Get the index of a sub string after a certain prefix.
24 *
25 * The prefixes from table tss_const_prefixes will be used for case
26 * insensitive comparison.
27 *
28 * param[in] token the token with a potential prefix.
29 * @retval the position of the sub string after the prefix.
30 * @retval 0 if no prefix is found.
31 */
32
33static int
34get_token_start_idx(const char *token)
35{
36 int itoken = 0;
37 char *entry;
38 int i;
39
40 for (i = 0, entry = tss_const_prefixes[0]; entry != NULL;
41 i++, entry = tss_const_prefixes[i]) {
42 if (strncasecmp(token, entry, strlen(entry)) == 0) {
43 itoken += strlen(entry);
44 break;
45 }
46 }
47 return itoken;
48}
49
50/** Get number from a string.
51 *
52 * A string which represents a number or hex number (prefix 0x) is converted
53 * to an int64 number.
54 *
55 * param[in] token the string representing the number.
56 * param[out] num the converted number.
57 * @retval true if token represents a number
58 * @retval false if token does not represent a number.
59 */
60static bool
61get_number(const char *token, int64_t *num)
62{
63 int itoken = 0;
64 int pos = 0;
65 if (strncmp(token, "0x", 2) == 0) {
66 itoken = 2;
67 sscanf(&token[itoken], "%"PRIx64"%n", num, &pos);
68 } else {
69 sscanf(&token[itoken], "%"PRId64"%n", num, &pos);
70 }
71 if ((size_t)pos == strlen(token) - itoken)
72 return true;
73 else
74 return false;
75}
76
77/** Deserialize a TPMI_POLICYTYPE json object.
78 *
79 * @param[in] jso the json object to be deserialized.
80 * @param[out] out the deserialzed binary object.
81 * @retval TSS2_RC_SUCCESS if the function call was a success.
82 * @retval TSS2_FAPI_RC_BAD_VALUE if the json object can't be deserialized.
83 */
84TSS2_RC
85ifapi_json_TPMI_POLICYTYPE_deserialize(json_object *jso, TPMI_POLICYTYPE *out)
86{
87 LOG_TRACE("call");
88 return ifapi_json_TPMI_POLICYTYPE_deserialize_txt(jso, out);
89}
90
91typedef struct {
92 TPMI_POLICYTYPE in;
93 char *name;
94} IFAPI_TPMI_POLICYTYPE_ASSIGN;
95
96static IFAPI_TPMI_POLICYTYPE_ASSIGN deserialize_TPMI_POLICYTYPE_tab[] = {
97 { POLICYOR, "Or" },
98 { POLICYSIGNED, "Signed" },
99 { POLICYSECRET, "Secret" },
100 { POLICYPCR, "PCR" },
101 { POLICYLOCALITY, "Locality" },
102 { POLICYNV, "NV" },
103 { POLICYCOUNTERTIMER, "CounterTimer" },
104 { POLICYCOMMANDCODE, "CommandCode" },
105 { POLICYPHYSICALPRESENCE, "PhysicalPresence" },
106 { POLICYCPHASH, "CpHash" },
107 { POLICYNAMEHASH, "NameHash" },
108 { POLICYDUPLICATIONSELECT, "DuplicationSelect" },
109 { POLICYAUTHORIZE, "Authorize" },
110 { POLICYAUTHVALUE, "AuthValue" },
111 { POLICYPASSWORD, "Password" },
112 { POLICYNVWRITTEN, "NvWritten" },
113 { POLICYTEMPLATE, "Template" },
114 { POLICYAUTHORIZENV, "AuthorizeNv" },
115 { POLICYACTION, "Action" },
116};
117
118/** Deserialize a json object of type TPMI_POLICYTYPE.
119 *
120 * @param[in] jso the json object to be deserialized.
121 * @param[out] out the deserialzed binary object.
122 * @retval TSS2_RC_SUCCESS if the function call was a success.
123 * @retval TSS2_FAPI_RC_BAD_VALUE if the json object can't be deserialized.
124 */
125TSS2_RC
126ifapi_json_TPMI_POLICYTYPE_deserialize_txt(json_object *jso,
127 TPMI_POLICYTYPE *out)
128{
129 LOG_TRACE("call");
130 const char *token = json_object_get_string(jso);
131 int64_t i64;
132 if (get_number(token, &i64)) {
133 *out = (TPMI_POLICYTYPE) i64;
134 if ((int64_t)*out != i64) {
135 LOG_ERROR("Bad value");
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100136 return TSS2_FAPI_RC_BAD_VALUE;
Juergen Repp6da95b02019-10-10 11:46:03 +0200137 }
138 return TSS2_RC_SUCCESS;
139
140 } else {
141 int itoken = get_token_start_idx(token);
142 size_t i;
143 size_t n = sizeof(deserialize_TPMI_POLICYTYPE_tab) /
144 sizeof(deserialize_TPMI_POLICYTYPE_tab[0]);
145 size_t size = strlen(token) - itoken;
146 for (i = 0; i < n; i++) {
147 if (strncasecmp(&token[itoken],
148 &deserialize_TPMI_POLICYTYPE_tab[i].name[0],
149 size) == 0) {
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100150 *out = deserialize_TPMI_POLICYTYPE_tab[i].in;
Juergen Repp6da95b02019-10-10 11:46:03 +0200151 return TSS2_RC_SUCCESS;
152 }
153 }
154 return_error(TSS2_FAPI_RC_BAD_VALUE, "Undefined constant.");
155 }
156
157}
158
159/** Deserialize a TPMS_POLICYSIGNED json object.
160 *
161 * @param[in] jso the json object to be deserialized.
162 * @param[out] out the deserialzed binary object.
163 * @retval TSS2_RC_SUCCESS if the function call was a success.
164 * @retval TSS2_FAPI_RC_BAD_VALUE if the json object can't be deserialized.
165 */
166TSS2_RC
167ifapi_json_TPMS_POLICYSIGNED_deserialize(json_object *jso,
168 TPMS_POLICYSIGNED *out)
169{
170 json_object *jso2;
171 TSS2_RC r;
172 LOG_TRACE("call");
173 return_if_null(out, "Bad reference.", TSS2_FAPI_RC_BAD_REFERENCE);
174 size_t cond_cnt = 0; /**< counter for conditional fields */
175
176 if (!ifapi_get_sub_object(jso, "cpHashA", &jso2)) {
177 memset(&out->cpHashA, 0, sizeof(TPM2B_DIGEST));
178 } else {
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100179 r = ifapi_json_TPM2B_DIGEST_deserialize(jso2, &out->cpHashA);
Juergen Repp6da95b02019-10-10 11:46:03 +0200180 return_if_error(r, "BAD VALUE");
181 }
182
183 if (!ifapi_get_sub_object(jso, "policyRef", &jso2)) {
184 memset(&out->policyRef, 0, sizeof(TPM2B_NONCE));
185 } else {
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100186 r = ifapi_json_TPM2B_NONCE_deserialize(jso2, &out->policyRef);
Juergen Repp6da95b02019-10-10 11:46:03 +0200187 return_if_error(r, "BAD VALUE");
188 }
189
190 out->expiration = 0;
191
192 if (!ifapi_get_sub_object(jso, "keyPath", &jso2)) {
193 out->keyPath = NULL;
194 } else {
195 cond_cnt++;
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100196 r = ifapi_json_char_deserialize(jso2, &out->keyPath);
Juergen Repp6da95b02019-10-10 11:46:03 +0200197 return_if_error(r, "BAD VALUE");
198 }
199
200 if (!ifapi_get_sub_object(jso, "keyPublic", &jso2)) {
201 memset(&out->keyPublic, 0, sizeof(TPMT_PUBLIC));
202 } else {
203 cond_cnt++;
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100204 r = ifapi_json_TPMT_PUBLIC_deserialize(jso2, &out->keyPublic);
Juergen Repp6da95b02019-10-10 11:46:03 +0200205 return_if_error(r, "BAD VALUE");
206 }
207
208 if (!ifapi_get_sub_object(jso, "keyPEM", &jso2)) {
209 out->keyPEM = NULL;
210 } else {
211 cond_cnt++;
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100212 r = ifapi_json_char_deserialize(jso2, &out->keyPEM);
Juergen Repp6da95b02019-10-10 11:46:03 +0200213 return_if_error(r, "BAD VALUE");
214 }
215
Juergen Reppde603422020-01-30 14:59:40 +0100216 if (!ifapi_get_sub_object(jso, "publicKeyHint", &jso2)) {
217 out->publicKeyHint = NULL;
218 } else {
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100219 r = ifapi_json_char_deserialize(jso2, &out->publicKeyHint);
Juergen Reppde603422020-01-30 14:59:40 +0100220 return_if_error(r, "BAD VALUE");
221 }
222
Juergen Repp6da95b02019-10-10 11:46:03 +0200223 if (!ifapi_get_sub_object(jso, "keyPEMhashAlg", &jso2)) {
224 out->keyPEMhashAlg = TPM2_ALG_SHA256;
225 } else {
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100226 r = ifapi_json_TPMI_ALG_HASH_deserialize(jso2, &out->keyPEMhashAlg);
Juergen Repp6da95b02019-10-10 11:46:03 +0200227 return_if_error(r, "BAD VALUE");
228 }
229
230 /* Check whether only one condition field found in policy. */
231 if (cond_cnt != 1) {
232 return_error(TSS2_FAPI_RC_BAD_TEMPLATE,
233 "Exactly one conditional is allowed for policy signed.");
234 }
235
236 LOG_TRACE("true");
237 return TSS2_RC_SUCCESS;
238}
239
240/** Deserialize a TPMS_POLICYSECRET json object.
241 *
242 * @param[in] jso the json object to be deserialized.
243 * @param[out] out the deserialzed binary object.
244 * @retval TSS2_RC_SUCCESS if the function call was a success.
245 * @retval TSS2_FAPI_RC_BAD_VALUE if the json object can't be deserialized.
246 */
247TSS2_RC
248ifapi_json_TPMS_POLICYSECRET_deserialize(json_object *jso,
249 TPMS_POLICYSECRET *out)
250{
251 json_object *jso2;
252 TSS2_RC r;
253 size_t cond_cnt = 0; /**< counter for conditional fields */
254
255 LOG_TRACE("call");
256 return_if_null(out, "Bad reference.", TSS2_FAPI_RC_BAD_REFERENCE);
257
258 if (!ifapi_get_sub_object(jso, "cpHashA", &jso2)) {
259 memset(&out->cpHashA, 0, sizeof(TPM2B_DIGEST));
260 } else {
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100261 r = ifapi_json_TPM2B_DIGEST_deserialize(jso2, &out->cpHashA);
Juergen Repp6da95b02019-10-10 11:46:03 +0200262 return_if_error(r, "BAD VALUE");
263 }
264
265 if (!ifapi_get_sub_object(jso, "policyRef", &jso2)) {
266 memset(&out->policyRef, 0, sizeof(TPM2B_NONCE));
267 } else {
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100268 r = ifapi_json_TPM2B_NONCE_deserialize(jso2, &out->policyRef);
Juergen Repp6da95b02019-10-10 11:46:03 +0200269 return_if_error(r, "BAD VALUE");
270 }
271 out->expiration = 0;
272
273 if (!ifapi_get_sub_object(jso, "objectPath", &jso2)) {
274 out->objectPath = NULL;
275 } else {
276 cond_cnt++;
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100277 r = ifapi_json_char_deserialize(jso2, &out->objectPath);
Juergen Repp6da95b02019-10-10 11:46:03 +0200278 return_if_error(r, "BAD VALUE");
279 }
280
281 if (!ifapi_get_sub_object(jso, "objectName", &jso2)) {
282 memset(&out->objectName, 0, sizeof(TPM2B_DIGEST));
283 } else {
284 cond_cnt++;
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100285 r = ifapi_json_TPM2B_NAME_deserialize(jso2, &out->objectName);
Juergen Repp6da95b02019-10-10 11:46:03 +0200286 return_if_error(r, "BAD VALUE");
287 }
288 if (cond_cnt != 1) {
289 return_error(TSS2_FAPI_RC_BAD_TEMPLATE,
290 "Exactly one conditional needed for policy secret .");
291 }
292 LOG_TRACE("true");
293 return TSS2_RC_SUCCESS;
294}
295
296/** Deserialize a TPMS_POLICYLOCALITY json object.
297 *
298 * @param[in] jso the json object to be deserialized.
299 * @param[out] out the deserialzed binary object.
300 * @retval TSS2_RC_SUCCESS if the function call was a success.
301 * @retval TSS2_FAPI_RC_BAD_VALUE if the json object can't be deserialized.
302 */
303TSS2_RC
304ifapi_json_TPMS_POLICYLOCALITY_deserialize(json_object *jso,
305 TPMS_POLICYLOCALITY *out)
306{
307 json_object *jso2;
308 TSS2_RC r;
309 LOG_TRACE("call");
310 return_if_null(out, "Bad reference.", TSS2_FAPI_RC_BAD_REFERENCE);
311
312 if (!ifapi_get_sub_object(jso, "locality", &jso2)) {
313 LOG_ERROR("Bad value");
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100314 return TSS2_FAPI_RC_BAD_VALUE;
Juergen Repp6da95b02019-10-10 11:46:03 +0200315 }
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100316 r = ifapi_json_TPMA_LOCALITY_deserialize(jso2, &out->locality);
Juergen Repp6da95b02019-10-10 11:46:03 +0200317 return_if_error(r, "BAD VALUE");
318 LOG_TRACE("true");
319 return TSS2_RC_SUCCESS;
320}
321
322/** Deserialize a TPMS_POLICYNV json object.
323 *
324 * @param[in] jso the json object to be deserialized.
325 * @param[out] out the deserialzed binary object.
326 * @retval TSS2_RC_SUCCESS if the function call was a success.
327 * @retval TSS2_FAPI_RC_BAD_VALUE if the json object can't be deserialized.
328 */
329TSS2_RC
330ifapi_json_TPMS_POLICYNV_deserialize(json_object *jso, TPMS_POLICYNV *out)
331{
332 json_object *jso2;
333 TSS2_RC r;
334 size_t cond_cnt = 0; /**< counter for conditional fields */
335
336 LOG_TRACE("call");
337 return_if_null(out, "Bad reference.", TSS2_FAPI_RC_BAD_REFERENCE);
338
339 if (!ifapi_get_sub_object(jso, "nvPath", &jso2)) {
340 out->nvPath = NULL;
341 } else {
342 cond_cnt++;
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100343 r = ifapi_json_char_deserialize(jso2, &out->nvPath);
Juergen Repp6da95b02019-10-10 11:46:03 +0200344 return_if_error(r, "BAD VALUE");
345 }
346
347 if (!ifapi_get_sub_object(jso, "nvIndex", &jso2)) {
348 out->nvIndex = 0;
349 } else {
350 cond_cnt++;
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100351 r = ifapi_json_TPMI_RH_NV_INDEX_deserialize(jso2, &out->nvIndex);
Juergen Repp6da95b02019-10-10 11:46:03 +0200352 return_if_error(r, "BAD VALUE");
353 }
354
355 if (!ifapi_get_sub_object(jso, "nvPublic", &jso2)) {
356 memset(&out->nvPublic, 0, sizeof(TPM2B_NV_PUBLIC));
357 } else {
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100358 r = ifapi_json_TPM2B_NV_PUBLIC_deserialize(jso2, &out->nvPublic);
Juergen Repp6da95b02019-10-10 11:46:03 +0200359 return_if_error(r, "BAD VALUE");
360 }
361
362 if (!ifapi_get_sub_object(jso, "operandB", &jso2)) {
363 LOG_ERROR("Bad value");
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100364 return TSS2_FAPI_RC_BAD_VALUE;
Juergen Repp6da95b02019-10-10 11:46:03 +0200365 }
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100366 r = ifapi_json_TPM2B_OPERAND_deserialize(jso2, &out->operandB);
Juergen Repp6da95b02019-10-10 11:46:03 +0200367 return_if_error(r, "BAD VALUE");
368
369 if (!ifapi_get_sub_object(jso, "offset", &jso2)) {
370 out->offset = 0;
371 } else {
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100372 r = ifapi_json_UINT16_deserialize(jso2, &out->offset);
Juergen Repp6da95b02019-10-10 11:46:03 +0200373 return_if_error(r, "BAD VALUE");
374 }
375
376 if (!ifapi_get_sub_object(jso, "operation", &jso2)) {
377 out->operation = 0;
378 } else {
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100379 r = ifapi_json_TPM2_EO_deserialize(jso2, &out->operation);
Juergen Repp6da95b02019-10-10 11:46:03 +0200380 return_if_error(r, "BAD VALUE");
381 }
382 /* Check whether only one conditional is used. */
383 if (cond_cnt != 1) {
384 return_error(TSS2_FAPI_RC_BAD_TEMPLATE,
385 "Exactly one conditional is allowed for policy NV.");
386 }
387
388 LOG_TRACE("true");
389 return TSS2_RC_SUCCESS;
390}
391
392/** Deserialize a TPMS_POLICYCOUNTERTIMER json object.
393 *
394 * @param[in] jso the json object to be deserialized.
395 * @param[out] out the deserialzed binary object.
396 * @retval TSS2_RC_SUCCESS if the function call was a success.
397 * @retval TSS2_FAPI_RC_BAD_VALUE if the json object can't be deserialized.
398 */
399TSS2_RC
400ifapi_json_TPMS_POLICYCOUNTERTIMER_deserialize(json_object *jso,
401 TPMS_POLICYCOUNTERTIMER *out)
402{
403 json_object *jso2;
404 TSS2_RC r;
405 LOG_TRACE("call");
406 return_if_null(out, "Bad reference.", TSS2_FAPI_RC_BAD_REFERENCE);
407
408 if (!ifapi_get_sub_object(jso, "operandB", &jso2)) {
409 LOG_ERROR("Bad value");
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100410 return TSS2_FAPI_RC_BAD_VALUE;
Juergen Repp6da95b02019-10-10 11:46:03 +0200411 }
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100412 r = ifapi_json_TPM2B_OPERAND_deserialize(jso2, &out->operandB);
Juergen Repp6da95b02019-10-10 11:46:03 +0200413 return_if_error(r, "BAD VALUE");
414
415 if (!ifapi_get_sub_object(jso, "offset", &jso2)) {
416 out->offset = 0;
417 } else {
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100418 r = ifapi_json_UINT16_deserialize(jso2, &out->offset);
Juergen Repp6da95b02019-10-10 11:46:03 +0200419 return_if_error(r, "BAD VALUE");
420 }
421
422 if (!ifapi_get_sub_object(jso, "operation", &jso2)) {
423 LOG_ERROR("Bad value");
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100424 return TSS2_FAPI_RC_BAD_VALUE;
Juergen Repp6da95b02019-10-10 11:46:03 +0200425 }
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100426 r = ifapi_json_TPM2_EO_deserialize(jso2, &out->operation);
Juergen Repp6da95b02019-10-10 11:46:03 +0200427 return_if_error(r, "BAD VALUE");
428 LOG_TRACE("true");
429 return TSS2_RC_SUCCESS;
430}
431
432/** Deserialize a TPMS_POLICYCOMMANDCODE json object.
433 *
434 * @param[in] jso the json object to be deserialized.
435 * @param[out] out the deserialzed binary object.
436 * @retval TSS2_RC_SUCCESS if the function call was a success.
437 * @retval TSS2_FAPI_RC_BAD_VALUE if the json object can't be deserialized.
438 */
439TSS2_RC
440ifapi_json_TPMS_POLICYCOMMANDCODE_deserialize(json_object *jso,
441 TPMS_POLICYCOMMANDCODE *out)
442{
443 json_object *jso2;
444 TSS2_RC r;
445 LOG_TRACE("call");
446 return_if_null(out, "Bad reference.", TSS2_FAPI_RC_BAD_REFERENCE);
447
448 if (!ifapi_get_sub_object(jso, "code", &jso2)) {
449 LOG_ERROR("Bad value");
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100450 return TSS2_FAPI_RC_BAD_VALUE;
Juergen Repp6da95b02019-10-10 11:46:03 +0200451 }
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100452 r = ifapi_json_TPM2_CC_deserialize(jso2, &out->code);
Juergen Repp6da95b02019-10-10 11:46:03 +0200453 return_if_error(r, "BAD VALUE");
454 LOG_TRACE("true");
455 return TSS2_RC_SUCCESS;
456}
457
458/** Deserialize a TPMS_POLICYPHYSICALPRESENCE json object.
459 *
460 * @param[in] jso the json object to be deserialized.
461 * @param[out] out the deserialzed binary object.
462 * @retval TSS2_RC_SUCCESS if the function call was a success.
463 * @retval TSS2_FAPI_RC_BAD_VALUE if the json object can't be deserialized.
464 */
465TSS2_RC
466ifapi_json_TPMS_POLICYPHYSICALPRESENCE_deserialize(json_object *jso,
467 TPMS_POLICYPHYSICALPRESENCE *out)
468{
469 LOG_TRACE("call");
470 (void)jso;
471 (void)out;
472
473 LOG_TRACE("true");
474 return TSS2_RC_SUCCESS;
475}
476
477/** Deserialize a TPMS_POLICYCPHASH json object.
478 *
479 * @param[in] jso the json object to be deserialized.
480 * @param[out] out the deserialzed binary object.
481 * @retval TSS2_RC_SUCCESS if the function call was a success.
482 * @retval TSS2_FAPI_RC_BAD_VALUE if the json object can't be deserialized.
483 */
484TSS2_RC
485ifapi_json_TPMS_POLICYCPHASH_deserialize(json_object *jso,
486 TPMS_POLICYCPHASH *out)
487{
488 json_object *jso2;
489 TSS2_RC r;
490 LOG_TRACE("call");
491 return_if_null(out, "Bad reference.", TSS2_FAPI_RC_BAD_REFERENCE);
492
493 if (!ifapi_get_sub_object(jso, "cpHash", &jso2)) {
494 LOG_ERROR("Bad value");
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100495 return TSS2_FAPI_RC_BAD_VALUE;
Juergen Repp6da95b02019-10-10 11:46:03 +0200496 }
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100497 r = ifapi_json_TPM2B_DIGEST_deserialize(jso2, &out->cpHash);
Juergen Repp6da95b02019-10-10 11:46:03 +0200498 return_if_error(r, "BAD VALUE");
499 LOG_TRACE("true");
500 return TSS2_RC_SUCCESS;
501}
502
503/** Deserialize a TPMS_POLICYNAMEHASH json object.
504 *
505 * @param[in] jso the json object to be deserialized.
506 * @param[out] out the deserialzed binary object.
507 * @retval TSS2_RC_SUCCESS if the function call was a success.
508 * @retval TSS2_FAPI_RC_BAD_VALUE if the json object can't be deserialized.
509 */
510TSS2_RC
511ifapi_json_TPMS_POLICYNAMEHASH_deserialize(json_object *jso,
512 TPMS_POLICYNAMEHASH *out)
513{
514 json_object *jso2, *jso3;
515 TSS2_RC r;
516 size_t i, n_paths = 0, n_names = 0;
517 size_t cond_cnt = 0; /**< counter for conditional fields */
518
519 LOG_TRACE("call");
520 memset(out, 0, sizeof(TPMS_POLICYNAMEHASH));
521 return_if_null(out, "Bad reference.", TSS2_FAPI_RC_BAD_REFERENCE);
522
523 if (ifapi_get_sub_object(jso, "nameHash", &jso2)) {
524 cond_cnt++;
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100525 r = ifapi_json_TPM2B_DIGEST_deserialize(jso2, &out->nameHash);
Juergen Repp6da95b02019-10-10 11:46:03 +0200526 return_if_error(r, "BAD VALUE");
527
528 /* No need to deserialize namePaths or objectNames from which nameHash would
529 be derived. */
530 return TSS2_RC_SUCCESS;
531 }
532
533 if (ifapi_get_sub_object(jso, "namePaths", &jso2)) {
534 json_type jso_type = json_object_get_type(jso2);
535 cond_cnt++;
536 if (jso_type == json_type_array) {
537 n_paths = json_object_array_length(jso2);
538 if (n_paths > 3) {
539 return_error(TSS2_FAPI_RC_BAD_TEMPLATE,
540 "More than 3 path names in policy name hash.");
541 }
542 for (i = 0; i < n_paths; i++) {
543 jso3 = json_object_array_get_idx(jso2, i);
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100544 r = ifapi_json_char_deserialize(jso3, &out->namePaths[i]);
Juergen Repp6da95b02019-10-10 11:46:03 +0200545 return_if_error(r, "BAD VALUE");
546 }
547 out->count = n_paths;
548 } else {
549 LOG_ERROR("No list of name paths");
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100550 return TSS2_FAPI_RC_BAD_TEMPLATE;
Juergen Repp6da95b02019-10-10 11:46:03 +0200551 }
552
553 }
554 if (ifapi_get_sub_object(jso, "objectNames", &jso2)) {
555 json_type jso_type = json_object_get_type(jso);
556 if (jso_type == json_type_array) {
557 n_names = json_object_array_length(jso2);
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100558 if (n_paths > 0 && n_names > 0) {
Juergen Repp6da95b02019-10-10 11:46:03 +0200559 return_error(TSS2_FAPI_RC_BAD_TEMPLATE,
560 "Only pathname or only TPM names are allowed "
561 "for policy name hash.");
562 }
563 if (n_names > 3) {
564 return_error(TSS2_FAPI_RC_BAD_TEMPLATE,
565 "More than 3 names in policy name hash.");
566 }
567 for (i = 0; i < n_names; i++) {
568 jso3 = json_object_array_get_idx(jso, i);
569 r = ifapi_json_TPM2B_NAME_deserialize(jso3, &out->objectNames[i]);
570 return_if_error(r, "BAD TEMPLATE");
571 }
572 out->count = n_names;
573 } else {
574 LOG_ERROR("No list of object names");
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100575 return TSS2_FAPI_RC_BAD_TEMPLATE;
Juergen Repp6da95b02019-10-10 11:46:03 +0200576 }
577 }
578 if (out->count == 0) {
579 LOG_ERROR("No list of object names or path names");
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100580 return TSS2_FAPI_RC_BAD_TEMPLATE;
Juergen Repp6da95b02019-10-10 11:46:03 +0200581 }
582 /* Check whether only one condition field found in policy. */
583 if (cond_cnt != 1) {
584 return_error(TSS2_FAPI_RC_BAD_TEMPLATE,
585 "Exactly one conditional is allowed for policy name hash.");
586 }
587 return TSS2_RC_SUCCESS;
588}
589
590/** Deserialize a TPMS_POLICYDUPLICATIONSELECT json object.
591 *
592 * @param[in] jso the json object to be deserialized.
593 * @param[out] out the deserialzed binary object.
594 * @retval TSS2_RC_SUCCESS if the function call was a success.
595 * @retval TSS2_FAPI_RC_BAD_VALUE if the json object can't be deserialized.
596 */
597TSS2_RC
598ifapi_json_TPMS_POLICYDUPLICATIONSELECT_deserialize(json_object *jso,
599 TPMS_POLICYDUPLICATIONSELECT *out)
600{
601 json_object *jso2;
602 TSS2_RC r;
603 size_t cond_cnt = 0; /**< counter for conditional fields */
604
605 LOG_TRACE("call");
606 return_if_null(out, "Bad reference.", TSS2_FAPI_RC_BAD_REFERENCE);
607
608 GET_OPTIONAL(objectName, "objectName", TPM2B_NAME);
609 GET_OPTIONAL(newParentName, "newParentName", TPM2B_NAME);
610 if (out->newParentName.size)
611 cond_cnt++;
612 if (ifapi_get_sub_object(jso, "includeObject", &jso2)) {
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100613 r = ifapi_json_TPMI_YES_NO_deserialize(jso2, &out->includeObject);
Juergen Repp6da95b02019-10-10 11:46:03 +0200614 return_if_error(r, "Yes or No expected.");
615 } else {
616 out->includeObject = TPM2_NO;
617 }
618 GET_OPTIONAL(newParentPublic, "newParentPublic", TPM2B_PUBLIC);
619 if (out->newParentPublic.size)
620 cond_cnt++;
621
622 if (!ifapi_get_sub_object(jso, "newParentPath", &jso2)) {
623 if (!out->newParentPublic.publicArea.type) {
624 return_error(TSS2_FAPI_RC_BAD_VALUE, "No path and TPM2B_PUBLIC");
625 }
626 out->newParentPath = NULL;
627 } else {
628 cond_cnt++;
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100629 r = ifapi_json_char_deserialize(jso2, &out->newParentPath);
Juergen Repp6da95b02019-10-10 11:46:03 +0200630 return_if_error(r, "BAD VALUE");
631 }
632 /* Check whether only one condition field found in policy. */
633 if (cond_cnt != 1) {
634 return_error(TSS2_FAPI_RC_BAD_TEMPLATE,
635 "Exactly one conditional is allowed for "
636 "policy duplication select.");
637 }
638 LOG_TRACE("true");
639 return TSS2_RC_SUCCESS;
640}
641
642/** Deserialize a TPMS_POLICYAUTHORIZE json object.
643 *
644 * @param[in] jso the json object to be deserialized.
645 * @param[out] out the deserialzed binary object.
646 * @retval TSS2_RC_SUCCESS if the function call was a success.
647 * @retval TSS2_FAPI_RC_BAD_VALUE if the json object can't be deserialized.
648 */
649TSS2_RC
650ifapi_json_TPMS_POLICYAUTHORIZE_deserialize(json_object *jso,
651 TPMS_POLICYAUTHORIZE *out)
652{
653 json_object *jso2;
654 TSS2_RC r;
655 size_t cond_cnt = 0; /**< counter for conditional fields */
656
657 LOG_TRACE("call");
658 return_if_null(out, "Bad reference.", TSS2_FAPI_RC_BAD_REFERENCE);
659
660 if (!ifapi_get_sub_object(jso, "approvedPolicy", &jso2)) {
661 memset(&out->approvedPolicy, 0, sizeof(TPM2B_DIGEST));
662 } else {
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100663 r = ifapi_json_TPM2B_DIGEST_deserialize(jso2, &out->approvedPolicy);
Juergen Repp6da95b02019-10-10 11:46:03 +0200664 return_if_error(r, "BAD VALUE");
665 }
666
667 if (!ifapi_get_sub_object(jso, "policyRef", &jso2)) {
668 memset(&out->policyRef, 0, sizeof(TPM2B_NONCE));
669 } else {
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100670 r = ifapi_json_TPM2B_NONCE_deserialize(jso2, &out->policyRef);
Juergen Repp6da95b02019-10-10 11:46:03 +0200671 return_if_error(r, "BAD VALUE");
672 }
673
674 if (!ifapi_get_sub_object(jso, "keyName", &jso2)) {
675 memset(&out->keyName, 0, sizeof(TPM2B_NAME));
676 } else {
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100677 r = ifapi_json_TPM2B_NAME_deserialize(jso2, &out->keyName);
Juergen Repp6da95b02019-10-10 11:46:03 +0200678 return_if_error(r, "BAD VALUE");
679 }
680
681 if (!ifapi_get_sub_object(jso, "checkTicket", &jso2)) {
682 memset(&out->checkTicket, 0, sizeof(TPMT_TK_VERIFIED));
683 } else {
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100684 r = ifapi_json_TPMT_TK_VERIFIED_deserialize(jso2, &out->checkTicket);
Juergen Repp6da95b02019-10-10 11:46:03 +0200685 return_if_error(r, "BAD VALUE");
686 }
687
688 if (ifapi_get_sub_object(jso, "keyPath", &jso2)) {
689 cond_cnt++;
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100690 r = ifapi_json_char_deserialize(jso2, &out->keyPath);
Juergen Repp6da95b02019-10-10 11:46:03 +0200691 return_if_error(r, "BAD VALUE");
692 } else {
693 out->keyPath = NULL;
694 }
695
696 if (!ifapi_get_sub_object(jso, "keyPublic", &jso2)) {
697 memset(&out->keyPublic, 0, sizeof(TPMT_PUBLIC));
698 } else {
699 cond_cnt++;
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100700 r = ifapi_json_TPMT_PUBLIC_deserialize(jso2, &out->keyPublic);
Juergen Repp6da95b02019-10-10 11:46:03 +0200701 return_if_error(r, "BAD VALUE");
702 }
703
704 if (!ifapi_get_sub_object(jso, "keyPEM", &jso2)) {
705 out->keyPEM = NULL;
706 } else {
707 cond_cnt++;
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100708 r = ifapi_json_char_deserialize(jso2, &out->keyPEM);
Juergen Repp6da95b02019-10-10 11:46:03 +0200709 return_if_error(r, "BAD VALUE");
710 }
711
712 if (!ifapi_get_sub_object(jso, "keyPEMhashAlg", &jso2)) {
713 out->keyPEMhashAlg = 0;
714 } else {
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100715 r = ifapi_json_TPMI_ALG_HASH_deserialize(jso2, &out->keyPEMhashAlg);
Juergen Repp6da95b02019-10-10 11:46:03 +0200716 return_if_error(r, "BAD VALUE");
717 }
718 /* Check whether only one condition field found in policy. */
719 if (cond_cnt != 1) {
720 return_error(TSS2_FAPI_RC_BAD_TEMPLATE,
721 "Exactly one conditional is allowed for policy authorize.");
722 }
723 LOG_TRACE("true");
724 return TSS2_RC_SUCCESS;
725}
726
727/** Deserialize a TPMS_POLICYAUTHVALUE json object.
728 *
729 * @param[in] jso the json object to be deserialized.
730 * @param[out] out the deserialzed binary object.
731 * @retval TSS2_RC_SUCCESS if the function call was a success.
732 * @retval TSS2_FAPI_RC_BAD_VALUE if the json object can't be deserialized.
733 */
734TSS2_RC
735ifapi_json_TPMS_POLICYAUTHVALUE_deserialize(json_object *jso,
736 TPMS_POLICYAUTHVALUE *out)
737{
738 LOG_TRACE("call");
739 (void)out;
740 (void)jso;
741
742 LOG_TRACE("true");
743 return TSS2_RC_SUCCESS;
744}
745
746/** Deserialize a TPMS_POLICYPASSWORD json object.
747 *
748 * @param[in] jso the json object to be deserialized.
749 * @param[out] out the deserialzed binary object.
750 * @retval TSS2_RC_SUCCESS if the function call was a success.
751 * @retval TSS2_FAPI_RC_BAD_VALUE if the json object can't be deserialized.
752 */
753TSS2_RC
754ifapi_json_TPMS_POLICYPASSWORD_deserialize(json_object *jso,
755 TPMS_POLICYPASSWORD *out)
756{
757 LOG_TRACE("call");
758 (void)jso;
759 (void)out;
760
761 LOG_TRACE("true");
762 return TSS2_RC_SUCCESS;
763}
764
765/** Deserialize a TPMS_POLICYNVWRITTEN json object.
766 *
767 * @param[in] jso the json object to be deserialized.
768 * @param[out] out the deserialzed binary object.
769 * @retval TSS2_RC_SUCCESS if the function call was a success.
770 * @retval TSS2_FAPI_RC_BAD_VALUE if the json object can't be deserialized.
771 */
772TSS2_RC
773ifapi_json_TPMS_POLICYNVWRITTEN_deserialize(json_object *jso,
774 TPMS_POLICYNVWRITTEN *out)
775{
776 json_object *jso2;
777 TSS2_RC r;
778 LOG_TRACE("call");
779 return_if_null(out, "Bad reference.", TSS2_FAPI_RC_BAD_REFERENCE);
780
Juergen Repp6da95b02019-10-10 11:46:03 +0200781 if (!ifapi_get_sub_object(jso, "writtenSet", &jso2)) {
782 out->writtenSet = TPM2_YES;
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100783 return TSS2_RC_SUCCESS;
Juergen Repp6da95b02019-10-10 11:46:03 +0200784 }
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100785 r = ifapi_json_TPMI_YES_NO_deserialize(jso2, &out->writtenSet);
Juergen Repp6da95b02019-10-10 11:46:03 +0200786 return_if_error(r, "BAD VALUE");
787 LOG_TRACE("true");
788 return TSS2_RC_SUCCESS;
789}
790
791/** Deserialize a TPMS_POLICYTEMPLATE json object.
792 *
793 * @param[in] jso the json object to be deserialized.
794 * @param[out] out the deserialzed binary object.
795 * @retval TSS2_RC_SUCCESS if the function call was a success.
796 * @retval TSS2_FAPI_RC_BAD_VALUE if the json object can't be deserialized.
797 */
798TSS2_RC
799ifapi_json_TPMS_POLICYTEMPLATE_deserialize(json_object *jso,
800 TPMS_POLICYTEMPLATE *out)
801{
802 json_object *jso2;
803 TSS2_RC r;
804 size_t cond_cnt = 0; /**< counter for conditional fields */
805
806 LOG_TRACE("call");
807 return_if_null(out, "Bad reference.", TSS2_FAPI_RC_BAD_REFERENCE);
808
809 if (!ifapi_get_sub_object(jso, "templateHash", &jso2)) {
810 memset(&out->templateHash, 0, sizeof(TPM2B_DIGEST));
811 } else {
812 cond_cnt++;
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100813 r = ifapi_json_TPM2B_DIGEST_deserialize(jso2, &out->templateHash);
Juergen Repp6da95b02019-10-10 11:46:03 +0200814 return_if_error(r, "BAD VALUE");
815 }
816
817 if (!ifapi_get_sub_object(jso, "templatePublic", &jso2)) {
818 memset(&out->templatePublic, 0, sizeof(TPM2B_PUBLIC));
819 } else {
820 cond_cnt++;
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100821 r = ifapi_json_TPM2B_PUBLIC_deserialize(jso2, &out->templatePublic);
Juergen Repp6da95b02019-10-10 11:46:03 +0200822 return_if_error(r, "BAD VALUE");
823 }
824
825 if (ifapi_get_sub_object(jso, "templateName", &jso2)) {
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100826 r = ifapi_json_char_deserialize(jso2, &out->templateName);
Juergen Repp6da95b02019-10-10 11:46:03 +0200827 return_if_error(r, "BAD VALUE");
828 } else {
829 out->templateName = NULL;
830 }
831
832 /* Check whether only one condition field found in policy. */
833 if (cond_cnt != 1) {
834 return_error(TSS2_FAPI_RC_BAD_TEMPLATE,
835 "Exactly one conditional is allowed for policy template.");
836 }
837
838 LOG_TRACE("true");
839 return TSS2_RC_SUCCESS;
840}
841
842/** Deserialize a TPMS_POLICYAUTHORIZENV json object.
843 *
844 * @param[in] jso the json object to be deserialized.
845 * @param[out] out the deserialzed binary object.
846 * @retval TSS2_RC_SUCCESS if the function call was a success.
847 * @retval TSS2_FAPI_RC_BAD_VALUE if the json object can't be deserialized.
848 */
849TSS2_RC
850ifapi_json_TPMS_POLICYAUTHORIZENV_deserialize(json_object *jso,
851 TPMS_POLICYAUTHORIZENV *out)
852{
853 json_object *jso2;
854 TSS2_RC r;
855 size_t cond_cnt = 0; /**< counter for conditional fields */
856
857 LOG_TRACE("call");
858 return_if_null(out, "Bad reference.", TSS2_FAPI_RC_BAD_REFERENCE);
859
860 memset(out, 0, sizeof(TPMS_POLICYAUTHORIZENV));
861
862 if (ifapi_get_sub_object(jso, "nvPath", &jso2)) {
863 cond_cnt++;
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100864 r = ifapi_json_char_deserialize(jso2, &out->nvPath);
Juergen Repp6da95b02019-10-10 11:46:03 +0200865 return_if_error(r, "BAD VALUE");
866 } else {
867 out->nvPath = NULL;
868 }
869
870 if (!ifapi_get_sub_object(jso, "nvPublic", &jso2)) {
871 memset(&out->nvPublic, 0, sizeof(TPM2B_NV_PUBLIC));
872 } else {
873 cond_cnt++;
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100874 r = ifapi_json_TPM2B_NV_PUBLIC_deserialize(jso2, &out->nvPublic);
Juergen Repp6da95b02019-10-10 11:46:03 +0200875 return_if_error(r, "BAD VALUE");
876 }
877 /* Check whether only one condition field found in policy. */
878 if (cond_cnt != 1) {
879 return_error(TSS2_FAPI_RC_BAD_TEMPLATE,
880 "Exactly one conditional is allowed for policy signed.");
881 }
882
883 LOG_TRACE("true");
884 return TSS2_RC_SUCCESS;
885}
886
887/** Deserialize a TPMS_POLICYACTION json object.
888 *
889 * @param[in] jso the json object to be deserialized.
890 * @param[out] out the deserialzed binary object.
891 * @retval TSS2_RC_SUCCESS if the function call was a success.
892 * @retval TSS2_FAPI_RC_BAD_VALUE if the json object can't be deserialized.
893 */
894TSS2_RC
895ifapi_json_TPMS_POLICYACTION_deserialize(json_object *jso,
896 TPMS_POLICYACTION *out)
897{
898 json_object *jso2;
899 TSS2_RC r;
900 LOG_TRACE("call");
901 return_if_null(out, "Bad reference.", TSS2_FAPI_RC_BAD_REFERENCE);
902
Andreas Fuchs1e3138a2020-01-21 14:54:59 +0100903 memset(out, 0, sizeof(*out));
Juergen Repp6da95b02019-10-10 11:46:03 +0200904
905 if (!ifapi_get_sub_object(jso, "action", &jso2)) {
906 LOG_ERROR("Bad value");
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100907 return TSS2_FAPI_RC_BAD_VALUE;
Juergen Repp6da95b02019-10-10 11:46:03 +0200908 }
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100909 r = ifapi_json_char_deserialize(jso2, &out->action);
Juergen Repp6da95b02019-10-10 11:46:03 +0200910 return_if_error(r, "BAD VALUE");
911 LOG_TRACE("true");
912 return TSS2_RC_SUCCESS;
913}
914
915/** Deserialize a TPMS_PCRVALUE json object.
916 *
917 * @param[in] jso the json object to be deserialized.
918 * @param[out] out the deserialzed binary object.
919 * @retval TSS2_RC_SUCCESS if the function call was a success.
920 * @retval TSS2_FAPI_RC_BAD_VALUE if the json object can't be deserialized.
921 */
922TSS2_RC
923ifapi_json_TPMS_PCRVALUE_deserialize(json_object *jso, TPMS_PCRVALUE *out)
924{
925 json_object *jso2;
926 TSS2_RC r;
927
928 LOG_TRACE("call");
929 return_if_null(out, "Bad reference.", TSS2_FAPI_RC_BAD_REFERENCE);
930
931 if (!ifapi_get_sub_object(jso, "pcr", &jso2)) {
932 LOG_ERROR("Bad value");
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100933 return TSS2_FAPI_RC_BAD_VALUE;
Juergen Repp6da95b02019-10-10 11:46:03 +0200934 }
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100935 r = ifapi_json_UINT32_deserialize(jso2, &out->pcr);
Juergen Repp6da95b02019-10-10 11:46:03 +0200936 return_if_error(r, "BAD VALUE");
937
938 if (!ifapi_get_sub_object(jso, "hashAlg", &jso2)) {
939 LOG_ERROR("Bad value");
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100940 return TSS2_FAPI_RC_BAD_VALUE;
Juergen Repp6da95b02019-10-10 11:46:03 +0200941 }
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100942 r = ifapi_json_TPM2_ALG_ID_deserialize(jso2, &out->hashAlg);
Juergen Repp6da95b02019-10-10 11:46:03 +0200943 return_if_error(r, "BAD VALUE");
944 if (!ifapi_get_sub_object(jso, "digest", &jso2)) {
945 LOG_ERROR("BAD VALUE");
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100946 return TSS2_FAPI_RC_BAD_VALUE;
Juergen Repp6da95b02019-10-10 11:46:03 +0200947 }
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100948 r = ifapi_json_TPMU_HA_deserialize(out->hashAlg, jso2, &out->digest);
Juergen Repp6da95b02019-10-10 11:46:03 +0200949 return_if_error(r, "BAD VALUE");
950
951 LOG_TRACE("true");
952 return TSS2_RC_SUCCESS;
953}
954
955/** Deserialize a TPML_PCRVALUES json object.
956 *
957 * @param[in] jso the json object to be deserialized.
958 * @param[out] out the deserialzed binary object.
959 * @retval TSS2_RC_SUCCESS if the function call was a success.
960 * @retval TSS2_FAPI_RC_BAD_VALUE if the json object can't be deserialized.
961 */
962TSS2_RC
963ifapi_json_TPML_PCRVALUES_deserialize(json_object *jso, TPML_PCRVALUES **out)
964{
965 json_object *jso2;
966 TSS2_RC r;
967 LOG_TRACE("call");
968 return_if_null(out, "Bad reference.", TSS2_FAPI_RC_BAD_REFERENCE);
969
970 json_type jso_type = json_object_get_type(jso);
971 if (jso_type == json_type_array) {
972 *out = calloc(1, sizeof(TPML_PCRVALUES) +
973 json_object_array_length(jso) * sizeof(TPMS_PCRVALUE));
974 return_if_null(*out, "Out of memory.", TSS2_FAPI_RC_MEMORY);
975
976 (*out)->count = json_object_array_length(jso);
977 for (size_t i = 0; i < (*out)->count; i++) {
978 jso2 = json_object_array_get_idx(jso, i);
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +0100979 r = ifapi_json_TPMS_PCRVALUE_deserialize(jso2, &(*out)->pcrs[i]);
Juergen Repp6da95b02019-10-10 11:46:03 +0200980 return_if_error(r, "TPMS_PCRVALUE_deserialize");
981 }
982 } else {
983 return_error(TSS2_FAPI_RC_BAD_VALUE, "BAD VALUE");
984 }
985 return TSS2_RC_SUCCESS;
986}
987
988/** Deserialize a TPMS_POLICYPCR json object.
989 *
990 * @param[in] jso the json object to be deserialized.
991 * @param[out] out the deserialzed binary object.
992 * @retval TSS2_RC_SUCCESS if the function call was a success.
993 * @retval TSS2_FAPI_RC_BAD_VALUE if the json object can't be deserialized.
994 */
995TSS2_RC
996ifapi_json_TPMS_POLICYPCR_deserialize(json_object *jso, TPMS_POLICYPCR *out)
997{
998 json_object *jso2;
999 TSS2_RC r;
1000 size_t cond_cnt = 0; /**< counter for conditional fields */
1001
1002 LOG_TRACE("call");
1003 return_if_null(out, "Bad reference.", TSS2_FAPI_RC_BAD_REFERENCE);
1004
1005 if (ifapi_get_sub_object(jso, "pcrs", &jso2)) {
1006 cond_cnt++;
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +01001007 r = ifapi_json_TPML_PCRVALUES_deserialize(jso2, &out->pcrs);
Juergen Repp6da95b02019-10-10 11:46:03 +02001008 return_if_error(r, "BAD VALUE");
1009 } else {
1010 memset(&out->pcrs, 0, sizeof(TPML_PCRVALUES));
1011 }
1012
1013 if (ifapi_get_sub_object(jso, "currentPCRs", &jso2)) {
1014 cond_cnt++;
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +01001015 r = ifapi_json_TPMS_PCR_SELECT_deserialize(jso2, &out->currentPCRs);
Juergen Repp6da95b02019-10-10 11:46:03 +02001016 return_if_error(r, "BAD VALUE");
1017 } else {
1018 memset(&out->currentPCRs, 0, sizeof(TPMS_PCR_SELECT));
1019 }
1020
1021 if (ifapi_get_sub_object(jso, "currentPCRandBanks", &jso2)) {
1022 cond_cnt++;
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +01001023 r = ifapi_json_TPML_PCR_SELECTION_deserialize(jso2, &out->currentPCRandBanks);
Juergen Repp6da95b02019-10-10 11:46:03 +02001024 return_if_error(r, "BAD VALUE");
1025 } else {
1026 memset(&out->currentPCRandBanks, 0, sizeof(TPML_PCR_SELECTION));
1027 }
1028
1029 /* Check whether only one conditional is used. */
1030 if (cond_cnt != 1) {
1031 return_error(TSS2_FAPI_RC_BAD_TEMPLATE,
1032 "Exactly one conditional is allowed for policy PCR.");
1033 }
1034
1035 LOG_TRACE("true");
1036 return TSS2_RC_SUCCESS;
1037}
1038
1039/** Deserialize a TPMS_POLICYAUTHORIZATION json object.
1040 *
1041 * @param[in] jso the json object to be deserialized.
1042 * @param[out] out the deserialzed binary object.
1043 * @retval TSS2_RC_SUCCESS if the function call was a success.
1044 * @retval TSS2_FAPI_RC_BAD_VALUE if the json object can't be deserialized.
1045 */
1046TSS2_RC
1047ifapi_json_TPMS_POLICYAUTHORIZATION_deserialize(json_object *jso,
1048 TPMS_POLICYAUTHORIZATION *out)
1049{
1050 json_object *jso2;
1051 TSS2_RC r;
1052 LOG_TRACE("call");
1053 return_if_null(out, "Bad reference.", TSS2_FAPI_RC_BAD_REFERENCE);
1054
Juergen Repp6da95b02019-10-10 11:46:03 +02001055 if (!ifapi_get_sub_object(jso, "type", &jso2)) {
1056 LOG_ERROR("Bad value");
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +01001057 return TSS2_FAPI_RC_BAD_VALUE;
Juergen Repp6da95b02019-10-10 11:46:03 +02001058 }
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +01001059 r = ifapi_json_char_deserialize(jso2, &out->type);
Juergen Repp6da95b02019-10-10 11:46:03 +02001060 return_if_error(r, "BAD VALUE");
1061
1062 if (!ifapi_get_sub_object(jso, "key", &jso2)) {
1063 LOG_ERROR("Bad value");
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +01001064 return TSS2_FAPI_RC_BAD_VALUE;
Juergen Repp6da95b02019-10-10 11:46:03 +02001065 }
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +01001066 r = ifapi_json_TPMT_PUBLIC_deserialize(jso2, &out->key);
Juergen Repp6da95b02019-10-10 11:46:03 +02001067 return_if_error(r, "BAD VALUE");
1068
1069 if (!ifapi_get_sub_object(jso, "policyRef", &jso2)) {
1070 LOG_ERROR("Bad value");
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +01001071 return TSS2_FAPI_RC_BAD_VALUE;
Juergen Repp6da95b02019-10-10 11:46:03 +02001072 }
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +01001073 r = ifapi_json_TPM2B_NONCE_deserialize(jso2, &out->policyRef);
Juergen Repp6da95b02019-10-10 11:46:03 +02001074 return_if_error(r, "BAD VALUE");
1075
1076 if (!ifapi_get_sub_object(jso, "signature", &jso2)) {
1077 LOG_ERROR("Bad value");
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +01001078 return TSS2_FAPI_RC_BAD_VALUE;
Juergen Repp6da95b02019-10-10 11:46:03 +02001079 }
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +01001080 r = ifapi_json_TPMT_SIGNATURE_deserialize(jso2, &out->signature);
Juergen Repp6da95b02019-10-10 11:46:03 +02001081 return_if_error(r, "BAD VALUE");
1082 LOG_TRACE("true");
1083 return TSS2_RC_SUCCESS;
1084}
1085
1086/** Deserialize a TPML_POLICYAUTHORIZATIONS json object.
1087 *
1088 * @param[in] jso the json object to be deserialized.
1089 * @param[out] out the deserialzed binary object.
1090 * @retval TSS2_RC_SUCCESS if the function call was a success.
1091 * @retval TSS2_FAPI_RC_BAD_VALUE if the json object can't be deserialized.
1092 */
1093TSS2_RC
1094ifapi_json_TPML_POLICYAUTHORIZATIONS_deserialize(json_object *jso,
1095 TPML_POLICYAUTHORIZATIONS **out)
1096{
1097 json_object *jso2;
1098 TSS2_RC r = TSS2_RC_SUCCESS;
1099 LOG_TRACE("call");
1100 return_if_null(out, "Bad reference.", TSS2_FAPI_RC_BAD_REFERENCE);
1101
1102 json_type jso_type = json_object_get_type(jso);
1103 if (jso_type == json_type_array) {
1104 *out = calloc(1, sizeof(TPML_POLICYAUTHORIZATIONS) +
1105 json_object_array_length(jso) * sizeof(TPMS_POLICYAUTHORIZATION));
1106 return_if_null(*out, "Out of memory.", TSS2_FAPI_RC_MEMORY);
1107
1108 (*out)->count = json_object_array_length(jso);
1109 for (size_t i = 0; i < (*out)->count; i++) {
1110 jso2 = json_object_array_get_idx(jso, i);
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +01001111 r = ifapi_json_TPMS_POLICYAUTHORIZATION_deserialize(jso2,
Juergen Repp6da95b02019-10-10 11:46:03 +02001112 &(*out)->authorizations[i]);
1113 return_if_error(r, "TPMS_POLICYAUTHORIZATION_deserialize");
1114 }
1115 } else {
1116 return_error(TSS2_FAPI_RC_BAD_VALUE, "BAD VALUE");
1117 }
1118 return TSS2_RC_SUCCESS;
1119}
1120
1121/** Deserialize a TPMS_POLICYBRANCH json object.
1122 *
1123 * @param[in] jso the json object to be deserialized.
1124 * @param[out] out the deserialzed binary object.
1125 * @retval TSS2_RC_SUCCESS if the function call was a success.
1126 * @retval TSS2_FAPI_RC_BAD_VALUE if the json object can't be deserialized.
1127 */
1128TSS2_RC
1129ifapi_json_TPMS_POLICYBRANCH_deserialize(json_object *jso,
1130 TPMS_POLICYBRANCH *out)
1131{
1132 json_object *jso2;
1133 TSS2_RC r;
1134 LOG_TRACE("call");
1135 return_if_null(out, "Bad reference.", TSS2_FAPI_RC_BAD_REFERENCE);
1136
Juergen Repp6da95b02019-10-10 11:46:03 +02001137 if (!ifapi_get_sub_object(jso, "name", &jso2)) {
1138 LOG_ERROR("Bad value");
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +01001139 return TSS2_FAPI_RC_BAD_VALUE;
Juergen Repp6da95b02019-10-10 11:46:03 +02001140 }
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +01001141 r = ifapi_json_char_deserialize(jso2, &out->name);
Juergen Repp6da95b02019-10-10 11:46:03 +02001142 return_if_error(r, "BAD VALUE");
1143
1144 if (!ifapi_get_sub_object(jso, "description", &jso2)) {
1145 LOG_ERROR("Bad value");
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +01001146 return TSS2_FAPI_RC_BAD_VALUE;
Juergen Repp6da95b02019-10-10 11:46:03 +02001147 }
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +01001148 r = ifapi_json_char_deserialize(jso2, &out->description);
Juergen Repp6da95b02019-10-10 11:46:03 +02001149 return_if_error(r, "BAD VALUE");
1150
1151 if (!ifapi_get_sub_object(jso, "policy", &jso2)) {
1152 LOG_ERROR("Bad value");
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +01001153 return TSS2_FAPI_RC_BAD_VALUE;
Juergen Repp6da95b02019-10-10 11:46:03 +02001154 }
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +01001155 r = ifapi_json_TPML_POLICYELEMENTS_deserialize(jso2, &out->policy);
Juergen Repp6da95b02019-10-10 11:46:03 +02001156 return_if_error(r, "BAD VALUE");
1157
1158 if (!ifapi_get_sub_object(jso, "policyDigests", &jso2)) {
1159 memset(&out->policyDigests, 0, sizeof(TPML_DIGEST_VALUES));
1160 } else {
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +01001161 r = ifapi_json_TPML_DIGEST_VALUES_deserialize(jso2, &out->policyDigests);
Juergen Repp6da95b02019-10-10 11:46:03 +02001162 return_if_error(r, "BAD VALUE");
1163
1164 }
1165
1166 LOG_TRACE("true");
1167 return TSS2_RC_SUCCESS;
1168}
1169
1170/** Deserialize a TPML_POLICYBRANCHES json object.
1171 *
1172 * @param[in] jso the json object to be deserialized.
1173 * @param[out] out the deserialzed binary object.
1174 * @retval TSS2_RC_SUCCESS if the function call was a success.
1175 * @retval TSS2_FAPI_RC_BAD_VALUE if the json object can't be deserialized.
1176 */
1177TSS2_RC
1178ifapi_json_TPML_POLICYBRANCHES_deserialize(json_object *jso,
1179 TPML_POLICYBRANCHES **out)
1180{
1181 json_object *jso2;
1182 TSS2_RC r;
1183 LOG_TRACE("call");
1184 return_if_null(out, "Bad reference.", TSS2_FAPI_RC_BAD_REFERENCE);
1185
1186 json_type jso_type = json_object_get_type(jso);
1187 if (jso_type == json_type_array) {
1188 *out = calloc(1, sizeof(TPML_POLICYBRANCHES) +
1189 json_object_array_length(jso) * sizeof(TPMS_POLICYBRANCH));
1190 return_if_null(*out, "Out of memory.", TSS2_FAPI_RC_MEMORY);
1191
1192 (*out)->count = json_object_array_length(jso);
1193 for (size_t i = 0; i < (*out)->count; i++) {
1194 jso2 = json_object_array_get_idx(jso, i);
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +01001195 r = ifapi_json_TPMS_POLICYBRANCH_deserialize(jso2, &(*out)->authorizations[i]);
Juergen Repp6da95b02019-10-10 11:46:03 +02001196 return_if_error(r, "TPMS_POLICYBRANCH_deserialize");
1197 }
1198 } else {
1199 return_error(TSS2_FAPI_RC_BAD_VALUE, "BAD VALUE");
1200 }
1201 return TSS2_RC_SUCCESS;
1202}
1203
1204/** Deserialize a TPMS_POLICYOR json object.
1205 *
1206 * @param[in] jso the json object to be deserialized.
1207 * @param[out] out the deserialzed binary object.
1208 * @retval TSS2_RC_SUCCESS if the function call was a success.
1209 * @retval TSS2_FAPI_RC_BAD_VALUE if the json object can't be deserialized.
1210 */
1211TSS2_RC
1212ifapi_json_TPMS_POLICYOR_deserialize(json_object *jso, TPMS_POLICYOR *out)
1213{
1214 json_object *jso2;
1215 TSS2_RC r;
1216 LOG_TRACE("call");
1217 return_if_null(out, "Bad reference.", TSS2_FAPI_RC_BAD_REFERENCE);
1218
1219 if (!ifapi_get_sub_object(jso, "branches", &jso2)) {
1220 LOG_ERROR("Bad value");
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +01001221 return TSS2_FAPI_RC_BAD_VALUE;
Juergen Repp6da95b02019-10-10 11:46:03 +02001222 }
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +01001223 r = ifapi_json_TPML_POLICYBRANCHES_deserialize(jso2, &out->branches);
Juergen Repp6da95b02019-10-10 11:46:03 +02001224 return_if_error(r, "BAD VALUE");
1225 LOG_TRACE("true");
1226 return TSS2_RC_SUCCESS;
1227}
1228
1229/** Deserialize a TPMU_POLICYELEMENT json object.
1230 *
1231 * This functions expects the Bitfield to be encoded as unsigned int in host-endianess.
1232 * @param[in] jso the json object to be deserialized.
1233 * @param[out] out the deserialzed binary object.
1234 * @retval TSS2_RC_SUCCESS if the function call was a success.
1235 * @retval TSS2_FAPI_RC_BAD_VALUE if the json object can't be deserialized.
1236 */
1237TSS2_RC
1238ifapi_json_TPMU_POLICYELEMENT_deserialize(
1239 UINT32 selector,
1240 json_object *jso,
1241 TPMU_POLICYELEMENT *out)
1242{
1243 LOG_TRACE("call");
1244 switch (selector) {
1245 case POLICYOR:
1246 return ifapi_json_TPMS_POLICYOR_deserialize(jso, &out->PolicyOr);
1247 case POLICYSIGNED:
1248 return ifapi_json_TPMS_POLICYSIGNED_deserialize(jso, &out->PolicySigned);
1249 case POLICYSECRET:
1250 return ifapi_json_TPMS_POLICYSECRET_deserialize(jso, &out->PolicySecret);
1251 case POLICYPCR:
1252 return ifapi_json_TPMS_POLICYPCR_deserialize(jso, &out->PolicyPCR);
1253 case POLICYLOCALITY:
1254 return ifapi_json_TPMS_POLICYLOCALITY_deserialize(jso, &out->PolicyLocality);
1255 case POLICYNV:
1256 return ifapi_json_TPMS_POLICYNV_deserialize(jso, &out->PolicyNV);
1257 case POLICYCOUNTERTIMER:
1258 return ifapi_json_TPMS_POLICYCOUNTERTIMER_deserialize(jso,
1259 &out->PolicyCounterTimer);
1260 case POLICYCOMMANDCODE:
1261 return ifapi_json_TPMS_POLICYCOMMANDCODE_deserialize(jso,
1262 &out->PolicyCommandCode);
1263 case POLICYPHYSICALPRESENCE:
1264 return ifapi_json_TPMS_POLICYPHYSICALPRESENCE_deserialize(jso,
1265 &out->PolicyPhysicalPresence);
1266 case POLICYCPHASH:
1267 return ifapi_json_TPMS_POLICYCPHASH_deserialize(jso, &out->PolicyCpHash);
1268 case POLICYNAMEHASH:
1269 return ifapi_json_TPMS_POLICYNAMEHASH_deserialize(jso, &out->PolicyNameHash);
1270 case POLICYDUPLICATIONSELECT:
1271 return ifapi_json_TPMS_POLICYDUPLICATIONSELECT_deserialize(jso,
1272 &out->PolicyDuplicationSelect);
1273 case POLICYAUTHORIZE:
1274 return ifapi_json_TPMS_POLICYAUTHORIZE_deserialize(jso, &out->PolicyAuthorize);
1275 case POLICYAUTHVALUE:
1276 return ifapi_json_TPMS_POLICYAUTHVALUE_deserialize(jso, &out->PolicyAuthValue);
1277 case POLICYPASSWORD:
1278 return ifapi_json_TPMS_POLICYPASSWORD_deserialize(jso, &out->PolicyPassword);
1279 case POLICYNVWRITTEN:
1280 return ifapi_json_TPMS_POLICYNVWRITTEN_deserialize(jso, &out->PolicyNvWritten);
1281 case POLICYTEMPLATE:
1282 return ifapi_json_TPMS_POLICYTEMPLATE_deserialize(jso, &out->PolicyTemplate);
1283 case POLICYAUTHORIZENV:
1284 return ifapi_json_TPMS_POLICYAUTHORIZENV_deserialize(jso,
1285 &out->PolicyAuthorizeNv);
1286 case POLICYACTION:
1287 return ifapi_json_TPMS_POLICYACTION_deserialize(jso, &out->PolicyAction);
1288 default:
1289 LOG_TRACE("false");
1290 return TSS2_FAPI_RC_BAD_VALUE;
1291 };
1292}
1293
1294/** Deserialize a TPMT_POLICYELEMENT json object.
1295 *
1296 * @param[in] jso the json object to be deserialized.
1297 * @param[out] out the deserialzed binary object.
1298 * @retval TSS2_RC_SUCCESS if the function call was a success.
1299 * @retval TSS2_FAPI_RC_BAD_VALUE if the json object can't be deserialized.
1300 */
1301TSS2_RC
1302ifapi_json_TPMT_POLICYELEMENT_deserialize(json_object *jso,
1303 TPMT_POLICYELEMENT *out)
1304{
1305 json_object *jso2;
1306 TSS2_RC r;
1307 LOG_TRACE("call");
1308 return_if_null(out, "Bad reference.", TSS2_FAPI_RC_BAD_REFERENCE);
1309
Juergen Repp6da95b02019-10-10 11:46:03 +02001310 if (!ifapi_get_sub_object(jso, "type", &jso2)) {
1311 LOG_ERROR("Bad value");
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +01001312 return TSS2_FAPI_RC_BAD_VALUE;
Juergen Repp6da95b02019-10-10 11:46:03 +02001313 }
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +01001314 r = ifapi_json_TPMI_POLICYTYPE_deserialize(jso2, &out->type);
Juergen Repp6da95b02019-10-10 11:46:03 +02001315 return_if_error(r, "BAD VALUE");
1316
1317 if (!ifapi_get_sub_object(jso, "policyDigests", &jso2)) {
1318 memset(&out->policyDigests, 0, sizeof(TPML_DIGEST_VALUES));
1319 } else {
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +01001320 r = ifapi_json_TPML_DIGEST_VALUES_deserialize(jso2, &out->policyDigests);
Juergen Repp6da95b02019-10-10 11:46:03 +02001321 return_if_error(r, "BAD VALUE");
1322
1323 }
1324 r = ifapi_json_TPMU_POLICYELEMENT_deserialize(out->type, jso, &out->element);
1325 return_if_error(r, "BAD VALUE");
1326
1327 LOG_TRACE("true");
1328 return TSS2_RC_SUCCESS;
1329}
1330
1331/** Deserialize a TPML_POLICYELEMENTS json object.
1332 *
1333 * @param[in] jso the json object to be deserialized.
1334 * @param[out] out the deserialzed binary object.
1335 * @retval TSS2_RC_SUCCESS if the function call was a success.
1336 * @retval TSS2_FAPI_RC_BAD_VALUE if the json object can't be deserialized.
1337 */
1338TSS2_RC
1339ifapi_json_TPML_POLICYELEMENTS_deserialize(json_object *jso,
1340 TPML_POLICYELEMENTS **out)
1341{
1342 json_object *jso2;
1343 TSS2_RC r;
1344 LOG_TRACE("call");
1345 return_if_null(out, "Bad reference.", TSS2_FAPI_RC_BAD_REFERENCE);
1346
1347 json_type jso_type = json_object_get_type(jso);
1348 if (jso_type == json_type_array) {
1349 *out = calloc(1, sizeof(TPML_POLICYELEMENTS) +
1350 json_object_array_length(jso) * sizeof(TPMT_POLICYELEMENT));
1351 return_if_null(*out, "Out of memory.", TSS2_FAPI_RC_MEMORY);
1352
1353 (*out)->count = json_object_array_length(jso);
1354 for (size_t i = 0; i < (*out)->count; i++) {
1355 jso2 = json_object_array_get_idx(jso, i);
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +01001356 r = ifapi_json_TPMT_POLICYELEMENT_deserialize(jso2, &(*out)->elements[i]);
Juergen Repp6da95b02019-10-10 11:46:03 +02001357 return_if_error(r, "TPMT_POLICYELEMENT_deserialize");
1358 }
1359 } else {
1360 return_error(TSS2_FAPI_RC_BAD_VALUE, "BAD VALUE");
1361 }
1362 return TSS2_RC_SUCCESS;
1363}
1364
Andreas Fuchs02427f82020-01-31 15:14:21 +01001365/** Deserialize a TPMS_POLICY json object.
Juergen Repp6da95b02019-10-10 11:46:03 +02001366 *
1367 * @param[in] jso the json object to be deserialized.
1368 * @param[out] out the deserialzed binary object.
1369 * @retval TSS2_RC_SUCCESS if the function call was a success.
1370 * @retval TSS2_FAPI_RC_BAD_VALUE if the json object can't be deserialized.
1371 */
1372TSS2_RC
Andreas Fuchs02427f82020-01-31 15:14:21 +01001373ifapi_json_TPMS_POLICY_deserialize(json_object *jso,
1374 TPMS_POLICY *out)
Juergen Repp6da95b02019-10-10 11:46:03 +02001375{
1376 json_object *jso2;
1377 TSS2_RC r;
1378 LOG_TRACE("call");
1379 return_if_null(out, "Bad reference.", TSS2_FAPI_RC_BAD_REFERENCE);
1380
1381 if (!ifapi_get_sub_object(jso, "description", &jso2)) {
1382 LOG_ERROR("No description for policy.");
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +01001383 return TSS2_FAPI_RC_BAD_VALUE;
Juergen Repp6da95b02019-10-10 11:46:03 +02001384 }
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +01001385 r = ifapi_json_char_deserialize(jso2, &out->description);
Juergen Repp6da95b02019-10-10 11:46:03 +02001386 return_if_error(r, "BAD VALUE");
1387
1388 if (!ifapi_get_sub_object(jso, "policyDigests", &jso2)) {
1389 memset(&out->policyDigests, 0, sizeof(TPML_DIGEST_VALUES));
1390 } else {
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +01001391 r = ifapi_json_TPML_DIGEST_VALUES_deserialize(jso2, &out->policyDigests);
Juergen Repp6da95b02019-10-10 11:46:03 +02001392 return_if_error(r, "BAD VALUE");
1393
1394 }
1395 if (!ifapi_get_sub_object(jso, "policyAuthorizations", &jso2)) {
1396 memset(&out->policyAuthorizations, 0, sizeof(TPML_POLICYAUTHORIZATIONS));
1397 } else {
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +01001398 r = ifapi_json_TPML_POLICYAUTHORIZATIONS_deserialize(jso2,
Juergen Repp6da95b02019-10-10 11:46:03 +02001399 &out->policyAuthorizations);
1400 return_if_error(r, "BAD VALUE");
1401
1402 }
1403 if (!ifapi_get_sub_object(jso, "policy", &jso2)) {
1404 LOG_ERROR("Bad value");
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +01001405 return TSS2_FAPI_RC_BAD_VALUE;
Juergen Repp6da95b02019-10-10 11:46:03 +02001406 }
Andreas Fuchs1f7fc3c2020-01-31 14:13:09 +01001407 r = ifapi_json_TPML_POLICYELEMENTS_deserialize(jso2, &out->policy);
Juergen Repp6da95b02019-10-10 11:46:03 +02001408 return_if_error(r, "BAD VALUE");
1409 LOG_TRACE("true");
1410 return TSS2_RC_SUCCESS;
1411}