1 /* 2 * Copyright (c) 2018-2021 Yubico AB. All rights reserved. 3 * Use of this source code is governed by a BSD-style 4 * license that can be found in the LICENSE file. 5 */ 6 7 /* 8 * Perform a factory reset on a given authenticator. 9 */ 10 11 #include <fido.h> 12 #include <stdio.h> 13 #include <stdlib.h> 14 15 #include "../openbsd-compat/openbsd-compat.h" 16 #include "extern.h" 17 18 int 19 main(int argc, char **argv) 20 { 21 fido_dev_t *dev; 22 int r; 23 24 if (argc != 2) { 25 fprintf(stderr, "usage: reset <device>\n"); 26 exit(EXIT_FAILURE); 27 } 28 29 fido_init(0); 30 31 if ((dev = fido_dev_new()) == NULL) 32 errx(1, "fido_dev_new"); 33 34 if ((r = fido_dev_open(dev, argv[1])) != FIDO_OK) 35 errx(1, "fido_dev_open: %s (0x%x)", fido_strerr(r), r); 36 37 if ((r = fido_dev_reset(dev)) != FIDO_OK) { 38 fido_dev_cancel(dev); 39 errx(1, "fido_dev_reset: %s (0x%x)", fido_strerr(r), r); 40 } 41 42 if ((r = fido_dev_close(dev)) != FIDO_OK) 43 errx(1, "fido_dev_close: %s (0x%x)", fido_strerr(r), r); 44 45 fido_dev_free(&dev); 46 47 exit(0); 48 } 49