[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.189 and 1.191

version 1.189, 2010/04/23 22:48:31 version 1.191, 2010/06/22 04:32:06
Line 114 
Line 114 
 u_int64_t cert_valid_to = ~0ULL;  u_int64_t cert_valid_to = ~0ULL;
   
 /* Certificate options */  /* Certificate options */
 #define CRITOPT_X_FWD   (1)  #define CERTOPT_X_FWD   (1)
 #define CRITOPT_AGENT_FWD       (1<<1)  #define CERTOPT_AGENT_FWD       (1<<1)
 #define CRITOPT_PORT_FWD        (1<<2)  #define CERTOPT_PORT_FWD        (1<<2)
 #define CRITOPT_PTY             (1<<3)  #define CERTOPT_PTY             (1<<3)
 #define CRITOPT_USER_RC (1<<4)  #define CERTOPT_USER_RC (1<<4)
 #define CRITOPT_DEFAULT (CRITOPT_X_FWD|CRITOPT_AGENT_FWD| \  #define CERTOPT_DEFAULT (CERTOPT_X_FWD|CERTOPT_AGENT_FWD| \
                                 CRITOPT_PORT_FWD|CRITOPT_PTY| \                           CERTOPT_PORT_FWD|CERTOPT_PTY|CERTOPT_USER_RC)
                                 CRITOPT_USER_RC)  u_int32_t certflags_flags = CERTOPT_DEFAULT;
 u_int32_t critical_flags = CRITOPT_DEFAULT;  char *certflags_command = NULL;
 char *critical_command = NULL;  char *certflags_src_addr = NULL;
 char *critical_src_addr = NULL;  
   
 /* Dump public key file in format used by real and the original SSH 2 */  /* Dump public key file in format used by real and the original SSH 2 */
 int convert_to_ssh2 = 0;  int convert_to_ssh2 = 0;
