summaryrefslogtreecommitdiff
path: root/examples/setpin.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/setpin.c')
-rw-r--r--examples/setpin.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/examples/setpin.c b/examples/setpin.c
new file mode 100644
index 0000000..75d3d4a
--- /dev/null
+++ b/examples/setpin.c
@@ -0,0 +1,59 @@
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 * Configure a PIN 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
22static void
23setpin(const char *path, const char *pin, const char *oldpin)
24{
25 fido_dev_t *dev;
26 int r;
27
28 fido_init(0);
29
30 if ((dev = fido_dev_new()) == NULL)
31 errx(1, "fido_dev_new");
32
33 if ((r = fido_dev_open(dev, path)) != FIDO_OK)
34 errx(1, "fido_dev_open: %s (0x%x)", fido_strerr(r), r);
35
36 if ((r = fido_dev_set_pin(dev, pin, oldpin)) != FIDO_OK)
37 errx(1, "fido_setpin: %s (0x%x)", fido_strerr(r), r);
38
39 if ((r = fido_dev_close(dev)) != FIDO_OK)
40 errx(1, "fido_dev_close: %s (0x%x)", fido_strerr(r), r);
41
42 fido_dev_free(&dev);
43}
44
45int
46main(int argc, char **argv)
47{
48 if (argc < 3 || argc > 4) {
49 fprintf(stderr, "usage: setpin <pin> [oldpin] <device>\n");
50 exit(EXIT_FAILURE);
51 }
52
53 if (argc == 3)
54 setpin(argv[2], argv[1], NULL);
55 else
56 setpin(argv[3], argv[1], argv[2]);
57
58 exit(0);
59}