|
Lines 53-58
Link Here
|
| 53 |
#include "rsa.h" |
53 |
#include "rsa.h" |
| 54 |
#include "log.h" |
54 |
#include "log.h" |
| 55 |
#include "key.h" |
55 |
#include "key.h" |
|
|
56 |
#include "pkcs11.h" |
| 56 |
#include "buffer.h" |
57 |
#include "buffer.h" |
| 57 |
#include "authfd.h" |
58 |
#include "authfd.h" |
| 58 |
#include "authfile.h" |
59 |
#include "authfile.h" |
|
Lines 316-321
usage(void)
Link Here
|
| 316 |
fprintf(stderr, " -X Unlock agent.\n"); |
317 |
fprintf(stderr, " -X Unlock agent.\n"); |
| 317 |
fprintf(stderr, " -t life Set lifetime (in seconds) when adding identities.\n"); |
318 |
fprintf(stderr, " -t life Set lifetime (in seconds) when adding identities.\n"); |
| 318 |
fprintf(stderr, " -c Require confirmation to sign using identities\n"); |
319 |
fprintf(stderr, " -c Require confirmation to sign using identities\n"); |
|
|
320 |
#ifdef ENABLE_PKCS11 |
| 321 |
fprintf(stderr, " -K provider Add PKCS#11 provider, format:\n"); |
| 322 |
fprintf(stderr, " lib[:prot_auth[:private_mode[:cert_is_private]]]\n"); |
| 323 |
fprintf(stderr, " prot_auth - 1 to allow protected mode authentication.\n"); |
| 324 |
fprintf(stderr, " private_mode - Private key mode, see man page.\n"); |
| 325 |
fprintf(stderr, " cert_is_private - 1 if login is required to access certificates.\n"); |
| 326 |
fprintf(stderr, " -I Add PKCS#11 id, remainging arguments:\n"); |
| 327 |
fprintf(stderr, " pkcs11_id [session_cache [cert_file]]\n"); |
| 328 |
fprintf(stderr, " pkcs11_id - Serialized id, get from ssh-keygen -K.\n"); |
| 329 |
fprintf(stderr, " session_cache - Session cache timeout in seconds -1 for infinite.\n"); |
| 330 |
fprintf(stderr, " cert_file - Specify PEM file to load if token is unavailable.\n"); |
| 331 |
#endif |
| 319 |
#ifdef SMARTCARD |
332 |
#ifdef SMARTCARD |
| 320 |
fprintf(stderr, " -s reader Add key in smartcard reader.\n"); |
333 |
fprintf(stderr, " -s reader Add key in smartcard reader.\n"); |
| 321 |
fprintf(stderr, " -e reader Remove key in smartcard reader.\n"); |
334 |
fprintf(stderr, " -e reader Remove key in smartcard reader.\n"); |
|
Lines 330-335
main(int argc, char **argv)
Link Here
|
| 330 |
AuthenticationConnection *ac = NULL; |
343 |
AuthenticationConnection *ac = NULL; |
| 331 |
char *sc_reader_id = NULL; |
344 |
char *sc_reader_id = NULL; |
| 332 |
int i, ch, deleting = 0, ret = 0; |
345 |
int i, ch, deleting = 0, ret = 0; |
|
|
346 |
#ifdef ENABLE_PKCS11 |
| 347 |
pkcs11_provider *pkcs11_provider = NULL; |
| 348 |
int doing_pkcs11 = 0; |
| 349 |
#endif /* ENABLE_PKCS11 */ |
| 333 |
|
350 |
|
| 334 |
/* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */ |
351 |
/* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */ |
| 335 |
sanitise_stdfd(); |
352 |
sanitise_stdfd(); |
|
Lines 343-349
main(int argc, char **argv)
Link Here
|
| 343 |
"Could not open a connection to your authentication agent.\n"); |
360 |
"Could not open a connection to your authentication agent.\n"); |
| 344 |
exit(2); |
361 |
exit(2); |
| 345 |
} |
362 |
} |
| 346 |
while ((ch = getopt(argc, argv, "lLcdDxXe:s:t:")) != -1) { |
363 |
while ((ch = getopt(argc, argv, "lLcdDxXe:s:t:K:I")) != -1) { |
| 347 |
switch (ch) { |
364 |
switch (ch) { |
| 348 |
case 'l': |
365 |
case 'l': |
| 349 |
case 'L': |
366 |
case 'L': |
|
Lines 379-384
main(int argc, char **argv)
Link Here
|
| 379 |
goto done; |
396 |
goto done; |
| 380 |
} |
397 |
} |
| 381 |
break; |
398 |
break; |
|
|
399 |
#ifdef ENABLE_PKCS11 |
| 400 |
case 'K': |
| 401 |
if ((pkcs11_provider = pkcs11_parse_provider(optarg)) == NULL) { |
| 402 |
fprintf(stderr, "Cannot parse PKCS#11 provider\n"); |
| 403 |
ret = 1; |
| 404 |
goto done; |
| 405 |
} |
| 406 |
break; |
| 407 |
case 'I': |
| 408 |
doing_pkcs11 = 1; |
| 409 |
break; |
| 410 |
#endif /* ENABLE_PKCS11 */ |
| 382 |
default: |
411 |
default: |
| 383 |
usage(); |
412 |
usage(); |
| 384 |
ret = 1; |
413 |
ret = 1; |
|
Lines 387-392
main(int argc, char **argv)
Link Here
|
| 387 |
} |
416 |
} |
| 388 |
argc -= optind; |
417 |
argc -= optind; |
| 389 |
argv += optind; |
418 |
argv += optind; |
|
|
419 |
|
| 420 |
#ifdef ENABLE_PKCS11 |
| 421 |
if (pkcs11_provider != NULL) { |
| 422 |
if (!ssh_pkcs11_add_provider(ac, pkcs11_provider)) { |
| 423 |
fprintf(stderr, |
| 424 |
"Cannot add provider '%s'\n", pkcs11_provider->provider); |
| 425 |
ret = 1; |
| 426 |
goto done; |
| 427 |
} |
| 428 |
fprintf(stderr, "Provider '%s' added successfully.\n", pkcs11_provider->provider); |
| 429 |
pkcs11_free_provider(pkcs11_provider); |
| 430 |
} |
| 431 |
|
| 432 |
if (doing_pkcs11) { |
| 433 |
pkcs11_id *pkcs11_id = NULL; |
| 434 |
if (argc < 1 || argc > 3) { |
| 435 |
fprintf(stderr, |
| 436 |
"Invalid PKCS#11 id format\n"); |
| 437 |
ret = 1; |
| 438 |
goto done; |
| 439 |
} |
| 440 |
if ((pkcs11_id = pkcs11_id_new()) == NULL) { |
| 441 |
fprintf(stderr, "Memory allocation error.\n"); |
| 442 |
ret = 1; |
| 443 |
goto done; |
| 444 |
} |
| 445 |
pkcs11_id->id = argv[0]; |
| 446 |
if (argc > 1) |
| 447 |
pkcs11_id->pin_cache_period = atoi(argv[1]); |
| 448 |
if (argc > 2) |
| 449 |
pkcs11_id->cert_file = xstrdup(argv[2]); |
| 450 |
|
| 451 |
if (!ssh_pkcs11_id(ac, pkcs11_id, deleting)) { |
| 452 |
fprintf(stderr, |
| 453 |
"Cannot %s id '%s'\n", deleting ? "remove" : "add", pkcs11_id->id); |
| 454 |
ret = 1; |
| 455 |
goto done; |
| 456 |
} |
| 457 |
pkcs11_id_free(pkcs11_id); |
| 458 |
fprintf(stderr, "Identity %s successfully.\n", deleting ? "removed" : "added"); |
| 459 |
goto done; |
| 460 |
} |
| 461 |
#endif /* ENABLE_PKCS11 */ |
| 462 |
|
| 390 |
if (sc_reader_id != NULL) { |
463 |
if (sc_reader_id != NULL) { |
| 391 |
if (update_card(ac, !deleting, sc_reader_id) == -1) |
464 |
if (update_card(ac, !deleting, sc_reader_id) == -1) |
| 392 |
ret = 1; |
465 |
ret = 1; |