mirror of
https://github.com/token2/fido2-manage.git
synced 2026-04-09 10:45:39 +00:00
Update pin.c
This commit is contained in:
13
tools/pin.c
13
tools/pin.c
@@ -80,6 +80,7 @@ out:
|
||||
|
||||
int pin_set2(char *path, const char *pin1) {
|
||||
fido_dev_t *dev = NULL;
|
||||
char mutable_pin[64]; // Temporary buffer for mutable PIN
|
||||
int r, status = 1;
|
||||
|
||||
if (strlen(pin1) < 4 || strlen(pin1) > 63) {
|
||||
@@ -87,28 +88,36 @@ out:
|
||||
return status;
|
||||
}
|
||||
|
||||
// Copy the PIN to a mutable buffer
|
||||
strncpy(mutable_pin, pin1, sizeof(mutable_pin) - 1);
|
||||
mutable_pin[sizeof(mutable_pin) - 1] = '\0'; // Null-terminate
|
||||
|
||||
dev = open_dev(path);
|
||||
if (!dev) {
|
||||
fprintf(stderr, "Failed to open device\n");
|
||||
return status;
|
||||
}
|
||||
|
||||
r = fido_dev_set_pin(dev, pin1, NULL);
|
||||
r = fido_dev_set_pin(dev, mutable_pin, NULL);
|
||||
if (r != FIDO_OK) {
|
||||
fprintf(stderr, "Error setting PIN: %s\n", fido_strerr(r));
|
||||
goto out;
|
||||
}
|
||||
|
||||
status = 0; // Success
|
||||
|
||||
out:
|
||||
if (dev) {
|
||||
fido_dev_close(dev);
|
||||
fido_dev_free(&dev);
|
||||
}
|
||||
explicit_bzero((void *)pin1, strlen(pin1)); // Clear PIN from memory
|
||||
|
||||
// Clear the PIN from memory
|
||||
explicit_bzero(mutable_pin, sizeof(mutable_pin));
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
pin_change(char *path)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user