[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.365 and 1.374

version 1.365, 2019/11/18 01:59:48 version 1.374, 2019/12/10 22:37:20
Line 29 
Line 29 
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
   #include <stdarg.h>
 #include <unistd.h>  #include <unistd.h>
 #include <limits.h>  #include <limits.h>
 #include <locale.h>  #include <locale.h>
Line 113 
Line 114 
 static u_int64_t cert_valid_to = ~0ULL;  static u_int64_t cert_valid_to = ~0ULL;
   
 /* Certificate options */  /* Certificate options */
 #define CERTOPT_X_FWD   (1)  #define CERTOPT_X_FWD                           (1)
 #define CERTOPT_AGENT_FWD       (1<<1)  #define CERTOPT_AGENT_FWD                       (1<<1)
 #define CERTOPT_PORT_FWD        (1<<2)  #define CERTOPT_PORT_FWD                        (1<<2)
 #define CERTOPT_PTY             (1<<3)  #define CERTOPT_PTY                             (1<<3)
 #define CERTOPT_USER_RC (1<<4)  #define CERTOPT_USER_RC                         (1<<4)
   #define CERTOPT_NO_REQUIRE_USER_PRESENCE        (1<<5)
 #define CERTOPT_DEFAULT (CERTOPT_X_FWD|CERTOPT_AGENT_FWD| \  #define CERTOPT_DEFAULT (CERTOPT_X_FWD|CERTOPT_AGENT_FWD| \
                          CERTOPT_PORT_FWD|CERTOPT_PTY|CERTOPT_USER_RC)                           CERTOPT_PORT_FWD|CERTOPT_PTY|CERTOPT_USER_RC)
 static u_int32_t certflags_flags = CERTOPT_DEFAULT;  static u_int32_t certflags_flags = CERTOPT_DEFAULT;
Line 569 
Line 571 
         if (sshkey_sign(key, &sig, &slen, data, sizeof(data),          if (sshkey_sign(key, &sig, &slen, data, sizeof(data),
             NULL, NULL, 0) != 0 ||              NULL, NULL, 0) != 0 ||
             sshkey_verify(key, sig, slen, data, sizeof(data),              sshkey_verify(key, sig, slen, data, sizeof(data),
             NULL, 0) != 0) {              NULL, 0, NULL) != 0) {
                 sshkey_free(key);                  sshkey_free(key);
                 free(sig);                  free(sig);
                 return NULL;                  return NULL;
Line 1645 
Line 1647 
             (certflags_flags & CERTOPT_USER_RC) != 0)              (certflags_flags & CERTOPT_USER_RC) != 0)
                 add_flag_option(c, "permit-user-rc");                  add_flag_option(c, "permit-user-rc");
         if ((which & OPTIONS_CRITICAL) != 0 &&          if ((which & OPTIONS_CRITICAL) != 0 &&
               (certflags_flags & CERTOPT_NO_REQUIRE_USER_PRESENCE) != 0)
                   add_flag_option(c, "no-touch-required");
           if ((which & OPTIONS_CRITICAL) != 0 &&
             certflags_src_addr != NULL)              certflags_src_addr != NULL)
                 add_string_option(c, "source-address", certflags_src_addr);                  add_string_option(c, "source-address", certflags_src_addr);
         for (i = 0; i < ncert_userext; i++) {          for (i = 0; i < ncert_userext; i++) {
Line 1710 
Line 1715 
         int r, i, fd, found, agent_fd = -1;          int r, i, fd, found, agent_fd = -1;
         u_int n;          u_int n;
         struct sshkey *ca, *public;          struct sshkey *ca, *public;
         char valid[64], *otmp, *tmp, *cp, *out, *comment, **plist = NULL;          char valid[64], *otmp, *tmp, *cp, *out, *comment;
           char *ca_fp = NULL, **plist = NULL;
         FILE *f;          FILE *f;
         struct ssh_identitylist *agent_ids;          struct ssh_identitylist *agent_ids;
         size_t j;          size_t j;
           struct notifier_ctx *notifier = NULL;
   
 #ifdef ENABLE_PKCS11  #ifdef ENABLE_PKCS11
         pkcs11_init(1);          pkcs11_init(1);
Line 1759 
Line 1766 
                 fatal("CA key type %s doesn't match specified %s",                  fatal("CA key type %s doesn't match specified %s",
                     sshkey_ssh_name(ca), key_type_name);                      sshkey_ssh_name(ca), key_type_name);
         }          }
           ca_fp = sshkey_fingerprint(ca, fingerprint_hash, SSH_FP_DEFAULT);
   
         for (i = 0; i < argc; i++) {          for (i = 0; i < argc; i++) {
                 /* Split list of principals */                  /* Split list of principals */
Line 1780 
Line 1788 
                 if ((r = sshkey_load_public(tmp, &public, &comment)) != 0)                  if ((r = sshkey_load_public(tmp, &public, &comment)) != 0)
                         fatal("%s: unable to open \"%s\": %s",                          fatal("%s: unable to open \"%s\": %s",
                             __func__, tmp, ssh_err(r));                              __func__, tmp, ssh_err(r));
                 if (public->type != KEY_RSA && public->type != KEY_DSA &&                  if (sshkey_is_cert(public))
                     public->type != KEY_ECDSA && public->type != KEY_ED25519 &&  
                     public->type != KEY_XMSS)  
                         fatal("%s: key \"%s\" type %s cannot be certified",                          fatal("%s: key \"%s\" type %s cannot be certified",
                             __func__, tmp, sshkey_type(public));                              __func__, tmp, sshkey_type(public));
   
Line 1811 
Line 1817 
                                 fatal("Couldn't certify key %s via agent: %s",                                  fatal("Couldn't certify key %s via agent: %s",
                                     tmp, ssh_err(r));                                      tmp, ssh_err(r));
                 } else {                  } else {
                         if ((sshkey_certify(public, ca, key_type_name,                          if (sshkey_is_sk(ca) &&
                             sk_provider)) != 0)                              (ca->sk_flags & SSH_SK_USER_PRESENCE_REQD)) {
                                   notifier = notify_start(0,
                                       "Confirm user presence for key %s %s",
                                       sshkey_type(ca), ca_fp);
                           }
                           r = sshkey_certify(public, ca, key_type_name,
                               sk_provider);
                           notify_complete(notifier);
                           if (r != 0)
                                 fatal("Couldn't certify key %s: %s",                                  fatal("Couldn't certify key %s: %s",
                                     tmp, ssh_err(r));                                      tmp, ssh_err(r));
                 }                  }
