2 * Author: Tatu Ylonen <ylo@cs.hut.fi>
3 * Copyright (c) 1994 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5 * Identity and host key generation and maintenance.
7 * As far as I am concerned, the code I have written for this software
8 * can be used freely for any purpose. Any derived versions of this
9 * software must be clearly marked as such, and if the derived work is
10 * incompatible with the protocol description in the RFC file, it must be
11 * called by a name other than "ssh" or "Secure Shell".
15 RCSID("$OpenBSD: ssh-keygen.c,v 1.77 2001/08/02 15:06:52 jakob Exp $");
17 #include <openssl/evp.h>
18 #include <openssl/pem.h>
27 #include "pathnames.h"
33 #include <openssl/engine.h>
37 /* Number of bits in the RSA/DSA key. This value can be changed on the command line. */
41 * Flag indicating that we just want to change the passphrase. This can be
42 * set on the command line.
44 int change_passphrase = 0;
47 * Flag indicating that we just want to change the comment. This can be set
48 * on the command line.
50 int change_comment = 0;
54 /* Flag indicating that we just want to see the key fingerprint */
55 int print_fingerprint = 0;
56 int print_bubblebabble = 0;
58 /* The identity file name, given on the command line or entered by the user. */
59 char identity_file[1024];
60 int have_identity = 0;
62 /* This is set to the passphrase if given on the command line. */
63 char *identity_passphrase = NULL;
65 /* This is set to the new passphrase if given on the command line. */
66 char *identity_new_passphrase = NULL;
68 /* This is set to the new comment if given on the command line. */
69 char *identity_comment = NULL;
71 /* Dump public key file in format used by real and the original SSH 2 */
72 int convert_to_ssh2 = 0;
73 int convert_from_ssh2 = 0;
76 /* default to RSA for SSH-1 */
77 char *key_type_name = "rsa1";
80 #ifdef HAVE___PROGNAME
81 extern char *__progname;
86 char hostname[MAXHOSTNAMELEN];
89 ask_filename(struct passwd *pw, const char *prompt)
94 switch (key_type_from_name(key_type_name)) {
96 name = _PATH_SSH_CLIENT_IDENTITY;
99 name = _PATH_SSH_CLIENT_ID_DSA;
102 name = _PATH_SSH_CLIENT_ID_RSA;
105 fprintf(stderr, "bad key type");
109 snprintf(identity_file, sizeof(identity_file), "%s/%s", pw->pw_dir, name);
110 fprintf(stderr, "%s (%s): ", prompt, identity_file);
112 if (fgets(buf, sizeof(buf), stdin) == NULL)
114 if (strchr(buf, '\n'))
115 *strchr(buf, '\n') = 0;
116 if (strcmp(buf, "") != 0)
117 strlcpy(identity_file, buf, sizeof(identity_file));
122 load_identity(char *filename)
127 prv = key_load_private(filename, "", NULL);
129 if (identity_passphrase)
130 pass = xstrdup(identity_passphrase);
132 pass = read_passphrase("Enter passphrase: ",
134 prv = key_load_private(filename, pass, NULL);
135 memset(pass, 0, strlen(pass));
141 #define SSH_COM_PUBLIC_BEGIN "---- BEGIN SSH2 PUBLIC KEY ----"
142 #define SSH_COM_PUBLIC_END "---- END SSH2 PUBLIC KEY ----"
143 #define SSH_COM_PRIVATE_BEGIN "---- BEGIN SSH2 ENCRYPTED PRIVATE KEY ----"
144 #define SSH_COM_PRIVATE_KEY_MAGIC 0x3f6ff9eb
147 do_convert_to_ssh2(struct passwd *pw)
155 ask_filename(pw, "Enter file in which the key is");
156 if (stat(identity_file, &st) < 0) {
157 perror(identity_file);
160 if ((k = key_load_public(identity_file, NULL)) == NULL) {
161 if ((k = load_identity(identity_file)) == NULL) {
162 fprintf(stderr, "load failed\n");
166 key_to_blob(k, &blob, &len);
167 fprintf(stdout, "%s\n", SSH_COM_PUBLIC_BEGIN);
169 "Comment: \"%d-bit %s, converted from OpenSSH by %s@%s\"\n",
170 key_size(k), key_type(k),
171 pw->pw_name, hostname);
172 dump_base64(stdout, blob, len);
173 fprintf(stdout, "%s\n", SSH_COM_PUBLIC_END);
180 buffer_get_bignum_bits(Buffer *b, BIGNUM *value)
182 int bits = buffer_get_int(b);
183 int bytes = (bits + 7) / 8;
185 if (buffer_len(b) < bytes)
186 fatal("buffer_get_bignum_bits: input buffer too small: "
187 "need %d have %d", bytes, buffer_len(b));
188 BN_bin2bn((u_char *)buffer_ptr(b), bytes, value);
189 buffer_consume(b, bytes);
193 do_convert_private_ssh2_from_blob(char *blob, int blen)
198 u_char *sig, data[] = "abcde12345";
199 int magic, rlen, ktype, i1, i2, i3, i4;
204 buffer_append(&b, blob, blen);
206 magic = buffer_get_int(&b);
207 if (magic != SSH_COM_PRIVATE_KEY_MAGIC) {
208 error("bad magic 0x%x != 0x%x", magic, SSH_COM_PRIVATE_KEY_MAGIC);
212 i1 = buffer_get_int(&b);
213 type = buffer_get_string(&b, NULL);
214 cipher = buffer_get_string(&b, NULL);
215 i2 = buffer_get_int(&b);
216 i3 = buffer_get_int(&b);
217 i4 = buffer_get_int(&b);
218 debug("ignore (%d %d %d %d)", i1,i2,i3,i4);
219 if (strcmp(cipher, "none") != 0) {
220 error("unsupported cipher %s", cipher);
228 if (strstr(type, "dsa")) {
230 } else if (strstr(type, "rsa")) {
236 key = key_new_private(ktype);
241 buffer_get_bignum_bits(&b, key->dsa->p);
242 buffer_get_bignum_bits(&b, key->dsa->g);
243 buffer_get_bignum_bits(&b, key->dsa->q);
244 buffer_get_bignum_bits(&b, key->dsa->pub_key);
245 buffer_get_bignum_bits(&b, key->dsa->priv_key);
248 e = buffer_get_char(&b);
252 e += buffer_get_char(&b);
255 e += buffer_get_char(&b);
258 if (!BN_set_word(key->rsa->e, e)) {
263 buffer_get_bignum_bits(&b, key->rsa->d);
264 buffer_get_bignum_bits(&b, key->rsa->n);
265 buffer_get_bignum_bits(&b, key->rsa->iqmp);
266 buffer_get_bignum_bits(&b, key->rsa->q);
267 buffer_get_bignum_bits(&b, key->rsa->p);
268 rsa_generate_additional_parameters(key->rsa);
271 rlen = buffer_len(&b);
273 error("do_convert_private_ssh2_from_blob: "
274 "remaining bytes in key blob %d", rlen);
278 key_sign(key, &sig, &slen, data, sizeof(data));
279 key_verify(key, sig, slen, data, sizeof(data));
285 do_convert_from_ssh2(struct passwd *pw)
293 int escaped = 0, private = 0, ok;
297 ask_filename(pw, "Enter file in which the key is");
298 if (stat(identity_file, &st) < 0) {
299 perror(identity_file);
302 fp = fopen(identity_file, "r");
304 perror(identity_file);
308 while (fgets(line, sizeof(line), fp)) {
309 if (!(p = strchr(line, '\n'))) {
310 fprintf(stderr, "input line too long.\n");
313 if (p > line && p[-1] == '\\')
315 if (strncmp(line, "----", 4) == 0 ||
316 strstr(line, ": ") != NULL) {
317 if (strstr(line, SSH_COM_PRIVATE_BEGIN) != NULL)
319 if (strstr(line, " END ") != NULL) {
322 /* fprintf(stderr, "ignore: %s", line); */
327 /* fprintf(stderr, "escaped: %s", line); */
331 strlcat(encoded, line, sizeof(encoded));
333 blen = uudecode(encoded, (u_char *)blob, sizeof(blob));
335 fprintf(stderr, "uudecode failed.\n");
339 do_convert_private_ssh2_from_blob(blob, blen) :
340 key_from_blob(blob, blen);
342 fprintf(stderr, "decode blob failed.\n");
346 (k->type == KEY_DSA ?
347 PEM_write_DSAPrivateKey(stdout, k->dsa, NULL, NULL, 0, NULL, NULL) :
348 PEM_write_RSAPrivateKey(stdout, k->rsa, NULL, NULL, 0, NULL, NULL)) :
349 key_write(k, stdout);
351 fprintf(stderr, "key write failed");
355 fprintf(stdout, "\n");
361 do_print_public(struct passwd *pw)
367 ask_filename(pw, "Enter file in which the key is");
368 if (stat(identity_file, &st) < 0) {
369 perror(identity_file);
372 prv = load_identity(identity_file);
374 fprintf(stderr, "load failed\n");
377 if (!key_write(prv, stdout))
378 fprintf(stderr, "key_write failed");
380 fprintf(stdout, "\n");
385 #define NUM_RSA_KEY_ELEMENTS 5+1
386 #define COPY_RSA_KEY(x, i) \
388 len = BN_num_bytes(prv->rsa->x); \
389 elements[i] = xmalloc(len); \
390 debug("#bytes %d", len); \
391 if (BN_bn2bin(prv->rsa->x, elements[i]) < 0) \
398 EVP_MD *evp_md = EVP_sha1();
402 pass = read_passphrase("Enter passphrase for smartcard: ", RP_ALLOW_STDIN);
405 EVP_DigestInit(&md, evp_md);
406 EVP_DigestUpdate(&md, pass, strlen(pass));
407 EVP_DigestFinal(&md, aut0, NULL);
408 memset(pass, 0, strlen(pass));
414 do_upload(struct passwd *pw, const char *sc_reader_id)
418 u_char *elements[NUM_RSA_KEY_ELEMENTS];
420 u_char DEFAUT0[] = {0xad, 0x9f, 0x61, 0xfe, 0xfa, 0x20, 0xce, 0x63};
421 u_char AUT0[EVP_MAX_MD_SIZE];
422 int len, status = 1, i, fd = -1, ret;
423 int sw = 0, cla = 0x00;
425 for (i = 0; i < NUM_RSA_KEY_ELEMENTS; i++)
428 ask_filename(pw, "Enter file in which the key is");
429 if (stat(identity_file, &st) < 0) {
430 perror(identity_file);
433 prv = load_identity(identity_file);
435 error("load failed");
440 COPY_RSA_KEY(iqmp, 2);
441 COPY_RSA_KEY(dmq1, 3);
442 COPY_RSA_KEY(dmp1, 4);
444 len = BN_num_bytes(prv->rsa->n);
445 fd = sectok_friendly_open(sc_reader_id, STONOWAIT, &sw);
447 error("sectok_open failed: %s", sectok_get_sw(sw));
450 if (! sectok_cardpresent(fd)) {
451 error("smartcard in reader %s not present",
455 ret = sectok_reset(fd, 0, NULL, &sw);
457 error("sectok_reset failed: %s", sectok_get_sw(sw));
460 if ((cla = cyberflex_inq_class(fd)) < 0) {
461 error("cyberflex_inq_class failed");
464 memcpy(AUT0, DEFAUT0, sizeof(DEFAUT0));
465 if (cyberflex_verify_AUT0(fd, cla, AUT0, sizeof(DEFAUT0)) < 0) {
466 if (get_AUT0(AUT0) < 0 ||
467 cyberflex_verify_AUT0(fd, cla, AUT0, sizeof(DEFAUT0)) < 0) {
468 error("cyberflex_verify_AUT0 failed");
474 if (cyberflex_load_rsa_priv(fd, cla, key_fid, 5, 8*len, elements,
476 error("cyberflex_load_rsa_priv failed: %s", sectok_get_sw(sw));
479 if (!sectok_swOK(sw))
481 log("cyberflex_load_rsa_priv done");
484 if (cyberflex_load_rsa_pub(fd, cla, key_fid, len, elements[5],
486 error("cyberflex_load_rsa_pub failed: %s", sectok_get_sw(sw));
489 if (!sectok_swOK(sw))
491 log("cyberflex_load_rsa_pub done");
493 log("loading key done");
497 for (i = 0; i < NUM_RSA_KEY_ELEMENTS; i++)
506 do_download(struct passwd *pw, const char *sc_reader_id)
510 pub = sc_get_key(sc_reader_id);
512 fatal("cannot read public key from smartcard");
513 key_write(pub, stdout);
515 fprintf(stdout, "\n");
521 do_fingerprint(struct passwd *pw)
525 char *comment = NULL, *cp, *ep, line[16*1024], *fp;
526 int i, skip = 0, num = 1, invalid = 1, rep, fptype;
529 fptype = print_bubblebabble ? SSH_FP_SHA1 : SSH_FP_MD5;
530 rep = print_bubblebabble ? SSH_FP_BUBBLEBABBLE : SSH_FP_HEX;
533 ask_filename(pw, "Enter file in which the key is");
534 if (stat(identity_file, &st) < 0) {
535 perror(identity_file);
538 public = key_load_public(identity_file, &comment);
539 if (public != NULL) {
540 fp = key_fingerprint(public, fptype, rep);
541 printf("%d %s %s\n", key_size(public), fp, comment);
550 f = fopen(identity_file, "r");
552 while (fgets(line, sizeof(line), f)) {
553 i = strlen(line) - 1;
554 if (line[i] != '\n') {
555 error("line %d too long: %.40s...", num, line);
566 /* Skip leading whitespace, empty and comment lines. */
567 for (cp = line; *cp == ' ' || *cp == '\t'; cp++)
569 if (!*cp || *cp == '\n' || *cp == '#')
571 i = strtol(cp, &ep, 10);
572 if (i == 0 || ep == NULL || (*ep != ' ' && *ep != '\t')) {
575 for (; *cp && (quoted || (*cp != ' ' && *cp != '\t')); cp++) {
576 if (*cp == '\\' && cp[1] == '"')
577 cp++; /* Skip both */
586 public = key_new(KEY_RSA1);
587 if (key_read(public, &cp) != 1) {
590 public = key_new(KEY_UNSPEC);
591 if (key_read(public, &cp) != 1) {
596 comment = *cp ? cp : comment;
597 fp = key_fingerprint(public, fptype, rep);
598 printf("%d %s %s\n", key_size(public), fp,
599 comment ? comment : "no comment");
607 printf("%s is not a valid key file.\n", identity_file);
614 * Perform changing a passphrase. The argument is the passwd structure
615 * for the current user.
618 do_change_passphrase(struct passwd *pw)
621 char *old_passphrase, *passphrase1, *passphrase2;
626 ask_filename(pw, "Enter file in which the key is");
627 if (stat(identity_file, &st) < 0) {
628 perror(identity_file);
631 /* Try to load the file with empty passphrase. */
632 private = key_load_private(identity_file, "", &comment);
633 if (private == NULL) {
634 if (identity_passphrase)
635 old_passphrase = xstrdup(identity_passphrase);
638 read_passphrase("Enter old passphrase: ",
640 private = key_load_private(identity_file, old_passphrase,
642 memset(old_passphrase, 0, strlen(old_passphrase));
643 xfree(old_passphrase);
644 if (private == NULL) {
645 printf("Bad passphrase.\n");
649 printf("Key has comment '%s'\n", comment);
651 /* Ask the new passphrase (twice). */
652 if (identity_new_passphrase) {
653 passphrase1 = xstrdup(identity_new_passphrase);
657 read_passphrase("Enter new passphrase (empty for no "
658 "passphrase): ", RP_ALLOW_STDIN);
659 passphrase2 = read_passphrase("Enter same passphrase again: ",
662 /* Verify that they are the same. */
663 if (strcmp(passphrase1, passphrase2) != 0) {
664 memset(passphrase1, 0, strlen(passphrase1));
665 memset(passphrase2, 0, strlen(passphrase2));
668 printf("Pass phrases do not match. Try again.\n");
671 /* Destroy the other copy. */
672 memset(passphrase2, 0, strlen(passphrase2));
676 /* Save the file using the new passphrase. */
677 if (!key_save_private(private, identity_file, passphrase1, comment)) {
678 printf("Saving the key failed: %s.\n", identity_file);
679 memset(passphrase1, 0, strlen(passphrase1));
685 /* Destroy the passphrase and the copy of the key in memory. */
686 memset(passphrase1, 0, strlen(passphrase1));
688 key_free(private); /* Destroys contents */
691 printf("Your identification has been saved with the new passphrase.\n");
696 * Change the comment of a private key file.
699 do_change_comment(struct passwd *pw)
701 char new_comment[1024], *comment, *passphrase;
709 ask_filename(pw, "Enter file in which the key is");
710 if (stat(identity_file, &st) < 0) {
711 perror(identity_file);
714 private = key_load_private(identity_file, "", &comment);
715 if (private == NULL) {
716 if (identity_passphrase)
717 passphrase = xstrdup(identity_passphrase);
718 else if (identity_new_passphrase)
719 passphrase = xstrdup(identity_new_passphrase);
721 passphrase = read_passphrase("Enter passphrase: ",
723 /* Try to load using the passphrase. */
724 private = key_load_private(identity_file, passphrase, &comment);
725 if (private == NULL) {
726 memset(passphrase, 0, strlen(passphrase));
728 printf("Bad passphrase.\n");
732 passphrase = xstrdup("");
734 if (private->type != KEY_RSA1) {
735 fprintf(stderr, "Comments are only supported for RSA1 keys.\n");
739 printf("Key now has comment '%s'\n", comment);
741 if (identity_comment) {
742 strlcpy(new_comment, identity_comment, sizeof(new_comment));
744 printf("Enter new comment: ");
746 if (!fgets(new_comment, sizeof(new_comment), stdin)) {
747 memset(passphrase, 0, strlen(passphrase));
751 if (strchr(new_comment, '\n'))
752 *strchr(new_comment, '\n') = 0;
755 /* Save the file using the new passphrase. */
756 if (!key_save_private(private, identity_file, passphrase, new_comment)) {
757 printf("Saving the key failed: %s.\n", identity_file);
758 memset(passphrase, 0, strlen(passphrase));
764 memset(passphrase, 0, strlen(passphrase));
766 public = key_from_private(private);
769 strlcat(identity_file, ".pub", sizeof(identity_file));
770 fd = open(identity_file, O_WRONLY | O_CREAT | O_TRUNC, 0644);
772 printf("Could not save your public key in %s\n", identity_file);
777 printf("fdopen %s failed", identity_file);
780 if (!key_write(public, f))
781 fprintf(stderr, "write key failed");
783 fprintf(f, " %s\n", new_comment);
788 printf("The comment in your key file has been changed.\n");
795 fprintf(stderr, "Usage: %s [options]\n", __progname);
796 fprintf(stderr, "Options:\n");
797 fprintf(stderr, " -b bits Number of bits in the key to create.\n");
798 fprintf(stderr, " -c Change comment in private and public key files.\n");
799 fprintf(stderr, " -e Convert OpenSSH to IETF SECSH key file.\n");
800 fprintf(stderr, " -f filename Filename of the key file.\n");
801 fprintf(stderr, " -i Convert IETF SECSH to OpenSSH key file.\n");
802 fprintf(stderr, " -l Show fingerprint of key file.\n");
803 fprintf(stderr, " -p Change passphrase of private key file.\n");
804 fprintf(stderr, " -q Quiet.\n");
805 fprintf(stderr, " -y Read private key file and print public key.\n");
806 fprintf(stderr, " -t type Specify type of key to create.\n");
807 fprintf(stderr, " -B Show bubblebabble digest of key file.\n");
808 fprintf(stderr, " -C comment Provide new comment.\n");
809 fprintf(stderr, " -N phrase Provide new passphrase.\n");
810 fprintf(stderr, " -P phrase Provide old passphrase.\n");
812 fprintf(stderr, " -D reader Download public key from smartcard.\n");
813 fprintf(stderr, " -U reader Upload private key to smartcard.\n");
814 #endif /* SMARTCARD */
820 * Main program for key management.
823 main(int ac, char **av)
825 char dotsshdir[16 * 1024], comment[1024], *passphrase1, *passphrase2;
826 char *reader_id = NULL;
827 Key *private, *public;
830 int opt, type, fd, download = 0;
836 __progname = get_progname(av[0]);
840 SSLeay_add_all_algorithms();
842 /* we need this for the home * directory. */
843 pw = getpwuid(getuid());
845 printf("You don't exist, go away!\n");
848 if (gethostname(hostname, sizeof(hostname)) < 0) {
849 perror("gethostname");
853 while ((opt = getopt(ac, av, "deiqpclBRxXyb:f:t:U:D:P:N:C:")) != -1) {
857 if (bits < 512 || bits > 32768) {
858 printf("Bits has bad value.\n");
863 print_fingerprint = 1;
866 print_bubblebabble = 1;
869 change_passphrase = 1;
875 strlcpy(identity_file, optarg, sizeof(identity_file));
879 identity_passphrase = optarg;
882 identity_new_passphrase = optarg;
885 identity_comment = optarg;
902 convert_from_ssh2 = 1;
908 key_type_name = "dsa";
911 key_type_name = optarg;
924 printf("Too many arguments.\n");
927 if (change_passphrase && change_comment) {
928 printf("Can only have one of -p and -c.\n");
931 if (print_fingerprint || print_bubblebabble)
933 if (change_passphrase)
934 do_change_passphrase(pw);
936 do_change_comment(pw);
938 do_convert_to_ssh2(pw);
939 if (convert_from_ssh2)
940 do_convert_from_ssh2(pw);
943 if (reader_id != NULL) {
946 do_download(pw, reader_id);
948 do_upload(pw, reader_id);
950 fatal("no support for smartcards.");
956 type = key_type_from_name(key_type_name);
957 if (type == KEY_UNSPEC) {
958 fprintf(stderr, "unknown key type %s\n", key_type_name);
962 printf("Generating public/private %s key pair.\n", key_type_name);
963 private = key_generate(type, bits);
964 if (private == NULL) {
965 fprintf(stderr, "key_generate failed");
968 public = key_from_private(private);
971 ask_filename(pw, "Enter file in which to save the key");
973 /* Create ~/.ssh directory if it doesn\'t already exist. */
974 snprintf(dotsshdir, sizeof dotsshdir, "%s/%s", pw->pw_dir, _PATH_SSH_USER_DIR);
975 if (strstr(identity_file, dotsshdir) != NULL &&
976 stat(dotsshdir, &st) < 0) {
977 if (mkdir(dotsshdir, 0700) < 0)
978 error("Could not create directory '%s'.", dotsshdir);
980 printf("Created directory '%s'.\n", dotsshdir);
982 /* If the file already exists, ask the user to confirm. */
983 if (stat(identity_file, &st) >= 0) {
985 printf("%s already exists.\n", identity_file);
986 printf("Overwrite (y/n)? ");
988 if (fgets(yesno, sizeof(yesno), stdin) == NULL)
990 if (yesno[0] != 'y' && yesno[0] != 'Y')
993 /* Ask for a passphrase (twice). */
994 if (identity_passphrase)
995 passphrase1 = xstrdup(identity_passphrase);
996 else if (identity_new_passphrase)
997 passphrase1 = xstrdup(identity_new_passphrase);
1001 read_passphrase("Enter passphrase (empty for no "
1002 "passphrase): ", RP_ALLOW_STDIN);
1003 passphrase2 = read_passphrase("Enter same passphrase again: ",
1005 if (strcmp(passphrase1, passphrase2) != 0) {
1007 * The passphrases do not match. Clear them and
1010 memset(passphrase1, 0, strlen(passphrase1));
1011 memset(passphrase2, 0, strlen(passphrase2));
1014 printf("Passphrases do not match. Try again.\n");
1015 goto passphrase_again;
1017 /* Clear the other copy of the passphrase. */
1018 memset(passphrase2, 0, strlen(passphrase2));
1022 if (identity_comment) {
1023 strlcpy(comment, identity_comment, sizeof(comment));
1025 /* Create default commend field for the passphrase. */
1026 snprintf(comment, sizeof comment, "%s@%s", pw->pw_name, hostname);
1029 /* Save the key with the given passphrase and comment. */
1030 if (!key_save_private(private, identity_file, passphrase1, comment)) {
1031 printf("Saving the key failed: %s.\n", identity_file);
1032 memset(passphrase1, 0, strlen(passphrase1));
1036 /* Clear the passphrase. */
1037 memset(passphrase1, 0, strlen(passphrase1));
1040 /* Clear the private key and the random number generator. */
1045 printf("Your identification has been saved in %s.\n", identity_file);
1047 strlcat(identity_file, ".pub", sizeof(identity_file));
1048 fd = open(identity_file, O_WRONLY | O_CREAT | O_TRUNC, 0644);
1050 printf("Could not save your public key in %s\n", identity_file);
1053 f = fdopen(fd, "w");
1055 printf("fdopen %s failed", identity_file);
1058 if (!key_write(public, f))
1059 fprintf(stderr, "write key failed");
1060 fprintf(f, " %s\n", comment);
1064 char *fp = key_fingerprint(public, SSH_FP_MD5, SSH_FP_HEX);
1065 printf("Your public key has been saved in %s.\n",
1067 printf("The key fingerprint is:\n");
1068 printf("%s %s\n", fp, comment);