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