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) {
|
int pin_set2(char *path, const char *pin1) {
|
||||||
fido_dev_t *dev = NULL;
|
fido_dev_t *dev = NULL;
|
||||||
|
char mutable_pin[64]; // Temporary buffer for mutable PIN
|
||||||
int r, status = 1;
|
int r, status = 1;
|
||||||
|
|
||||||
if (strlen(pin1) < 4 || strlen(pin1) > 63) {
|
if (strlen(pin1) < 4 || strlen(pin1) > 63) {
|
||||||
@@ -87,28 +88,36 @@ out:
|
|||||||
return status;
|
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);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = fido_dev_set_pin(dev, pin1, NULL);
|
r = fido_dev_set_pin(dev, mutable_pin, NULL);
|
||||||
if (r != FIDO_OK) {
|
if (r != FIDO_OK) {
|
||||||
fprintf(stderr, "Error setting PIN: %s\n", fido_strerr(r));
|
fprintf(stderr, "Error setting PIN: %s\n", fido_strerr(r));
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = 0; // Success
|
status = 0; // Success
|
||||||
|
|
||||||
out:
|
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
|
|
||||||
|
// Clear the PIN from memory
|
||||||
|
explicit_bzero(mutable_pin, sizeof(mutable_pin));
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
pin_change(char *path)
|
pin_change(char *path)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user