Line 1850 
Line 1864 
                 if (cert_serial_autoinc)                  if (cert_serial_autoinc)
                         cert_serial++;                          cert_serial++;
         }          }
           free(ca_fp);
 #ifdef ENABLE_PKCS11  #ifdef ENABLE_PKCS11
         pkcs11_terminate();          pkcs11_terminate();
 #endif  #endif
Line 1948 
Line 1963 
                 certflags_flags &= ~CERTOPT_USER_RC;                  certflags_flags &= ~CERTOPT_USER_RC;
         else if (strcasecmp(opt, "permit-user-rc") == 0)          else if (strcasecmp(opt, "permit-user-rc") == 0)
                 certflags_flags |= CERTOPT_USER_RC;                  certflags_flags |= CERTOPT_USER_RC;
           else if (strcasecmp(opt, "touch-required") == 0)
                   certflags_flags &= ~CERTOPT_NO_REQUIRE_USER_PRESENCE;
           else if (strcasecmp(opt, "no-touch-required") == 0)
                   certflags_flags |= CERTOPT_NO_REQUIRE_USER_PRESENCE;
         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')
Line 2001 
Line 2020 
                     strcmp(name, "permit-agent-forwarding") == 0 ||                      strcmp(name, "permit-agent-forwarding") == 0 ||
                     strcmp(name, "permit-port-forwarding") == 0 ||                      strcmp(name, "permit-port-forwarding") == 0 ||
                     strcmp(name, "permit-pty") == 0 ||                      strcmp(name, "permit-pty") == 0 ||
                     strcmp(name, "permit-user-rc") == 0))                      strcmp(name, "permit-user-rc") == 0 ||
                       strcmp(name, "no-touch-required") == 0)) {
                         printf("\n");                          printf("\n");
                 else if (in_critical &&                  } else if (in_critical &&
                     (strcmp(name, "force-command") == 0 ||                      (strcmp(name, "force-command") == 0 ||
                     strcmp(name, "source-address") == 0)) {                      strcmp(name, "source-address") == 0)) {
                         if ((r = sshbuf_get_cstring(option, &arg, NULL)) != 0)                          if ((r = sshbuf_get_cstring(option, &arg, NULL)) != 0)
Line 2640 
Line 2660 
         struct sshbuf *sigbuf = NULL, *abuf = NULL;          struct sshbuf *sigbuf = NULL, *abuf = NULL;
         struct sshkey *sign_key = NULL;          struct sshkey *sign_key = NULL;
         char *fp = NULL;          char *fp = NULL;
           struct sshkey_sig_details *sig_details = NULL;
   
           memset(&sig_details, 0, sizeof(sig_details));
         if ((abuf = sshbuf_new()) == NULL)          if ((abuf = sshbuf_new()) == NULL)
                 fatal("%s: sshbuf_new() failed", __func__);                  fatal("%s: sshbuf_new() failed", __func__);
   
Line 2658 
Line 2680 
                 return r;                  return r;
         }          }
         if ((r = sshsig_verify_fd(sigbuf, STDIN_FILENO, sig_namespace,          if ((r = sshsig_verify_fd(sigbuf, STDIN_FILENO, sig_namespace,
             &sign_key)) != 0)              &sign_key, &sig_details)) != 0)
                 goto done; /* sshsig_verify() prints error */                  goto done; /* sshsig_verify() prints error */
   
         if ((fp = sshkey_fingerprint(sign_key, fingerprint_hash,          if ((fp = sshkey_fingerprint(sign_key, fingerprint_hash,
             SSH_FP_DEFAULT)) == NULL)              SSH_FP_DEFAULT)) == NULL)
                 fatal("%s: sshkey_fingerprint failed", __func__);                  fatal("%s: sshkey_fingerprint failed", __func__);
         debug("Valid (unverified) signature from key %s", fp);          debug("Valid (unverified) signature from key %s", fp);
           if (sig_details != NULL) {
                   debug2("%s: signature details: counter = %u, flags = 0x%02x",
                       __func__, sig_details->sk_counter, sig_details->sk_flags);
           }
         free(fp);          free(fp);
         fp = NULL;          fp = NULL;
   
