=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ssh/ssh-keygen.c,v retrieving revision 1.61 retrieving revision 1.64 diff -u -r1.61 -r1.64 --- src/usr.bin/ssh/ssh-keygen.c 2001/05/25 14:37:32 1.61 +++ src/usr.bin/ssh/ssh-keygen.c 2001/06/23 17:05:22 1.64 @@ -12,7 +12,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: ssh-keygen.c,v 1.61 2001/05/25 14:37:32 markus Exp $"); +RCSID("$OpenBSD: ssh-keygen.c,v 1.64 2001/06/23 17:05:22 markus Exp $"); #include #include @@ -75,7 +75,7 @@ char hostname[MAXHOSTNAMELEN]; -void +static void ask_filename(struct passwd *pw, const char *prompt) { char buf[1024]; @@ -108,7 +108,7 @@ have_identity = 1; } -Key * +static Key * load_identity(char *filename) { char *pass; @@ -132,7 +132,7 @@ #define SSH_COM_PRIVATE_BEGIN "---- BEGIN SSH2 ENCRYPTED PRIVATE KEY ----" #define SSH_COM_PRIVATE_KEY_MAGIC 0x3f6ff9eb -void +static void do_convert_to_ssh2(struct passwd *pw) { Key *k; @@ -165,7 +165,7 @@ exit(0); } -void +static void buffer_get_bignum_bits(Buffer *b, BIGNUM *value) { int bits = buffer_get_int(b); @@ -178,13 +178,16 @@ buffer_consume(b, bytes); } -Key * +static Key * do_convert_private_ssh2_from_blob(char *blob, int blen) { Buffer b; Key *key = NULL; - int ignore, magic, rlen, ktype; char *type, *cipher; + u_char *sig, data[10] = "abcde12345"; + int magic, rlen, ktype, i1, i2, i3, i4; + u_int slen; + u_long e; buffer_init(&b); buffer_append(&b, blob, blen); @@ -195,13 +198,13 @@ buffer_free(&b); return NULL; } - ignore = buffer_get_int(&b); + i1 = buffer_get_int(&b); type = buffer_get_string(&b, NULL); cipher = buffer_get_string(&b, NULL); - ignore = buffer_get_int(&b); - ignore = buffer_get_int(&b); - ignore = buffer_get_int(&b); - + i2 = buffer_get_int(&b); + i3 = buffer_get_int(&b); + i4 = buffer_get_int(&b); + debug("ignore (%d %d %d %d)", i1,i2,i3,i4); if (strcmp(cipher, "none") != 0) { error("unsupported cipher %s", cipher); xfree(cipher); @@ -231,7 +234,17 @@ buffer_get_bignum_bits(&b, key->dsa->priv_key); break; case KEY_RSA: - if (!BN_set_word(key->rsa->e, (u_long) buffer_get_char(&b))) { + e = buffer_get_char(&b); + debug("e %lx", e); + if (e < 30) { + e <<= 8; + e += buffer_get_char(&b); + debug("e %lx", e); + e <<= 8; + e += buffer_get_char(&b); + debug("e %lx", e); + } + if (!BN_set_word(key->rsa->e, e)) { buffer_free(&b); key_free(key); return NULL; @@ -249,20 +262,15 @@ error("do_convert_private_ssh2_from_blob: " "remaining bytes in key blob %d", rlen); buffer_free(&b); -#ifdef DEBUG_PK - { - u_int slen; - u_char *sig, data[10] = "abcde12345"; - key_sign(key, &sig, &slen, data, sizeof data); - key_verify(key, sig, slen, data, sizeof data); - xfree(sig); - } -#endif + /* try the key */ + key_sign(key, &sig, &slen, data, sizeof(data)); + key_verify(key, sig, slen, data, sizeof(data)); + xfree(sig); return key; } -void +static void do_convert_from_ssh2(struct passwd *pw) { Key *k; @@ -297,6 +305,9 @@ strstr(line, ": ") != NULL) { if (strstr(line, SSH_COM_PRIVATE_BEGIN) != NULL) private = 1; + if (strstr(line, " END ") != NULL) { + break; + } /* fprintf(stderr, "ignore: %s", line); */ continue; } @@ -335,7 +346,7 @@ exit(0); } -void +static void do_print_public(struct passwd *pw) { Key *prv; @@ -359,7 +370,7 @@ exit(0); } -void +static void do_fingerprint(struct passwd *pw) { FILE *f; @@ -456,7 +467,7 @@ * Perform changing a passphrase. The argument is the passwd structure * for the current user. */ -void +static void do_change_passphrase(struct passwd *pw) { char *comment; @@ -532,7 +543,7 @@ /* * Change the comment of a private key file. */ -void +static void do_change_comment(struct passwd *pw) { char new_comment[1024], *comment, *passphrase; @@ -625,7 +636,7 @@ exit(0); } -void +static void usage(void) { printf("Usage: %s [-ceilpqyB] [-t type] [-b bits] [-f file] [-C comment] "