[BACK]Return to ssh-keygen.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ssh

Diff for /src/usr.bin/ssh/ssh-keygen.c between version 1.54 and 1.64

version 1.54, 2001/04/03 13:56:11 version 1.64, 2001/06/23 17:05:22
Line 75 
Line 75 
   
 char hostname[MAXHOSTNAMELEN];  char hostname[MAXHOSTNAMELEN];
   
 void  static void
 ask_filename(struct passwd *pw, const char *prompt)  ask_filename(struct passwd *pw, const char *prompt)
 {  {
         char buf[1024];          char buf[1024];
Line 108 
Line 108 
         have_identity = 1;          have_identity = 1;
 }  }
   
 Key *  static Key *
 try_load_pem_key(char *filename)  load_identity(char *filename)
 {  {
         char *pass;          char *pass;
         Key *prv;          Key *prv;
   
         prv = key_load_private(filename, "", NULL);          prv = key_load_private(filename, "", NULL);
         if (prv == NULL) {          if (prv == NULL) {
                 pass = read_passphrase("Enter passphrase: ", 1);                  if (identity_passphrase)
                           pass = xstrdup(identity_passphrase);
                   else
                           pass = read_passphrase("Enter passphrase: ", 1);
                 prv = key_load_private(filename, pass, NULL);                  prv = key_load_private(filename, pass, NULL);
                 memset(pass, 0, strlen(pass));                  memset(pass, 0, strlen(pass));
                 xfree(pass);                  xfree(pass);
Line 129 
Line 132 
 #define SSH_COM_PRIVATE_BEGIN           "---- BEGIN SSH2 ENCRYPTED PRIVATE KEY ----"  #define SSH_COM_PRIVATE_BEGIN           "---- BEGIN SSH2 ENCRYPTED PRIVATE KEY ----"
 #define SSH_COM_PRIVATE_KEY_MAGIC       0x3f6ff9eb  #define SSH_COM_PRIVATE_KEY_MAGIC       0x3f6ff9eb
   
 void  static void
 do_convert_to_ssh2(struct passwd *pw)  do_convert_to_ssh2(struct passwd *pw)
 {  {
         Key *prv;          Key *k;
         int len;          int len;
         u_char *blob;          u_char *blob;
         struct stat st;          struct stat st;
Line 143 
Line 146 
                 perror(identity_file);                  perror(identity_file);
                 exit(1);                  exit(1);
         }          }
         prv = try_load_pem_key(identity_file);          if ((k = key_load_public(identity_file, NULL)) == NULL) {
         if (prv == NULL) {                  if ((k = load_identity(identity_file)) == NULL) {
                 fprintf(stderr, "load failed\n");                          fprintf(stderr, "load failed\n");
                 exit(1);                          exit(1);
                   }
         }          }
         key_to_blob(prv, &blob, &len);          key_to_blob(k, &blob, &len);
         fprintf(stdout, "%s\n", SSH_COM_PUBLIC_BEGIN);          fprintf(stdout, "%s\n", SSH_COM_PUBLIC_BEGIN);
         fprintf(stdout,          fprintf(stdout,
             "Comment: \"%d-bit %s, converted from OpenSSH by %s@%s\"\n",              "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);              pw->pw_name, hostname);
         dump_base64(stdout, blob, len);          dump_base64(stdout, blob, len);
         fprintf(stdout, "%s\n", SSH_COM_PUBLIC_END);          fprintf(stdout, "%s\n", SSH_COM_PUBLIC_END);
         key_free(prv);          key_free(k);
         xfree(blob);          xfree(blob);
         exit(0);          exit(0);
 }  }
   
 void  static void
 buffer_get_bignum_bits(Buffer *b, BIGNUM *value)  buffer_get_bignum_bits(Buffer *b, BIGNUM *value)
 {  {
         int bits = buffer_get_int(b);          int bits = buffer_get_int(b);
Line 174 
Line 178 
         buffer_consume(b, bytes);          buffer_consume(b, bytes);
 }  }
   
 Key *  static Key *
 do_convert_private_ssh2_from_blob(char *blob, int blen)  do_convert_private_ssh2_from_blob(char *blob, int blen)
 {  {
         Buffer b;          Buffer b;
         Key *key = NULL;          Key *key = NULL;
         int ignore, magic, rlen, ktype;  
         char *type, *cipher;          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_init(&b);
         buffer_append(&b, blob, blen);          buffer_append(&b, blob, blen);
Line 191 
Line 198 
                 buffer_free(&b);                  buffer_free(&b);
                 return NULL;                  return NULL;
         }          }
         ignore = buffer_get_int(&b);          i1 = buffer_get_int(&b);
         type   = buffer_get_string(&b, NULL);          type   = buffer_get_string(&b, NULL);
         cipher = buffer_get_string(&b, NULL);          cipher = buffer_get_string(&b, NULL);
         ignore = buffer_get_int(&b);          i2 = buffer_get_int(&b);
         ignore = buffer_get_int(&b);          i3 = buffer_get_int(&b);
         ignore = buffer_get_int(&b);          i4 = buffer_get_int(&b);
           debug("ignore (%d %d %d %d)", i1,i2,i3,i4);
         if (strcmp(cipher, "none") != 0) {          if (strcmp(cipher, "none") != 0) {
                 error("unsupported cipher %s", cipher);                  error("unsupported cipher %s", cipher);
                 xfree(cipher);                  xfree(cipher);
Line 227 
Line 234 
                 buffer_get_bignum_bits(&b, key->dsa->priv_key);                  buffer_get_bignum_bits(&b, key->dsa->priv_key);
                 break;                  break;
         case KEY_RSA:          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);                          buffer_free(&b);
                         key_free(key);                          key_free(key);
                         return NULL;                          return NULL;
Line 245 
Line 262 
                 error("do_convert_private_ssh2_from_blob: "                  error("do_convert_private_ssh2_from_blob: "
                     "remaining bytes in key blob %d", rlen);                      "remaining bytes in key blob %d", rlen);
         buffer_free(&b);          buffer_free(&b);
 #ifdef DEBUG_PK  
         {  
                 u_int slen;  
                 u_char *sig, data[10] = "abcde12345";  
   
                 key_sign(key, &sig, &slen, data, sizeof data);          /* try the key */
                 key_verify(key, sig, slen, data, sizeof data);          key_sign(key, &sig, &slen, data, sizeof(data));
                 xfree(sig);          key_verify(key, sig, slen, data, sizeof(data));
         }          xfree(sig);
 #endif  
         return key;          return key;
 }  }
   
 void  static void
 do_convert_from_ssh2(struct passwd *pw)  do_convert_from_ssh2(struct passwd *pw)
 {  {
         Key *k;          Key *k;
Line 293 
Line 305 
                     strstr(line, ": ") != NULL) {                      strstr(line, ": ") != NULL) {
                         if (strstr(line, SSH_COM_PRIVATE_BEGIN) != NULL)                          if (strstr(line, SSH_COM_PRIVATE_BEGIN) != NULL)
                                 private = 1;                                  private = 1;
                         fprintf(stderr, "ignore: %s", line);                          if (strstr(line, " END ") != NULL) {
                                   break;
                           }
                           /* fprintf(stderr, "ignore: %s", line); */
                         continue;                          continue;
                 }                  }
                 if (escaped) {                  if (escaped) {
                         escaped--;                          escaped--;
                         fprintf(stderr, "escaped: %s", line);                          /* fprintf(stderr, "escaped: %s", line); */
                         continue;                          continue;
                 }                  }
                 *p = '\0';                  *p = '\0';
Line 331 
Line 346 
         exit(0);          exit(0);
 }  }
   
 void  static void
 do_print_public(struct passwd *pw)  do_print_public(struct passwd *pw)
 {  {
         Key *prv;          Key *prv;
Line 343 
Line 358 
                 perror(identity_file);                  perror(identity_file);
                 exit(1);                  exit(1);
         }          }
         prv = try_load_pem_key(identity_file);          prv = load_identity(identity_file);
         if (prv == NULL) {          if (prv == NULL) {
                 fprintf(stderr, "load failed\n");                  fprintf(stderr, "load failed\n");
                 exit(1);                  exit(1);
Line 355 
Line 370 
         exit(0);          exit(0);
 }  }
   
 void  static void
 do_fingerprint(struct passwd *pw)  do_fingerprint(struct passwd *pw)
 {  {
         FILE *f;          FILE *f;
Line 452 
Line 467 
  * Perform changing a passphrase.  The argument is the passwd structure   * Perform changing a passphrase.  The argument is the passwd structure
  * for the current user.   * for the current user.
  */   */
 void  static void
 do_change_passphrase(struct passwd *pw)  do_change_passphrase(struct passwd *pw)
 {  {
         char *comment;          char *comment;
Line 508 
Line 523 
   
         /* Save the file using the new passphrase. */          /* Save the file using the new passphrase. */
         if (!key_save_private(private, identity_file, passphrase1, comment)) {          if (!key_save_private(private, identity_file, passphrase1, comment)) {
                 printf("Saving the key failed: %s: %s.\n",                  printf("Saving the key failed: %s.\n", identity_file);
                        identity_file, strerror(errno));  
                 memset(passphrase1, 0, strlen(passphrase1));                  memset(passphrase1, 0, strlen(passphrase1));
                 xfree(passphrase1);                  xfree(passphrase1);
                 key_free(private);                  key_free(private);
Line 529 
Line 543 
 /*  /*
  * Change the comment of a private key file.   * Change the comment of a private key file.
  */   */
 void  static void
 do_change_comment(struct passwd *pw)  do_change_comment(struct passwd *pw)
 {  {
         char new_comment[1024], *comment, *passphrase;          char new_comment[1024], *comment, *passphrase;
Line 587 
Line 601 
   
         /* Save the file using the new passphrase. */          /* Save the file using the new passphrase. */
         if (!key_save_private(private, identity_file, passphrase, new_comment)) {          if (!key_save_private(private, identity_file, passphrase, new_comment)) {
                 printf("Saving the key failed: %s: %s.\n",                  printf("Saving the key failed: %s.\n", identity_file);
                        identity_file, strerror(errno));  
                 memset(passphrase, 0, strlen(passphrase));                  memset(passphrase, 0, strlen(passphrase));
                 xfree(passphrase);                  xfree(passphrase);
                 key_free(private);                  key_free(private);
Line 623 
Line 636 
         exit(0);          exit(0);
 }  }
   
 void  static void
 usage(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);              "[-N new-pass] [-P pass]\n", __progname);
         exit(1);          exit(1);
 }  }
Line 660 
Line 673 
                 exit(1);                  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) {                  switch (opt) {
                 case 'b':                  case 'b':
                         bits = atoi(optarg);                          bits = atoi(optarg);
Line 712 
Line 725 
                         exit(0);                          exit(0);
                         break;                          break;
   
                   case 'e':
                 case 'x':                  case 'x':
                           /* export key */
                         convert_to_ssh2 = 1;                          convert_to_ssh2 = 1;
                         break;                          break;
   
                   case 'i':
                 case 'X':                  case 'X':
                           /* import key */
                         convert_from_ssh2 = 1;                          convert_from_ssh2 = 1;
                         break;                          break;
   
Line 830 
Line 847 
   
         /* Save the key with the given passphrase and comment. */          /* Save the key with the given passphrase and comment. */
         if (!key_save_private(private, identity_file, passphrase1, comment)) {          if (!key_save_private(private, identity_file, passphrase1, comment)) {
                 printf("Saving the key failed: %s: %s.\n",                  printf("Saving the key failed: %s.\n", identity_file);
                     identity_file, strerror(errno));  
                 memset(passphrase1, 0, strlen(passphrase1));                  memset(passphrase1, 0, strlen(passphrase1));
                 xfree(passphrase1);                  xfree(passphrase1);
                 exit(1);                  exit(1);

Legend:
Removed from v.1.54  
changed lines
  Added in v.1.64