1
1
/*
2
- * Copyright (c) 2018-2022 Yubico AB. All rights reserved.
2
+ * Copyright (c) 2018-2023 Yubico AB. All rights reserved.
3
3
* Use of this source code is governed by a BSD-style
4
4
* license that can be found in the LICENSE file.
5
5
* SPDX-License-Identifier: BSD-2-Clause
@@ -36,15 +36,16 @@ static void
36
36
usage (void )
37
37
{
38
38
fprintf (stderr , "usage: cred [-t es256|es384|rs256|eddsa] [-k pubkey] "
39
- "[-ei cred_id] [-P pin] [-T seconds] [-b blobkey] [-hruv] "
39
+ "[-ei cred_id] [-P pin] [-T seconds] [-b blobkey] [-c cred_protect] [- hruv] "
40
40
"<device>\n" );
41
41
exit (EXIT_FAILURE );
42
42
}
43
43
44
44
static void
45
45
verify_cred (int type , const char * fmt , const unsigned char * authdata_ptr ,
46
46
size_t authdata_len , const unsigned char * attstmt_ptr , size_t attstmt_len ,
47
- bool rk , bool uv , int ext , const char * key_out , const char * id_out )
47
+ bool rk , bool uv , int ext , int cred_protect , const char * key_out ,
48
+ const char * id_out )
48
49
{
49
50
fido_cred_t * cred ;
50
51
int r ;
@@ -85,6 +86,11 @@ verify_cred(int type, const char *fmt, const unsigned char *authdata_ptr,
85
86
if (uv && (r = fido_cred_set_uv (cred , FIDO_OPT_TRUE )) != FIDO_OK )
86
87
errx (1 , "fido_cred_set_uv: %s (0x%x)" , fido_strerr (r ), r );
87
88
89
+ /* credProt */
90
+ if (cred_protect != 0 && (r = fido_cred_set_prot (cred ,
91
+ cred_protect )) != FIDO_OK )
92
+ errx (1 , "fido_cred_set_prot: %s (0x%x)" , fido_strerr (r ), r );
93
+
88
94
/* fmt */
89
95
r = fido_cred_set_fmt (cred , fmt );
90
96
if (r != FIDO_OK )
@@ -159,11 +165,12 @@ main(int argc, char **argv)
159
165
int ext = 0 ;
160
166
int ch ;
161
167
int r ;
168
+ long long cred_protect = 0 ;
162
169
163
170
if ((cred = fido_cred_new ()) == NULL )
164
171
errx (1 , "fido_cred_new" );
165
172
166
- while ((ch = getopt (argc , argv , "P:T:b:e:hi:k:rt:uv " )) != -1 ) {
173
+ while ((ch = getopt (argc , argv , "P:T:b:e:hi:k:rt:uvc: " )) != -1 ) {
167
174
switch (ch ) {
168
175
case 'P' :
169
176
pin = optarg ;
@@ -192,6 +199,13 @@ main(int argc, char **argv)
192
199
case 'h' :
193
200
ext |= FIDO_EXT_HMAC_SECRET ;
194
201
break ;
202
+ case 'c' :
203
+ if (base10 (optarg , & cred_protect ) < 0 )
204
+ errx (1 , "base10: %s" , optarg );
205
+ if (cred_protect <= 0 || cred_protect > 3 )
206
+ errx (1 , "-c: %s must be in (1,3)" , optarg );
207
+ ext |= FIDO_EXT_CRED_PROTECT ;
208
+ break ;
195
209
case 'i' :
196
210
id_out = optarg ;
197
211
break ;
@@ -275,6 +289,11 @@ main(int argc, char **argv)
275
289
if (uv && (r = fido_cred_set_uv (cred , FIDO_OPT_TRUE )) != FIDO_OK )
276
290
errx (1 , "fido_cred_set_uv: %s (0x%x)" , fido_strerr (r ), r );
277
291
292
+ /* credProt */
293
+ if (cred_protect != 0 && (r = fido_cred_set_prot (cred ,
294
+ (int )cred_protect )) != FIDO_OK )
295
+ errx (1 , "fido_cred_set_prot: %s (0x%x)" , fido_strerr (r ), r );
296
+
278
297
/* timeout */
279
298
if (ms != 0 && (r = fido_dev_set_timeout (dev , (int )ms )) != FIDO_OK )
280
299
errx (1 , "fido_dev_set_timeout: %s (0x%x)" , fido_strerr (r ), r );
@@ -296,7 +315,8 @@ main(int argc, char **argv)
296
315
297
316
verify_cred (type , fido_cred_fmt (cred ), fido_cred_authdata_ptr (cred ),
298
317
fido_cred_authdata_len (cred ), fido_cred_attstmt_ptr (cred ),
299
- fido_cred_attstmt_len (cred ), rk , uv , ext , key_out , id_out );
318
+ fido_cred_attstmt_len (cred ), rk , uv , ext , fido_cred_prot (cred ),
319
+ key_out , id_out );
300
320
301
321
if (blobkey_out != NULL ) {
302
322
/* extract the "largeBlob" key */
0 commit comments