[BACK]Return to pkey.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / openssl

Diff for /src/usr.bin/openssl/pkey.c between version 1.18 and 1.19

version 1.18, 2022/11/11 17:07:39 version 1.19, 2023/03/06 14:32:06
Line 80 
Line 80 
         int pubout;          int pubout;
         int pubtext;          int pubtext;
         int text;          int text;
 } pkey_config;  } cfg;
   
 static int  static int
 pkey_opt_cipher(int argc, char **argv, int *argsused)  pkey_opt_cipher(int argc, char **argv, int *argsused)
Line 90 
Line 90 
         if (*name++ != '-')          if (*name++ != '-')
                 return (1);                  return (1);
   
         if ((pkey_config.cipher = EVP_get_cipherbyname(name)) == NULL) {          if ((cfg.cipher = EVP_get_cipherbyname(name)) == NULL) {
                 BIO_printf(bio_err, "Unknown cipher %s\n", name);                  BIO_printf(bio_err, "Unknown cipher %s\n", name);
                 return (1);                  return (1);
         }          }
Line 104 
Line 104 
                 .name = "check",                  .name = "check",
                 .desc = "Check validity of key",                  .desc = "Check validity of key",
                 .type = OPTION_FLAG,                  .type = OPTION_FLAG,
                 .opt.flag = &pkey_config.check,                  .opt.flag = &cfg.check,
         },          },
         {          {
                 .name = "in",                  .name = "in",
                 .argname = "file",                  .argname = "file",
                 .desc = "Input file (default stdin)",                  .desc = "Input file (default stdin)",
                 .type = OPTION_ARG,                  .type = OPTION_ARG,
                 .opt.arg = &pkey_config.infile,                  .opt.arg = &cfg.infile,
         },          },
         {          {
                 .name = "inform",                  .name = "inform",
                 .argname = "format",                  .argname = "format",
                 .desc = "Input format (DER or PEM (default))",                  .desc = "Input format (DER or PEM (default))",
                 .type = OPTION_ARG_FORMAT,                  .type = OPTION_ARG_FORMAT,
                 .opt.value = &pkey_config.informat,                  .opt.value = &cfg.informat,
         },          },
         {          {
                 .name = "noout",                  .name = "noout",
                 .desc = "Do not print encoded version of the key",                  .desc = "Do not print encoded version of the key",
                 .type = OPTION_FLAG,                  .type = OPTION_FLAG,
                 .opt.flag = &pkey_config.noout,                  .opt.flag = &cfg.noout,
         },          },
         {          {
                 .name = "out",                  .name = "out",
                 .argname = "file",                  .argname = "file",
                 .desc = "Output file (default stdout)",                  .desc = "Output file (default stdout)",
                 .type = OPTION_ARG,                  .type = OPTION_ARG,
                 .opt.arg = &pkey_config.outfile,                  .opt.arg = &cfg.outfile,
         },          },
         {          {
                 .name = "outform",                  .name = "outform",
                 .argname = "format",                  .argname = "format",
                 .desc = "Output format (DER or PEM (default))",                  .desc = "Output format (DER or PEM (default))",
                 .type = OPTION_ARG_FORMAT,                  .type = OPTION_ARG_FORMAT,
                 .opt.value = &pkey_config.outformat,                  .opt.value = &cfg.outformat,
         },          },
         {          {
                 .name = "passin",                  .name = "passin",
                 .argname = "src",                  .argname = "src",
                 .desc = "Input file passphrase source",                  .desc = "Input file passphrase source",
                 .type = OPTION_ARG,                  .type = OPTION_ARG,
                 .opt.arg = &pkey_config.passargin,                  .opt.arg = &cfg.passargin,
         },          },
         {          {
                 .name = "passout",                  .name = "passout",
                 .argname = "src",                  .argname = "src",
                 .desc = "Output file passphrase source",                  .desc = "Output file passphrase source",
                 .type = OPTION_ARG,                  .type = OPTION_ARG,
                 .opt.arg = &pkey_config.passargout,                  .opt.arg = &cfg.passargout,
         },          },
         {          {
                 .name = "pubcheck",                  .name = "pubcheck",
                 .desc = "Check validity of public key",                  .desc = "Check validity of public key",
                 .type = OPTION_FLAG,                  .type = OPTION_FLAG,
                 .opt.flag = &pkey_config.pubcheck,                  .opt.flag = &cfg.pubcheck,
         },          },
         {          {
                 .name = "pubin",                  .name = "pubin",
                 .desc = "Expect a public key (default private key)",                  .desc = "Expect a public key (default private key)",
                 .type = OPTION_VALUE,                  .type = OPTION_VALUE,
                 .value = 1,                  .value = 1,
                 .opt.value = &pkey_config.pubin,                  .opt.value = &cfg.pubin,
         },          },
         {          {
                 .name = "pubout",                  .name = "pubout",
                 .desc = "Output a public key (default private key)",                  .desc = "Output a public key (default private key)",
                 .type = OPTION_VALUE,                  .type = OPTION_VALUE,
                 .value = 1,                  .value = 1,
                 .opt.value = &pkey_config.pubout,                  .opt.value = &cfg.pubout,
         },          },
         {          {
                 .name = "text",                  .name = "text",
                 .desc = "Print the public/private key in plain text",                  .desc = "Print the public/private key in plain text",
                 .type = OPTION_FLAG,                  .type = OPTION_FLAG,
                 .opt.flag = &pkey_config.text,                  .opt.flag = &cfg.text,
         },          },
         {          {
                 .name = "text_pub",                  .name = "text_pub",
                 .desc = "Print out only public key in plain text",                  .desc = "Print out only public key in plain text",
                 .type = OPTION_FLAG,                  .type = OPTION_FLAG,
                 .opt.flag = &pkey_config.pubtext,                  .opt.flag = &cfg.pubtext,
         },          },
         {          {
                 .name = NULL,                  .name = NULL,
Line 226 
Line 226 
                 exit(1);                  exit(1);
         }          }
   
         memset(&pkey_config, 0, sizeof(pkey_config));          memset(&cfg, 0, sizeof(cfg));
         pkey_config.informat = FORMAT_PEM;          cfg.informat = FORMAT_PEM;
         pkey_config.outformat = FORMAT_PEM;          cfg.outformat = FORMAT_PEM;
   
         if (options_parse(argc, argv, pkey_options, NULL, NULL) != 0) {          if (options_parse(argc, argv, pkey_options, NULL, NULL) != 0) {
                 pkey_usage();                  pkey_usage();
                 goto end;                  goto end;
         }          }
   
         if (pkey_config.pubtext)          if (cfg.pubtext)
                 pkey_config.text = 1;                  cfg.text = 1;
         if (pkey_config.pubin)          if (cfg.pubin)
                 pkey_config.pubout = pkey_config.pubtext = 1;                  cfg.pubout = cfg.pubtext = 1;
   
         if (!app_passwd(bio_err, pkey_config.passargin, pkey_config.passargout,          if (!app_passwd(bio_err, cfg.passargin, cfg.passargout,
             &passin, &passout)) {              &passin, &passout)) {
                 BIO_printf(bio_err, "Error getting passwords\n");                  BIO_printf(bio_err, "Error getting passwords\n");
                 goto end;                  goto end;
         }          }
         if (pkey_config.outfile) {          if (cfg.outfile) {
                 if (!(out = BIO_new_file(pkey_config.outfile, "wb"))) {                  if (!(out = BIO_new_file(cfg.outfile, "wb"))) {
                         BIO_printf(bio_err,                          BIO_printf(bio_err,
                             "Can't open output file %s\n", pkey_config.outfile);                              "Can't open output file %s\n", cfg.outfile);
                         goto end;                          goto end;
                 }                  }
         } else {          } else {
                 out = BIO_new_fp(stdout, BIO_NOCLOSE);                  out = BIO_new_fp(stdout, BIO_NOCLOSE);
         }          }
   
         if (pkey_config.pubin)          if (cfg.pubin)
                 pkey = load_pubkey(bio_err, pkey_config.infile,                  pkey = load_pubkey(bio_err, cfg.infile,
                     pkey_config.informat, 1, passin, "Public Key");                      cfg.informat, 1, passin, "Public Key");
         else          else
                 pkey = load_key(bio_err, pkey_config.infile,                  pkey = load_key(bio_err, cfg.infile,
                     pkey_config.informat, 1, passin, "key");                      cfg.informat, 1, passin, "key");
         if (!pkey)          if (!pkey)
                 goto end;                  goto end;
   
         if (pkey_config.check) {          if (cfg.check) {
                 if (!pkey_check(out, pkey, EVP_PKEY_check, "Key pair"))                  if (!pkey_check(out, pkey, EVP_PKEY_check, "Key pair"))
                         goto end;                          goto end;
         } else if (pkey_config.pubcheck) {          } else if (cfg.pubcheck) {
                 if (!pkey_check(out, pkey, EVP_PKEY_public_check, "Public key"))                  if (!pkey_check(out, pkey, EVP_PKEY_public_check, "Public key"))
                         goto end;                          goto end;
         }          }
   
         if (!pkey_config.noout) {          if (!cfg.noout) {
                 if (pkey_config.outformat == FORMAT_PEM) {                  if (cfg.outformat == FORMAT_PEM) {
                         if (pkey_config.pubout)                          if (cfg.pubout)
                                 PEM_write_bio_PUBKEY(out, pkey);                                  PEM_write_bio_PUBKEY(out, pkey);
                         else                          else
                                 PEM_write_bio_PrivateKey(out, pkey,                                  PEM_write_bio_PrivateKey(out, pkey,
                                     pkey_config.cipher, NULL, 0, NULL, passout);                                      cfg.cipher, NULL, 0, NULL, passout);
                 } else if (pkey_config.outformat == FORMAT_ASN1) {                  } else if (cfg.outformat == FORMAT_ASN1) {
                         if (pkey_config.pubout)                          if (cfg.pubout)
                                 i2d_PUBKEY_bio(out, pkey);                                  i2d_PUBKEY_bio(out, pkey);
                         else                          else
                                 i2d_PrivateKey_bio(out, pkey);                                  i2d_PrivateKey_bio(out, pkey);
Line 290 
Line 290 
                 }                  }
   
         }          }
         if (pkey_config.text) {          if (cfg.text) {
                 if (pkey_config.pubtext)                  if (cfg.pubtext)
                         EVP_PKEY_print_public(out, pkey, 0, NULL);                          EVP_PKEY_print_public(out, pkey, 0, NULL);
                 else                  else
                         EVP_PKEY_print_private(out, pkey, 0, NULL);                          EVP_PKEY_print_private(out, pkey, 0, NULL);

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.19