Line 407 
Line 406 
                 perror(identity_file);                  perror(identity_file);
                 exit(1);                  exit(1);
         }          }
         fp = fopen(identity_file, "r");          if ((fp = fopen(identity_file, "r")) == NULL)
         if (fp == NULL) {                  fatal("%s: %s: %s", __progname, identity_file, strerror(errno));
                 perror(identity_file);  
                 exit(1);  
         }  
         encoded[0] = '\0';          encoded[0] = '\0';
         while ((blen = get_line(fp, line, sizeof(line))) != -1) {          while ((blen = get_line(fp, line, sizeof(line))) != -1) {
                 if (line[blen - 1] == '\\')                  if (line[blen - 1] == '\\')
Line 554 
Line 550 
                 comment = NULL;                  comment = NULL;
         }          }
   
         f = fopen(identity_file, "r");          if ((f = fopen(identity_file, "r")) == NULL)
         if (f != NULL) {                  fatal("%s: %s: %s", __progname, identity_file, strerror(errno));
                 while (fgets(line, sizeof(line), f)) {  
                         if ((cp = strchr(line, '\n')) == NULL) {  
                                 error("line %d too long: %.40s...",  
                                     num + 1, line);  
                                 skip = 1;  
                                 continue;  
                         }  
                         num++;  
                         if (skip) {  
                                 skip = 0;  
                                 continue;  
                         }  
                         *cp = '\0';  
   
                         /* Skip leading whitespace, empty and comment lines. */          while (fgets(line, sizeof(line), f)) {
                         for (cp = line; *cp == ' ' || *cp == '\t'; cp++)                  if ((cp = strchr(line, '\n')) == NULL) {
                                 ;                          error("line %d too long: %.40s...",
                         if (!*cp || *cp == '\n' || *cp == '#')                              num + 1, line);
                                 continue;                          skip = 1;
                         i = strtol(cp, &ep, 10);                          continue;
                         if (i == 0 || ep == NULL || (*ep != ' ' && *ep != '\t')) {                  }
                                 int quoted = 0;                  num++;
                                 comment = cp;                  if (skip) {
                                 for (; *cp && (quoted || (*cp != ' ' &&                          skip = 0;
                                     *cp != '\t')); cp++) {                          continue;
                                         if (*cp == '\\' && cp[1] == '"')                  }
                                                 cp++;   /* Skip both */                  *cp = '\0';
                                         else if (*cp == '"')  
                                                 quoted = !quoted;                  /* Skip leading whitespace, empty and comment lines. */
                                 }                  for (cp = line; *cp == ' ' || *cp == '\t'; cp++)
                                 if (!*cp)                          ;
                                         continue;                  if (!*cp || *cp == '\n' || *cp == '#')
                                 *cp++ = '\0';                          continue;
                   i = strtol(cp, &ep, 10);
                   if (i == 0 || ep == NULL || (*ep != ' ' && *ep != '\t')) {
                           int quoted = 0;
                           comment = cp;
                           for (; *cp && (quoted || (*cp != ' ' &&
                               *cp != '\t')); cp++) {
                                   if (*cp == '\\' && cp[1] == '"')
                                           cp++;   /* Skip both */
                                   else if (*cp == '"')
                                           quoted = !quoted;
                         }                          }
                         ep = cp;                          if (!*cp)
                         public = key_new(KEY_RSA1);                                  continue;
                           *cp++ = '\0';
                   }
                   ep = cp;
                   public = key_new(KEY_RSA1);
                   if (key_read(public, &cp) != 1) {
                           cp = ep;
                           key_free(public);
                           public = key_new(KEY_UNSPEC);
                         if (key_read(public, &cp) != 1) {                          if (key_read(public, &cp) != 1) {
                                 cp = ep;  
                                 key_free(public);                                  key_free(public);
                                 public = key_new(KEY_UNSPEC);                                  continue;
                                 if (key_read(public, &cp) != 1) {  
                                         key_free(public);  
                                         continue;  
                                 }  
                         }                          }
                         comment = *cp ? cp : comment;  
                         fp = key_fingerprint(public, fptype, rep);  
                         ra = key_fingerprint(public, SSH_FP_MD5, SSH_FP_RANDOMART);  
                         printf("%u %s %s (%s)\n", key_size(public), fp,  
                             comment ? comment : "no comment", key_type(public));  
                         if (log_level >= SYSLOG_LEVEL_VERBOSE)  
                                 printf("%s\n", ra);  
                         xfree(ra);  
                         xfree(fp);  
                         key_free(public);  
                         invalid = 0;  
                 }                  }
                 fclose(f);                  comment = *cp ? cp : comment;
                   fp = key_fingerprint(public, fptype, rep);
                   ra = key_fingerprint(public, SSH_FP_MD5, SSH_FP_RANDOMART);
                   printf("%u %s %s (%s)\n", key_size(public), fp,
                       comment ? comment : "no comment", key_type(public));
                   if (log_level >= SYSLOG_LEVEL_VERBOSE)
                           printf("%s\n", ra);
                   xfree(ra);
                   xfree(fp);
                   key_free(public);
                   invalid = 0;
         }          }
           fclose(f);
   
         if (invalid) {          if (invalid) {
                 printf("%s is not a public key file.\n", identity_file);                  printf("%s is not a public key file.\n", identity_file);
                 exit(1);                  exit(1);
Line 669 
Line 666 
                 have_identity = 1;                  have_identity = 1;
         }          }
         if ((in = fopen(identity_file, "r")) == NULL)          if ((in = fopen(identity_file, "r")) == NULL)
                 fatal("fopen: %s", strerror(errno));                  fatal("%s: %s: %s", __progname, identity_file, strerror(errno));
   
         /*          /*
          * Find hosts goes to stdout, hash and deletions happen in-place           * Find hosts goes to stdout, hash and deletions happen in-place
Line 1125 
Line 1122 
         buffer_free(&b);          buffer_free(&b);
 }  }
   
   #define OPTIONS_CRITICAL        1
   #define OPTIONS_EXTENSIONS      2
 static void  static void
 prepare_options_buf(Buffer *c)  prepare_options_buf(Buffer *c, int which)
 {  {
         buffer_clear(c);          buffer_clear(c);
         if ((critical_flags & CRITOPT_X_FWD) != 0)          if ((which & OPTIONS_EXTENSIONS) != 0 &&
               (certflags_flags & CERTOPT_X_FWD) != 0)
                 add_flag_option(c, "permit-X11-forwarding");                  add_flag_option(c, "permit-X11-forwarding");
         if ((critical_flags & CRITOPT_AGENT_FWD) != 0)          if ((which & OPTIONS_EXTENSIONS) != 0 &&
               (certflags_flags & CERTOPT_AGENT_FWD) != 0)
                 add_flag_option(c, "permit-agent-forwarding");                  add_flag_option(c, "permit-agent-forwarding");
         if ((critical_flags & CRITOPT_PORT_FWD) != 0)          if ((which & OPTIONS_EXTENSIONS) != 0 &&
               (certflags_flags & CERTOPT_PORT_FWD) != 0)
                 add_flag_option(c, "permit-port-forwarding");                  add_flag_option(c, "permit-port-forwarding");
         if ((critical_flags & CRITOPT_PTY) != 0)          if ((which & OPTIONS_EXTENSIONS) != 0 &&
               (certflags_flags & CERTOPT_PTY) != 0)
                 add_flag_option(c, "permit-pty");                  add_flag_option(c, "permit-pty");
         if ((critical_flags & CRITOPT_USER_RC) != 0)          if ((which & OPTIONS_EXTENSIONS) != 0 &&
               (certflags_flags & CERTOPT_USER_RC) != 0)
                 add_flag_option(c, "permit-user-rc");                  add_flag_option(c, "permit-user-rc");
         if (critical_command != NULL)          if ((which & OPTIONS_CRITICAL) != 0 &&
                 add_string_option(c, "force-command", critical_command);              certflags_command != NULL)
         if (critical_src_addr != NULL)                  add_string_option(c, "force-command", certflags_command);
                 add_string_option(c, "source-address", critical_src_addr);          if ((which & OPTIONS_CRITICAL) != 0 &&
               certflags_src_addr != NULL)
                   add_string_option(c, "source-address", certflags_src_addr);
 }  }
   
 static void  static void
Line 1210 
Line 1216 
                 public->cert->principals = plist;                  public->cert->principals = plist;
                 public->cert->valid_after = cert_valid_from;                  public->cert->valid_after = cert_valid_from;
                 public->cert->valid_before = cert_valid_to;                  public->cert->valid_before = cert_valid_to;
                 prepare_options_buf(&public->cert->critical);                  if (v00) {
                           prepare_options_buf(&public->cert->critical,
                               OPTIONS_CRITICAL|OPTIONS_EXTENSIONS);
                   } else {
                           prepare_options_buf(&public->cert->critical,
                               OPTIONS_CRITICAL);
                           prepare_options_buf(&public->cert->extensions,
                               OPTIONS_EXTENSIONS);
                   }
                 public->cert->signature_key = key_from_private(ca);                  public->cert->signature_key = key_from_private(ca);
   
                 if (key_certify(public, ca) != 0)                  if (key_certify(public, ca) != 0)
Line 1346 
Line 1360 
         char *val;          char *val;
   
         if (strcmp(opt, "clear") == 0)          if (strcmp(opt, "clear") == 0)
                 critical_flags = 0;                  certflags_flags = 0;
         else if (strcasecmp(opt, "no-x11-forwarding") == 0)          else if (strcasecmp(opt, "no-x11-forwarding") == 0)
                 critical_flags &= ~CRITOPT_X_FWD;                  certflags_flags &= ~CERTOPT_X_FWD;
         else if (strcasecmp(opt, "permit-x11-forwarding") == 0)          else if (strcasecmp(opt, "permit-x11-forwarding") == 0)
                 critical_flags |= CRITOPT_X_FWD;                  certflags_flags |= CERTOPT_X_FWD;
         else if (strcasecmp(opt, "no-agent-forwarding") == 0)          else if (strcasecmp(opt, "no-agent-forwarding") == 0)
                 critical_flags &= ~CRITOPT_AGENT_FWD;                  certflags_flags &= ~CERTOPT_AGENT_FWD;
         else if (strcasecmp(opt, "permit-agent-forwarding") == 0)          else if (strcasecmp(opt, "permit-agent-forwarding") == 0)
                 critical_flags |= CRITOPT_AGENT_FWD;                  certflags_flags |= CERTOPT_AGENT_FWD;
         else if (strcasecmp(opt, "no-port-forwarding") == 0)          else if (strcasecmp(opt, "no-port-forwarding") == 0)
                 critical_flags &= ~CRITOPT_PORT_FWD;                  certflags_flags &= ~CERTOPT_PORT_FWD;
         else if (strcasecmp(opt, "permit-port-forwarding") == 0)          else if (strcasecmp(opt, "permit-port-forwarding") == 0)
                 critical_flags |= CRITOPT_PORT_FWD;                  certflags_flags |= CERTOPT_PORT_FWD;
         else if (strcasecmp(opt, "no-pty") == 0)          else if (strcasecmp(opt, "no-pty") == 0)
                 critical_flags &= ~CRITOPT_PTY;                  certflags_flags &= ~CERTOPT_PTY;
         else if (strcasecmp(opt, "permit-pty") == 0)          else if (strcasecmp(opt, "permit-pty") == 0)
                 critical_flags |= CRITOPT_PTY;                  certflags_flags |= CERTOPT_PTY;
         else if (strcasecmp(opt, "no-user-rc") == 0)          else if (strcasecmp(opt, "no-user-rc") == 0)
                 critical_flags &= ~CRITOPT_USER_RC;                  certflags_flags &= ~CERTOPT_USER_RC;
         else if (strcasecmp(opt, "permit-user-rc") == 0)          else if (strcasecmp(opt, "permit-user-rc") == 0)
                 critical_flags |= CRITOPT_USER_RC;                  certflags_flags |= CERTOPT_USER_RC;
         else if (strncasecmp(opt, "force-command=", 14) == 0) {          else if (strncasecmp(opt, "force-command=", 14) == 0) {
                 val = opt + 14;                  val = opt + 14;
                 if (*val == '\0')                  if (*val == '\0')
                         fatal("Empty force-command option");                          fatal("Empty force-command option");
                 if (critical_command != NULL)                  if (certflags_command != NULL)
                         fatal("force-command already specified");                          fatal("force-command already specified");
                 critical_command = xstrdup(val);                  certflags_command = xstrdup(val);
         } else if (strncasecmp(opt, "source-address=", 15) == 0) {          } else if (strncasecmp(opt, "source-address=", 15) == 0) {
                 val = opt + 15;                  val = opt + 15;
                 if (*val == '\0')                  if (*val == '\0')
                         fatal("Empty source-address option");                          fatal("Empty source-address option");
                 if (critical_src_addr != NULL)                  if (certflags_src_addr != NULL)
                         fatal("source-address already specified");                          fatal("source-address already specified");
                 if (addr_match_cidr_list(NULL, val) != 0)                  if (addr_match_cidr_list(NULL, val) != 0)
                         fatal("Invalid source-address list");                          fatal("Invalid source-address list");
                 critical_src_addr = xstrdup(val);                  certflags_src_addr = xstrdup(val);
         } else          } else
                 fatal("Unsupported certificate option \"%s\"", opt);                  fatal("Unsupported certificate option \"%s\"", opt);
 }  }
Line 1399 
Line 1413 
   
         if (!have_identity)          if (!have_identity)
                 ask_filename(pw, "Enter file in which the key is");                  ask_filename(pw, "Enter file in which the key is");
         if (stat(identity_file, &st) < 0) {          if (stat(identity_file, &st) < 0)
                 perror(identity_file);                  fatal("%s: %s: %s", __progname, identity_file, strerror(errno));
                 exit(1);  
         }  
         if ((key = key_load_public(identity_file, NULL)) == NULL)          if ((key = key_load_public(identity_file, NULL)) == NULL)
                 fatal("%s is not a public key", identity_file);                  fatal("%s is not a public key", identity_file);
         if (!key_is_cert(key))          if (!key_is_cert(key))
Line 1654 
Line 1666 
                         break;                          break;
                 case 'h':                  case 'h':
                         cert_key_type = SSH2_CERT_TYPE_HOST;                          cert_key_type = SSH2_CERT_TYPE_HOST;
                         critical_flags = 0;                          certflags_flags = 0;
                         break;                          break;
                 case 'i':                  case 'i':
                 case 'X':                  case 'X':

Legend:
Removed from v.1.189  
changed lines
  Added in v.1.191