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:
30
tools/pin.c
30
tools/pin.c
@@ -78,42 +78,34 @@ out:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int pin_set2(char* path, const char* pin1)
|
int pin_set2(char *path, const char *pin1) {
|
||||||
{
|
fido_dev_t *dev = NULL;
|
||||||
fido_dev_t* dev = NULL;
|
int r, status = 1;
|
||||||
int r;
|
|
||||||
int status = 1; // Default to failure
|
|
||||||
|
|
||||||
// Validate the provided PIN length
|
|
||||||
if (strlen(pin1) < 4 || strlen(pin1) > 63) {
|
if (strlen(pin1) < 4 || strlen(pin1) > 63) {
|
||||||
fprintf(stderr, "invalid PIN length\n");
|
fprintf(stderr, "Invalid PIN length\n");
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open the device
|
|
||||||
dev = open_dev(path);
|
dev = open_dev(path);
|
||||||
if (!dev) {
|
if (!dev) {
|
||||||
fprintf(stderr, "Failed to open device\n");
|
fprintf(stderr, "Failed to open device\n");
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the PIN
|
r = fido_dev_set_pin(dev, pin1, NULL);
|
||||||
if ((r = fido_dev_set_pin(dev, pin1, NULL)) != FIDO_OK) {
|
if (r != FIDO_OK) {
|
||||||
warnx("fido_dev_set_pin: %s", fido_strerr(r));
|
fprintf(stderr, "Error setting PIN: %s\n", fido_strerr(r));
|
||||||
}
|
goto out;
|
||||||
else {
|
|
||||||
status = 0; // Success
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup
|
status = 0; // Success
|
||||||
|
out:
|
||||||
if (dev) {
|
if (dev) {
|
||||||
fido_dev_close(dev);
|
fido_dev_close(dev);
|
||||||
fido_dev_free(&dev);
|
fido_dev_free(&dev);
|
||||||
}
|
}
|
||||||
|
explicit_bzero((void *)pin1, strlen(pin1)); // Clear PIN from memory
|
||||||
// Explicitly clear the PIN from memory
|
|
||||||
explicit_bzero((void*)pin1, strlen(pin1));
|
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user