Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add get-metadata action #440

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tool/cmdline.ggo
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ option "action" a "Action to take" values="version","generate","set-mgm-key",
"request-certificate","verify-pin","change-pin","change-puk","unblock-pin",
"selfsign-certificate","delete-certificate","read-certificate","status",
"test-signature","test-decipher","list-readers","set-ccc","write-object",
"read-object","attest" enum multiple
"read-object","attest","get-metadata" enum multiple
text "
Multiple actions may be given at once and will be executed in order
for example --action=verify-pin --action=request-certificate\n"
Expand Down
30 changes: 30 additions & 0 deletions tool/yubico-piv-tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -2062,6 +2062,30 @@ static bool attest(ykpiv_state *state, enum enum_slot slot,
return ret;
}

static bool get_metadata(ykpiv_state *state, enum enum_slot slot) {
unsigned char data[2048] = {0};
size_t len = sizeof(data);

int key = get_slot_hex(slot);
if (ykpiv_get_metadata(state, key, data, &len) != YKPIV_OK) {
fprintf(stderr, "Failed to get metadata.\n");
return false;
}

ykpiv_metadata md = {0};
if(ykpiv_util_parse_metadata(data, len, &md) != YKPIV_OK) {
fprintf(stderr, "Failed to parse metadata.\n");
return false;
}

printf("Algorithm: %u\n", md.algorithm);
printf("Origin: %u\n", md.origin);
printf("Pin policy: %u\n", md.pin_policy);
printf("Touch policy: %u\n", md.touch_policy);

return true;
}

static bool write_object(ykpiv_state *state, int id,
const char *input_file_name, int verbosity, enum enum_format format) {
bool ret = false;
Expand Down Expand Up @@ -2329,6 +2353,7 @@ int main(int argc, char *argv[]) {
case action_arg_testMINUS_decipher:
case action_arg_listMINUS_readers:
case action_arg_attest:
case action_arg_getMINUS_metadata:
case action_arg_readMINUS_object:
case action__NULL:
default:
Expand Down Expand Up @@ -2560,6 +2585,11 @@ int main(int argc, char *argv[]) {
ret = EXIT_FAILURE;
}
break;
case action_arg_getMINUS_metadata:
if(get_metadata(state, args_info.slot_arg) == false) {
ret = EXIT_FAILURE;
}
break;
case action__NULL:
default:
fprintf(stderr, "Wrong action. %d.\n", action);
Expand Down