=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ssh/ssh-keygen.c,v retrieving revision 1.54 retrieving revision 1.59 diff -u -r1.54 -r1.59 --- src/usr.bin/ssh/ssh-keygen.c 2001/04/03 13:56:11 1.54 +++ src/usr.bin/ssh/ssh-keygen.c 2001/04/23 21:57:07 1.59 @@ -12,7 +12,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: ssh-keygen.c,v 1.54 2001/04/03 13:56:11 stevesk Exp $"); +RCSID("$OpenBSD: ssh-keygen.c,v 1.59 2001/04/23 21:57:07 markus Exp $"); #include #include @@ -114,7 +114,7 @@ char *pass; Key *prv; - prv = key_load_private(filename, "", NULL); + prv = key_load_private(filename, "", NULL); if (prv == NULL) { pass = read_passphrase("Enter passphrase: ", 1); prv = key_load_private(filename, pass, NULL); @@ -132,7 +132,7 @@ void do_convert_to_ssh2(struct passwd *pw) { - Key *prv; + Key *k; int len; u_char *blob; struct stat st; @@ -143,20 +143,21 @@ perror(identity_file); exit(1); } - prv = try_load_pem_key(identity_file); - if (prv == NULL) { - fprintf(stderr, "load failed\n"); - exit(1); + if ((k = key_load_public(identity_file, NULL)) == NULL) { + if ((k = try_load_pem_key(identity_file)) == NULL) { + fprintf(stderr, "load failed\n"); + exit(1); + } } - key_to_blob(prv, &blob, &len); + key_to_blob(k, &blob, &len); fprintf(stdout, "%s\n", SSH_COM_PUBLIC_BEGIN); fprintf(stdout, "Comment: \"%d-bit %s, converted from OpenSSH by %s@%s\"\n", - key_size(prv), key_type(prv), + key_size(k), key_type(k), pw->pw_name, hostname); dump_base64(stdout, blob, len); fprintf(stdout, "%s\n", SSH_COM_PUBLIC_END); - key_free(prv); + key_free(k); xfree(blob); exit(0); } @@ -508,8 +509,7 @@ /* Save the file using the new passphrase. */ if (!key_save_private(private, identity_file, passphrase1, comment)) { - printf("Saving the key failed: %s: %s.\n", - identity_file, strerror(errno)); + printf("Saving the key failed: %s.\n", identity_file); memset(passphrase1, 0, strlen(passphrase1)); xfree(passphrase1); key_free(private); @@ -587,8 +587,7 @@ /* Save the file using the new passphrase. */ if (!key_save_private(private, identity_file, passphrase, new_comment)) { - printf("Saving the key failed: %s: %s.\n", - identity_file, strerror(errno)); + printf("Saving the key failed: %s.\n", identity_file); memset(passphrase, 0, strlen(passphrase)); xfree(passphrase); key_free(private); @@ -626,7 +625,7 @@ void usage(void) { - printf("Usage: %s [-lBpqxXyc] [-t type] [-b bits] [-f file] [-C comment] " + printf("Usage: %s [-ceilpqyB] [-t type] [-b bits] [-f file] [-C comment] " "[-N new-pass] [-P pass]\n", __progname); exit(1); } @@ -660,7 +659,7 @@ exit(1); } - while ((opt = getopt(ac, av, "dqpclBRxXyb:f:t:P:N:C:")) != -1) { + while ((opt = getopt(ac, av, "deiqpclBRxXyb:f:t:P:N:C:")) != -1) { switch (opt) { case 'b': bits = atoi(optarg); @@ -712,11 +711,15 @@ exit(0); break; + case 'e': case 'x': + /* export key */ convert_to_ssh2 = 1; break; + case 'i': case 'X': + /* import key */ convert_from_ssh2 = 1; break; @@ -830,8 +833,7 @@ /* Save the key with the given passphrase and comment. */ if (!key_save_private(private, identity_file, passphrase1, comment)) { - printf("Saving the key failed: %s: %s.\n", - identity_file, strerror(errno)); + printf("Saving the key failed: %s.\n", identity_file); memset(passphrase1, 0, strlen(passphrase1)); xfree(passphrase1); exit(1);