Line 2709 
Line 2735 
         sshbuf_free(sigbuf);          sshbuf_free(sigbuf);
         sshbuf_free(abuf);          sshbuf_free(abuf);
         sshkey_free(sign_key);          sshkey_free(sign_key);
           sshkey_sig_details_free(sig_details);
         free(fp);          free(fp);
         return ret;          return ret;
 }  }
Line 2718 
Line 2745 
 {  {
         fprintf(stderr,          fprintf(stderr,
             "usage: ssh-keygen [-q] [-b bits] [-C comment] [-f output_keyfile] [-m format]\n"              "usage: ssh-keygen [-q] [-b bits] [-C comment] [-f output_keyfile] [-m format]\n"
             "                  [-t dsa | ecdsa | ecdsa-sk | ed25519 | rsa]\n"              "                  [-t dsa | ecdsa | ecdsa-sk | ed25519 | ed25519-sk | rsa]\n"
             "                  [-N new_passphrase] [-w provider] [-x flags]\n"              "                  [-N new_passphrase] [-w provider] [-x flags]\n"
             "       ssh-keygen -p [-f keyfile] [-m format] [-N new_passphrase]\n"              "       ssh-keygen -p [-f keyfile] [-m format] [-N new_passphrase]\n"
             "                   [-P old_passphrase]\n"              "                   [-P old_passphrase]\n"
Line 2979 
Line 3006 
                 case 'x':                  case 'x':
                         if (*optarg == '\0')                          if (*optarg == '\0')
                                 fatal("Missing security key flags");                                  fatal("Missing security key flags");
                         ull = strtoull(optarg, &ep, 0);                          if (strcasecmp(optarg, "no-touch-required") == 0)
                         if (*ep != '\0')                                  sk_flags &= ~SSH_SK_USER_PRESENCE_REQD;
                                 fatal("Security key flags \"%s\" is not a "                          else {
                                     "number", optarg);                                  ull = strtoull(optarg, &ep, 0);
                         if (ull > 0xff)                                  if (*ep != '\0')
                                 fatal("Invalid security key flags 0x%llx", ull);                                          fatal("Security key flags \"%s\" is "
                         sk_flags = (uint8_t)ull;                                              "not a number", optarg);
                                   if (ull > 0xff) {
                                           fatal("Invalid security key "
                                               "flags 0x%llx", ull);
                                   }
                                   sk_flags = (uint8_t)ull;
                           }
                         break;                          break;
                 case 'z':                  case 'z':
                         errno = 0;                          errno = 0;
Line 3251 
Line 3284 
         switch (type) {          switch (type) {
         case KEY_ECDSA_SK:          case KEY_ECDSA_SK:
         case KEY_ED25519_SK:          case KEY_ED25519_SK:
                   if (!quiet) {
                           printf("You may need to touch your security key "
                               "to authorize key generation.\n");
                   }
                   fflush(stdout);
                 if (sshsk_enroll(type, sk_provider,                  if (sshsk_enroll(type, sk_provider,
                     cert_key_id == NULL ? "ssh:" : cert_key_id,                      cert_key_id == NULL ? "ssh:" : cert_key_id,
                     sk_flags, NULL, &private, NULL) != 0)                      sk_flags, NULL, &private, NULL) != 0)

Legend:
Removed from v.1.365  
changed lines
  Added in v.1.374