summaryrefslogtreecommitdiff
path: root/ssh-keygen.c
diff options
context:
space:
mode:
authorBen Lindstrom <mouring@eviladmin.org>2002-03-22 03:33:43 +0000
committerBen Lindstrom <mouring@eviladmin.org>2002-03-22 03:33:43 +0000
commit70e3ad8231c4b93933bd2c9b05cc705c20013186 (patch)
tree5b049b68e4dc0bcc2add533cb0f864596b9bafb5 /ssh-keygen.c
parent0b675b16595b6b84631ab9ebcccb3ecaa311d14e (diff)
- markus@cvs.openbsd.org 2002/03/21 16:57:15
[scard.c] remove const
Diffstat (limited to 'ssh-keygen.c')
-rw-r--r--ssh-keygen.c126
1 files changed, 11 insertions, 115 deletions
diff --git a/ssh-keygen.c b/ssh-keygen.c
index 2de87167e..d14c99004 100644
--- a/ssh-keygen.c
+++ b/ssh-keygen.c
@@ -12,7 +12,7 @@
12 */ 12 */
13 13
14#include "includes.h" 14#include "includes.h"
15RCSID("$OpenBSD: ssh-keygen.c,v 1.94 2002/02/25 16:33:27 markus Exp $"); 15RCSID("$OpenBSD: ssh-keygen.c,v 1.95 2002/03/21 16:54:53 markus Exp $");
16 16
17#include <openssl/evp.h> 17#include <openssl/evp.h>
18#include <openssl/pem.h> 18#include <openssl/pem.h>
@@ -29,8 +29,6 @@ RCSID("$OpenBSD: ssh-keygen.c,v 1.94 2002/02/25 16:33:27 markus Exp $");
29#include "readpass.h" 29#include "readpass.h"
30 30
31#ifdef SMARTCARD 31#ifdef SMARTCARD
32#include <sectok.h>
33#include <openssl/engine.h>
34#include "scard.h" 32#include "scard.h"
35#endif 33#endif
36 34
@@ -389,132 +387,30 @@ do_print_public(struct passwd *pw)
389} 387}
390 388
391#ifdef SMARTCARD 389#ifdef SMARTCARD
392#define NUM_RSA_KEY_ELEMENTS 5+1
393#define COPY_RSA_KEY(x, i) \
394 do { \
395 len = BN_num_bytes(prv->rsa->x); \
396 elements[i] = xmalloc(len); \
397 debug("#bytes %d", len); \
398 if (BN_bn2bin(prv->rsa->x, elements[i]) < 0) \
399 goto done; \
400 } while (0)
401
402static int
403get_AUT0(char *aut0)
404{
405 EVP_MD *evp_md = EVP_sha1();
406 EVP_MD_CTX md;
407 char *pass;
408
409 pass = read_passphrase("Enter passphrase for smartcard: ", RP_ALLOW_STDIN);
410 if (pass == NULL)
411 return -1;
412 EVP_DigestInit(&md, evp_md);
413 EVP_DigestUpdate(&md, pass, strlen(pass));
414 EVP_DigestFinal(&md, aut0, NULL);
415 memset(pass, 0, strlen(pass));
416 xfree(pass);
417 return 0;
418}
419
420static void 390static void
421do_upload(struct passwd *pw, const char *sc_reader_id) 391do_upload(struct passwd *pw, const char *sc_reader_id)
422{ 392{
423 Key *prv = NULL; 393 Key *prv = NULL;
424 struct stat st; 394 struct stat st;
425 u_char *elements[NUM_RSA_KEY_ELEMENTS]; 395 int ret;
426 u_char key_fid[2]; 396
427 u_char DEFAUT0[] = {0xad, 0x9f, 0x61, 0xfe, 0xfa, 0x20, 0xce, 0x63};
428 u_char AUT0[EVP_MAX_MD_SIZE];
429 int len, status = 1, i, fd = -1, ret;
430 int sw = 0, cla = 0x00;
431
432 for (i = 0; i < NUM_RSA_KEY_ELEMENTS; i++)
433 elements[i] = NULL;
434 if (!have_identity) 397 if (!have_identity)
435 ask_filename(pw, "Enter file in which the key is"); 398 ask_filename(pw, "Enter file in which the key is");
436 if (stat(identity_file, &st) < 0) { 399 if (stat(identity_file, &st) < 0) {
437 perror(identity_file); 400 perror(identity_file);
438 goto done; 401 exit(1);
439 } 402 }
440 prv = load_identity(identity_file); 403 prv = load_identity(identity_file);
441 if (prv == NULL) { 404 if (prv == NULL) {
442 error("load failed"); 405 error("load failed");
443 goto done; 406 exit(1);
444 }
445 COPY_RSA_KEY(q, 0);
446 COPY_RSA_KEY(p, 1);
447 COPY_RSA_KEY(iqmp, 2);
448 COPY_RSA_KEY(dmq1, 3);
449 COPY_RSA_KEY(dmp1, 4);
450 COPY_RSA_KEY(n, 5);
451 len = BN_num_bytes(prv->rsa->n);
452 fd = sectok_friendly_open(sc_reader_id, STONOWAIT, &sw);
453 if (fd < 0) {
454 error("sectok_open failed: %s", sectok_get_sw(sw));
455 goto done;
456 }
457 if (! sectok_cardpresent(fd)) {
458 error("smartcard in reader %s not present",
459 sc_reader_id);
460 goto done;
461 }
462 ret = sectok_reset(fd, 0, NULL, &sw);
463 if (ret <= 0) {
464 error("sectok_reset failed: %s", sectok_get_sw(sw));
465 goto done;
466 }
467 if ((cla = cyberflex_inq_class(fd)) < 0) {
468 error("cyberflex_inq_class failed");
469 goto done;
470 }
471 memcpy(AUT0, DEFAUT0, sizeof(DEFAUT0));
472 if (cyberflex_verify_AUT0(fd, cla, AUT0, sizeof(DEFAUT0)) < 0) {
473 if (get_AUT0(AUT0) < 0 ||
474 cyberflex_verify_AUT0(fd, cla, AUT0, sizeof(DEFAUT0)) < 0) {
475 error("cyberflex_verify_AUT0 failed");
476 goto done;
477 }
478 }
479 key_fid[0] = 0x00;
480 key_fid[1] = 0x12;
481 if (cyberflex_load_rsa_priv(fd, cla, key_fid, 5, 8*len, elements,
482 &sw) < 0) {
483 error("cyberflex_load_rsa_priv failed: %s", sectok_get_sw(sw));
484 goto done;
485 }
486 if (!sectok_swOK(sw))
487 goto done;
488 log("cyberflex_load_rsa_priv done");
489 key_fid[0] = 0x73;
490 key_fid[1] = 0x68;
491 if (cyberflex_load_rsa_pub(fd, cla, key_fid, len, elements[5],
492 &sw) < 0) {
493 error("cyberflex_load_rsa_pub failed: %s", sectok_get_sw(sw));
494 goto done;
495 } 407 }
496 if (!sectok_swOK(sw)) 408 ret = sc_put_key(prv, sc_reader_id);
497 goto done; 409 key_free(prv);
498 log("cyberflex_load_rsa_pub done"); 410 if (ret < 0)
499 status = 0; 411 exit(1);
500 log("loading key done"); 412 log("loading key done");
501done: 413 exit(0);
502
503 memset(elements[0], '\0', BN_num_bytes(prv->rsa->q));
504 memset(elements[1], '\0', BN_num_bytes(prv->rsa->p));
505 memset(elements[2], '\0', BN_num_bytes(prv->rsa->iqmp));
506 memset(elements[3], '\0', BN_num_bytes(prv->rsa->dmq1));
507 memset(elements[4], '\0', BN_num_bytes(prv->rsa->dmp1));
508 memset(elements[5], '\0', BN_num_bytes(prv->rsa->n));
509
510 if (prv)
511 key_free(prv);
512 for (i = 0; i < NUM_RSA_KEY_ELEMENTS; i++)
513 if (elements[i])
514 xfree(elements[i]);
515 if (fd != -1)
516 sectok_close(fd);
517 exit(status);
518} 414}
519 415
520static void 416static void