Skip to content

Commit

Permalink
tpm2_policylocality: libyaml support
Browse files Browse the repository at this point in the history
Signed-off-by: Bill Roberts <[email protected]>
  • Loading branch information
williamcroberts committed Dec 13, 2023
1 parent db0becc commit 022172a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
27 changes: 15 additions & 12 deletions lib/tpm2_policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -727,18 +727,21 @@ tool_rc tpm2_policy_tool_finish(ESYS_CONTEXT *ectx, tpm2_yaml *y, tpm2_session *
return rc;
}

char *h = tpm2_util_bin2hex(policy_digest->buffer, policy_digest->size);
if (!h) {
LOG_ERR("oom");
return tool_rc_general_error;
}
rc = tpm2_yaml_hex_string(h, y);
if (rc != tool_rc_success) {
LOG_ERR("Could not create yaml string");
free(h);
return rc;
}
free(h);
// TODO DO WE ALLOW SCALAR VALUES
rc = tpm2_yaml_tpm2b_digest(policy_digest, y);

// char *h = tpm2_util_bin2hex(policy_digest->buffer, policy_digest->size);
// if (!h) {
// LOG_ERR("oom");
// return tool_rc_general_error;
// }
// rc = tpm2_yaml_hex_string(h, y);
// if (rc != tool_rc_success) {
// LOG_ERR("Could not create yaml string");
// free(h);
// return rc;
// }
// free(h);

rc = tool_rc_general_error;

Expand Down
12 changes: 6 additions & 6 deletions lib/tpm2_yaml.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct list {
uint64_t as_int;
} value;
unsigned base;
const yaml_char_t *tag;
yaml_char_t *tag;
};

tpm2_yaml *tpm2_yaml_new(int canonical) {
Expand Down Expand Up @@ -325,7 +325,7 @@ static int tpms_time_info_to_yaml(tpm2_yaml *y, int root,
clock_info, ARRAY_LEN(clock_info));
}

static tool_rc tpm2b_to_yaml(tpm2_yaml *y, int root, const char *key, const TPM2B_NAME *name) {
static tool_rc tpm2b_to_yaml(tpm2_yaml *y, int root, const char *key, const TPM2B *name) {

struct key_value key_bits = KVP_ADD_TPM2B(key, name);
int rc = add_kvp(y, root, &key_bits);
Expand All @@ -338,11 +338,11 @@ tool_rc tpm2_yaml_tpm2b_name(const TPM2B_NAME *name, tpm2_yaml *y) {
return tpm2b_to_yaml(y, y->root, "name", name);
}

tool_rc tpm2_yaml_hex_string(const char *hex, tpm2_yaml *y) {
tool_rc tpm2_yaml_tpm2b_digest(const TPM2B_DIGEST *data, tpm2_yaml *y) {
null_ret(y, 1);
assert(hex);
int rc = yaml_add_str(y, hex);
return rc ? tool_rc_success : tool_rc_general_error;
assert(data);
return tpm2b_to_yaml(y, y->root, "digest", data) ?
tool_rc_success : tool_rc_general_error;
}

tool_rc tpm2_yaml_qualified_name(const TPM2B_NAME *qname, tpm2_yaml *y) {
Expand Down
4 changes: 2 additions & 2 deletions lib/tpm2_yaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ tpm2_yaml *tpm2_yaml_new(int canonical);

void tpm2_yaml_free(tpm2_yaml *y);

tool_rc tpm2_yaml_tpm2b_name(const TPM2B_NAME *name, tpm2_yaml *y);
tool_rc tpm2_yaml_tpm2b_digest(const TPM2B_DIGEST *data, tpm2_yaml *y);

tool_rc tpm2_yaml_hex_string(const char *hex, tpm2_yaml *y);
tool_rc tpm2_yaml_tpm2b_name(const TPM2B_NAME *name, tpm2_yaml *y);

tool_rc tpm2_yaml_qualified_name(const TPM2B_NAME *qname, tpm2_yaml *y);

Expand Down

0 comments on commit 022172a

Please sign in to comment.