[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.257 and 1.264

version 1.257, 2015/01/18 21:51:19 version 1.264, 2015/02/23 22:21:21
Line 706 
Line 706 
                 fatal("%s: unknown key format %d", __func__, convert_format);                  fatal("%s: unknown key format %d", __func__, convert_format);
         }          }
   
         if (!private)          if (!private) {
                 if ((r = sshkey_write(k, stdout)) == 0)                  if ((r = sshkey_write(k, stdout)) == 0)
                         ok = 1;                          ok = 1;
                 if (ok)                  if (ok)
                         fprintf(stdout, "\n");                          fprintf(stdout, "\n");
         else {          } else {
                 switch (k->type) {                  switch (k->type) {
                 case KEY_DSA:                  case KEY_DSA:
                         ok = PEM_write_DSAPrivateKey(stdout, k->dsa, NULL,                          ok = PEM_write_DSAPrivateKey(stdout, k->dsa, NULL,
Line 783 
Line 783 
                         fp = sshkey_fingerprint(keys[i], fptype, rep);                          fp = sshkey_fingerprint(keys[i], fptype, rep);
                         ra = sshkey_fingerprint(keys[i], fingerprint_hash,                          ra = sshkey_fingerprint(keys[i], fingerprint_hash,
                             SSH_FP_RANDOMART);                              SSH_FP_RANDOMART);
                           if (fp == NULL || ra == NULL)
                                   fatal("%s: sshkey_fingerprint fail", __func__);
                         printf("%u %s %s (PKCS11 key)\n", sshkey_size(keys[i]),                          printf("%u %s %s (PKCS11 key)\n", sshkey_size(keys[i]),
                             fp, sshkey_type(keys[i]));                              fp, sshkey_type(keys[i]));
                         if (log_level >= SYSLOG_LEVEL_VERBOSE)                          if (log_level >= SYSLOG_LEVEL_VERBOSE)
Line 823 
Line 825 
                 exit(1);                  exit(1);
         }          }
         if ((r = sshkey_load_public(identity_file, &public, &comment)) != 0)          if ((r = sshkey_load_public(identity_file, &public, &comment)) != 0)
                 error("Error loading public key \"%s\": %s",                  debug2("Error loading public key \"%s\": %s",
                     identity_file, ssh_err(r));                      identity_file, ssh_err(r));
         else {          else {
                 fp = sshkey_fingerprint(public, fptype, rep);                  fp = sshkey_fingerprint(public, fptype, rep);
                 ra = sshkey_fingerprint(public, fingerprint_hash,                  ra = sshkey_fingerprint(public, fingerprint_hash,
                     SSH_FP_RANDOMART);                      SSH_FP_RANDOMART);
                   if (fp == NULL || ra == NULL)
                           fatal("%s: sshkey_fingerprint fail", __func__);
                 printf("%u %s %s (%s)\n", sshkey_size(public), fp, comment,                  printf("%u %s %s (%s)\n", sshkey_size(public), fp, comment,
                     sshkey_type(public));                      sshkey_type(public));
                 if (log_level >= SYSLOG_LEVEL_VERBOSE)                  if (log_level >= SYSLOG_LEVEL_VERBOSE)
Line 898 
Line 902 
                 fp = sshkey_fingerprint(public, fptype, rep);                  fp = sshkey_fingerprint(public, fptype, rep);
                 ra = sshkey_fingerprint(public, fingerprint_hash,                  ra = sshkey_fingerprint(public, fingerprint_hash,
                     SSH_FP_RANDOMART);                      SSH_FP_RANDOMART);
                   if (fp == NULL || ra == NULL)
                           fatal("%s: sshkey_fingerprint fail", __func__);
                 printf("%u %s %s (%s)\n", sshkey_size(public), fp,                  printf("%u %s %s (%s)\n", sshkey_size(public), fp,
                     comment ? comment : "no comment", sshkey_type(public));                      comment ? comment : "no comment", sshkey_type(public));
                 if (log_level >= SYSLOG_LEVEL_VERBOSE)                  if (log_level >= SYSLOG_LEVEL_VERBOSE)
Line 1027 
Line 1033 
         char *hashed, *cp, *hosts, *ohosts;          char *hashed, *cp, *hosts, *ohosts;
         int has_wild = l->hosts && strcspn(l->hosts, "*?!") != strlen(l->hosts);          int has_wild = l->hosts && strcspn(l->hosts, "*?!") != strlen(l->hosts);
   
         /* Retain invalid lines when hashing, but mark file as invalid. */          switch (l->status) {
         if (l->status == HKF_STATUS_INVALID) {          case HKF_STATUS_OK:
           case HKF_STATUS_MATCHED:
                   /*
                    * Don't hash hosts already already hashed, with wildcard
                    * characters or a CA/revocation marker.
                    */
                   if ((l->match & HKF_MATCH_HOST_HASHED) != 0 ||
                       has_wild || l->marker != MRK_NONE) {
                           fprintf(ctx->out, "%s\n", l->line);
                           if (has_wild && !find_host) {
                                   fprintf(stderr, "%s:%ld: ignoring host name "
                                       "with wildcard: %.64s\n", l->path,
                                       l->linenum, l->hosts);
                           }
                           return 0;
                   }
                   /*
                    * Split any comma-separated hostnames from the host list,
                    * hash and store separately.
                    */
                   ohosts = hosts = xstrdup(l->hosts);
                   while ((cp = strsep(&hosts, ",")) != NULL && *cp != '\0') {
                           if ((hashed = host_hash(cp, NULL, 0)) == NULL)
                                   fatal("hash_host failed");
                           fprintf(ctx->out, "%s %s\n", hashed, l->rawkey);
                           ctx->has_unhashed = 1;
                   }
                   free(ohosts);
                   return 0;
           case HKF_STATUS_INVALID:
                   /* Retain invalid lines, but mark file as invalid. */
                 ctx->invalid = 1;                  ctx->invalid = 1;
                 fprintf(stderr, "%s:%ld: invalid line\n", l->path, l->linenum);                  fprintf(stderr, "%s:%ld: invalid line\n", l->path, l->linenum);
                   /* FALLTHROUGH */
           default:
                 fprintf(ctx->out, "%s\n", l->line);                  fprintf(ctx->out, "%s\n", l->line);
                 return 0;                  return 0;
         }          }
           /* NOTREACHED */
         /*          return -1;
          * Don't hash hosts already already hashed, with wildcard characters  
          * or a CA/revocation marker.  
          */  
         if (l->was_hashed || has_wild || l->marker != MRK_NONE) {  
                 fprintf(ctx->out, "%s\n", l->line);  
                 if (has_wild && !find_host) {  
                         fprintf(stderr, "%s:%ld: ignoring host name "  
                             "with wildcard: %.64s\n", l->path,  
                             l->linenum, l->hosts);  
                 }  
                 return 0;  
         }  
         /*  
          * Split any comma-separated hostnames from the host list,  
          * hash and store separately.  
          */  
         ohosts = hosts = xstrdup(l->hosts);  
         while ((cp = strsep(&hosts, ",")) != NULL && *cp != '\0') {  
                 if ((hashed = host_hash(cp, NULL, 0)) == NULL)  
                         fatal("hash_host failed");  
                 fprintf(ctx->out, "%s %s\n", hashed, l->rawkey);  
                 ctx->has_unhashed = 1;  
         }  
         free(ohosts);  
         return 0;  
 }  }
   
 static int  static int
Line 1068 
Line 1081 
 {  {
         struct known_hosts_ctx *ctx = (struct known_hosts_ctx *)_ctx;          struct known_hosts_ctx *ctx = (struct known_hosts_ctx *)_ctx;
   
         if (l->status == HKF_STATUS_HOST_MATCHED) {          if (l->status == HKF_STATUS_MATCHED) {
                 if (delete_host) {                  if (delete_host) {
                         if (l->marker != MRK_NONE) {                          if (l->marker != MRK_NONE) {
                                 /* Don't remove CA and revocation lines */                                  /* Don't remove CA and revocation lines */
Line 1114 
Line 1127 
 static void  static void
 do_known_hosts(struct passwd *pw, const char *name)  do_known_hosts(struct passwd *pw, const char *name)
 {  {
         char *cp, tmp[MAXPATHLEN], old[MAXPATHLEN];          char *cp, tmp[PATH_MAX], old[PATH_MAX];
         int r, fd, oerrno, inplace = 0;          int r, fd, oerrno, inplace = 0;
         struct known_hosts_ctx ctx;          struct known_hosts_ctx ctx;
   
Line 1155 
Line 1168 
         /* XXX support identity_file == "-" for stdin */          /* XXX support identity_file == "-" for stdin */
         if ((r = hostkeys_foreach(identity_file,          if ((r = hostkeys_foreach(identity_file,
             hash_hosts ? known_hosts_hash : known_hosts_find_delete, &ctx,              hash_hosts ? known_hosts_hash : known_hosts_find_delete, &ctx,
             name, find_host ? HKF_WANT_MATCH_HOST : 0)) != 0)              name, NULL, find_host ? HKF_WANT_MATCH : 0)) != 0)
                 fatal("%s: hostkeys_foreach failed: %s", __func__, ssh_err(r));                  fatal("%s: hostkeys_foreach failed: %s", __func__, ssh_err(r));
   
         if (inplace)          if (inplace)
Line 1883 
Line 1896 
         key_fp = sshkey_fingerprint(key, fingerprint_hash, SSH_FP_DEFAULT);          key_fp = sshkey_fingerprint(key, fingerprint_hash, SSH_FP_DEFAULT);
         ca_fp = sshkey_fingerprint(key->cert->signature_key,          ca_fp = sshkey_fingerprint(key->cert->signature_key,
             fingerprint_hash, SSH_FP_DEFAULT);              fingerprint_hash, SSH_FP_DEFAULT);
           if (key_fp == NULL || ca_fp == NULL)
                   fatal("%s: sshkey_fingerprint fail", __func__);
   
         printf("%s:\n", identity_file);          printf("%s:\n", identity_file);
         printf("        Type: %s %s certificate\n", sshkey_ssh_name(key),          printf("        Type: %s %s certificate\n", sshkey_ssh_name(key),
Line 1947 
Line 1962 
 }  }
   
 static void  static void
 update_krl_from_file(struct passwd *pw, const char *file,  update_krl_from_file(struct passwd *pw, const char *file, int wild_ca,
     const struct sshkey *ca, struct ssh_krl *krl)      const struct sshkey *ca, struct ssh_krl *krl)
 {  {
         struct sshkey *key = NULL;          struct sshkey *key = NULL;
Line 1989 
Line 2004 
                 if (*cp == '\0')                  if (*cp == '\0')
                         continue;                          continue;
                 if (strncasecmp(cp, "serial:", 7) == 0) {                  if (strncasecmp(cp, "serial:", 7) == 0) {
                         if (ca == NULL) {                          if (ca == NULL && !wild_ca) {
                                 fatal("revoking certificates by serial number "                                  fatal("revoking certificates by serial number "
                                     "requires specification of a CA key");                                      "requires specification of a CA key");
                         }                          }
Line 2026 
Line 2041 
                                     __func__);                                      __func__);
                         }                          }
                 } else if (strncasecmp(cp, "id:", 3) == 0) {                  } else if (strncasecmp(cp, "id:", 3) == 0) {
                         if (ca == NULL) {                          if (ca == NULL && !wild_ca) {
                                 fatal("revoking certificates by key ID "                                  fatal("revoking certificates by key ID "
                                     "requires specification of a CA key");                                      "requires specification of a CA key");
                         }                          }
Line 2077 
Line 2092 
         struct ssh_krl *krl;          struct ssh_krl *krl;
         struct stat sb;          struct stat sb;
         struct sshkey *ca = NULL;          struct sshkey *ca = NULL;
         int fd, i, r;          int fd, i, r, wild_ca = 0;
         char *tmp;          char *tmp;
         struct sshbuf *kbuf;          struct sshbuf *kbuf;
   
Line 2091 
Line 2106 
                         fatal("KRL \"%s\" does not exist", identity_file);                          fatal("KRL \"%s\" does not exist", identity_file);
         }          }
         if (ca_key_path != NULL) {          if (ca_key_path != NULL) {
                 tmp = tilde_expand_filename(ca_key_path, pw->pw_uid);                  if (strcasecmp(ca_key_path, "none") == 0)
                 if ((r = sshkey_load_public(tmp, &ca, NULL)) != 0)                          wild_ca = 1;
                         fatal("Cannot load CA public key %s: %s",                  else {
                             tmp, ssh_err(r));                          tmp = tilde_expand_filename(ca_key_path, pw->pw_uid);
                 free(tmp);                          if ((r = sshkey_load_public(tmp, &ca, NULL)) != 0)
                                   fatal("Cannot load CA public key %s: %s",
                                       tmp, ssh_err(r));
                           free(tmp);
                   }
         }          }
   
         if (updating)          if (updating)
Line 2109 
Line 2128 
                 ssh_krl_set_comment(krl, identity_comment);                  ssh_krl_set_comment(krl, identity_comment);
   
         for (i = 0; i < argc; i++)          for (i = 0; i < argc; i++)
                 update_krl_from_file(pw, argv[i], ca, krl);                  update_krl_from_file(pw, argv[i], wild_ca, ca, krl);
   
         if ((kbuf = sshbuf_new()) == NULL)          if ((kbuf = sshbuf_new()) == NULL)
                 fatal("sshbuf_new failed");                  fatal("sshbuf_new failed");
Line 2199 
Line 2218 
 {  {
         char dotsshdir[PATH_MAX], comment[1024], *passphrase1, *passphrase2;          char dotsshdir[PATH_MAX], comment[1024], *passphrase1, *passphrase2;
         char *checkpoint = NULL;          char *checkpoint = NULL;
         char out_file[PATH_MAX], *rr_hostname = NULL, *ep;          char out_file[PATH_MAX], *rr_hostname = NULL, *ep, *fp, *ra;
         struct sshkey *private, *public;          struct sshkey *private, *public;
         struct passwd *pw;          struct passwd *pw;
         struct stat st;          struct stat st;
Line 2686 
Line 2705 
         fclose(f);          fclose(f);
   
         if (!quiet) {          if (!quiet) {
                 char *fp = sshkey_fingerprint(public, fingerprint_hash,                  fp = sshkey_fingerprint(public, fingerprint_hash,
                     SSH_FP_DEFAULT);                      SSH_FP_DEFAULT);
                 char *ra = sshkey_fingerprint(public, fingerprint_hash,                  ra = sshkey_fingerprint(public, fingerprint_hash,
                     SSH_FP_RANDOMART);                      SSH_FP_RANDOMART);
                   if (fp == NULL || ra == NULL)
                           fatal("sshkey_fingerprint failed");
                 printf("Your public key has been saved in %s.\n",                  printf("Your public key has been saved in %s.\n",
                     identity_file);                      identity_file);
                 printf("The key fingerprint is:\n");                  printf("The key fingerprint is:\n");

Legend:
Removed from v.1.257  
changed lines
  Added in v.1.264