mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-04-09 12:01:15 +00:00
Add cli option for changing an entry pin
This commit is contained in:
parent
2f61c447a9
commit
275c99bc4e
11
keyring.c
11
keyring.c
@ -1552,6 +1552,17 @@ int keyring_set_did(keyring_identity *id, const char *did, const char *name)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int keyring_set_pin(keyring_identity *id, const char *pin)
|
||||
{
|
||||
if (id->PKRPin){
|
||||
free(id->PKRPin);
|
||||
id->PKRPin = NULL;
|
||||
}
|
||||
if (pin && *pin)
|
||||
id->PKRPin = str_edup(pin);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int keyring_unpack_tag(const unsigned char *packed, size_t packed_len, const char **name, const unsigned char **value, size_t *length)
|
||||
{
|
||||
size_t i;
|
||||
|
@ -118,6 +118,7 @@ keyring_file *keyring_open_instance(const char *pin);
|
||||
keyring_file *keyring_open_instance_cli(const struct cli_parsed *parsed);
|
||||
int keyring_enter_pin(keyring_file *k, const char *pin);
|
||||
int keyring_set_did(keyring_identity *id, const char *did, const char *name);
|
||||
int keyring_set_pin(keyring_identity *id, const char *pin);
|
||||
int keyring_sign_message(struct keyring_identity *identity, unsigned char *content, size_t buffer_len, size_t *content_len);
|
||||
int keyring_send_identity_request(struct subscriber *subscriber);
|
||||
|
||||
|
@ -260,17 +260,17 @@ static int app_keyring_add(const struct cli_parsed *parsed, struct cli_context *
|
||||
|
||||
DEFINE_CMD(app_keyring_set_did, 0,
|
||||
"Set the DID for the specified SID (must supply PIN to unlock the SID record in the keyring)",
|
||||
"keyring", "set","did" KEYRING_PIN_OPTIONS,"<sid>","<did>","<name>");
|
||||
"keyring", "set","did" KEYRING_PIN_OPTIONS,"<sid>","<did>","<name>", "[<new_pin>]");
|
||||
static int app_keyring_set_did(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
{
|
||||
DEBUG_cli_parsed(verbose, parsed);
|
||||
const char *sidhex, *did, *name;
|
||||
const char *sidhex, *did, *name, *new_pin;
|
||||
|
||||
if (cli_arg(parsed, "sid", &sidhex, str_is_subscriber_id, "") == -1 ||
|
||||
cli_arg(parsed, "did", &did, cli_optional_did, "") == -1 ||
|
||||
cli_arg(parsed, "name", &name, NULL, "") == -1)
|
||||
return -1;
|
||||
|
||||
int set_pin = cli_arg(parsed, "new_pin", &new_pin, NULL, "") == 0;
|
||||
if (strlen(name)>63)
|
||||
return WHY("Name too long (31 char max)");
|
||||
|
||||
@ -289,17 +289,14 @@ static int app_keyring_set_did(const struct cli_parsed *parsed, struct cli_conte
|
||||
int r=0;
|
||||
if (!id)
|
||||
r=WHY("No matching SID");
|
||||
else{
|
||||
if (keyring_set_did(id, did, name))
|
||||
else if (keyring_set_did(id, did, name))
|
||||
r=WHY("Could not set DID");
|
||||
else{
|
||||
if (keyring_commit(keyring))
|
||||
r=WHY("Could not write updated keyring record");
|
||||
else{
|
||||
cli_output_identity(context, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (set_pin && keyring_set_pin(id, new_pin))
|
||||
r=WHY("Could not set new pin");
|
||||
else if (keyring_commit(keyring))
|
||||
r=WHY("Could not write updated keyring record");
|
||||
else
|
||||
cli_output_identity(context, id);
|
||||
|
||||
keyring_free(keyring);
|
||||
keyring = NULL;
|
||||
|
@ -116,6 +116,20 @@ test_Pinless() {
|
||||
assert_keyring_list 3
|
||||
}
|
||||
|
||||
doc_KeyringUpdatePin="Change the PIN on an identity"
|
||||
test_KeyringUpdatePin() {
|
||||
executeOk_servald keyring add ''
|
||||
extract_stdout_keyvalue SID sid "$rexp_sid"
|
||||
executeOk_servald keyring list
|
||||
assert_keyring_list 1
|
||||
executeOk_servald keyring set did "$SID" '' '' 'pin'
|
||||
executeOk_servald keyring list
|
||||
assert_keyring_list 0
|
||||
executeOk_servald keyring list --entry-pin 'pin'
|
||||
assert_keyring_list 1
|
||||
}
|
||||
|
||||
|
||||
doc_IdentityPins="No keyring PIN with identity PINs"
|
||||
test_IdentityPins() {
|
||||
executeOk_servald keyring add 'one'
|
||||
|
Loading…
x
Reference in New Issue
Block a user