diff --git a/tools/pin.c b/tools/pin.c index 8b2697e..4549757 100644 --- a/tools/pin.c +++ b/tools/pin.c @@ -77,6 +77,46 @@ out: exit(status); } + +int pin_set2(char* path, const char* pin1) +{ + fido_dev_t* dev = NULL; + int r; + int status = 1; // Default to failure + + // Validate the provided PIN length + if (strlen(pin1) < 4 || strlen(pin1) > 63) { + 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 + } + + // Cleanup + if (dev) { + fido_dev_close(dev); + fido_dev_free(&dev); + } + + // Explicitly clear the PIN from memory + explicit_bzero((void*)pin1, strlen(pin1)); + + return status; +} + int pin_change(char *path) {