diff options
Diffstat (limited to 'tools/cred_make.c')
-rw-r--r-- | tools/cred_make.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/tools/cred_make.c b/tools/cred_make.c index 380c67a..255a488 100644 --- a/tools/cred_make.c +++ b/tools/cred_make.c | |||
@@ -130,11 +130,16 @@ cred_make(int argc, char **argv) | |||
130 | FILE *out_f = NULL; | 130 | FILE *out_f = NULL; |
131 | int type = COSE_ES256; | 131 | int type = COSE_ES256; |
132 | int flags = 0; | 132 | int flags = 0; |
133 | int cred_protect = -1; | ||
133 | int ch; | 134 | int ch; |
134 | int r; | 135 | int r; |
135 | 136 | ||
136 | while ((ch = getopt(argc, argv, "dhi:o:qruv")) != -1) { | 137 | while ((ch = getopt(argc, argv, "c:dhi:o:qruv")) != -1) { |
137 | switch (ch) { | 138 | switch (ch) { |
139 | case 'c': | ||
140 | if ((cred_protect = base10(optarg)) < 0) | ||
141 | errx(1, "-c: invalid argument '%s'", optarg); | ||
142 | break; | ||
138 | case 'd': | 143 | case 'd': |
139 | flags |= FLAG_DEBUG; | 144 | flags |= FLAG_DEBUG; |
140 | break; | 145 | break; |
@@ -173,16 +178,8 @@ cred_make(int argc, char **argv) | |||
173 | in_f = open_read(in_path); | 178 | in_f = open_read(in_path); |
174 | out_f = open_write(out_path); | 179 | out_f = open_write(out_path); |
175 | 180 | ||
176 | if (argc > 1) { | 181 | if (argc > 1 && cose_type(argv[1], &type) < 0) |
177 | if (strcmp(argv[1], "es256") == 0) | 182 | errx(1, "unknown type %s", argv[1]); |
178 | type = COSE_ES256; | ||
179 | else if (strcmp(argv[1], "rs256") == 0) | ||
180 | type = COSE_RS256; | ||
181 | else if (strcmp(argv[1], "eddsa") == 0) | ||
182 | type = COSE_EDDSA; | ||
183 | else | ||
184 | errx(1, "unknown type %s", argv[1]); | ||
185 | } | ||
186 | 183 | ||
187 | fido_init((flags & FLAG_DEBUG) ? FIDO_DEBUG : 0); | 184 | fido_init((flags & FLAG_DEBUG) ? FIDO_DEBUG : 0); |
188 | 185 | ||
@@ -192,6 +189,13 @@ cred_make(int argc, char **argv) | |||
192 | if (flags & FLAG_U2F) | 189 | if (flags & FLAG_U2F) |
193 | fido_dev_force_u2f(dev); | 190 | fido_dev_force_u2f(dev); |
194 | 191 | ||
192 | if (cred_protect > 0) { | ||
193 | r = fido_cred_set_prot(cred, cred_protect); | ||
194 | if (r != FIDO_OK) { | ||
195 | errx(1, "fido_cred_set_prot: %s", fido_strerr(r)); | ||
196 | } | ||
197 | } | ||
198 | |||
195 | r = fido_dev_make_cred(dev, cred, NULL); | 199 | r = fido_dev_make_cred(dev, cred, NULL); |
196 | if (r == FIDO_ERR_PIN_REQUIRED && !(flags & FLAG_QUIET)) { | 200 | if (r == FIDO_ERR_PIN_REQUIRED && !(flags & FLAG_QUIET)) { |
197 | r = snprintf(prompt, sizeof(prompt), "Enter PIN for %s: ", | 201 | r = snprintf(prompt, sizeof(prompt), "Enter PIN for %s: ", |