1 /* 2 * Copyright (c) 2018 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 <openssl/ec.h> 12 13 #include <stdbool.h> 14 #include <stdint.h> 15 #include <stdio.h> 16 #include <stdlib.h> 17 18 #include "../openbsd-compat/openbsd-compat.h" 19 20 #include "fido.h" 21 #include "extern.h" 22 23 #ifdef SIGNAL_EXAMPLE 24 extern volatile sig_atomic_t got_signal; 25 #endif 26 27 int 28 main(int argc, char **argv) 29 { 30 fido_dev_t *dev; 31 int r; 32 33 if (argc != 2) { 34 fprintf(stderr, "usage: reset <device>\n"); 35 exit(EXIT_FAILURE); 36 } 37 38 fido_init(0); 39 40 if ((dev = fido_dev_new()) == NULL) 41 errx(1, "fido_dev_new"); 42 43 if ((r = fido_dev_open(dev, argv[1])) != FIDO_OK) 44 errx(1, "fido_dev_open: %s (0x%x)", fido_strerr(r), r); 45 46 #ifdef SIGNAL_EXAMPLE 47 prepare_signal_handler(SIGINT); 48 #endif 49 50 if ((r = fido_dev_reset(dev)) != FIDO_OK) { 51 #ifdef SIGNAL_EXAMPLE 52 if (got_signal) 53 fido_dev_cancel(dev); 54 #endif 55 errx(1, "fido_reset: %s (0x%x)", fido_strerr(r), r); 56 } 57 58 if ((r = fido_dev_close(dev)) != FIDO_OK) 59 errx(1, "fido_dev_close: %s (0x%x)", fido_strerr(r), r); 60 61 fido_dev_free(&dev); 62 63 exit(0); 64 } 65