Update CLI -pass option

This commit is contained in:
Zhi Guan
2026-06-26 14:23:08 +08:00
parent d804ea4e9b
commit e43f9e306d
36 changed files with 602 additions and 115 deletions

View File

@@ -19,9 +19,10 @@
#include <gmssl/x509.h>
#include <gmssl/rand.h>
#include <gmssl/error.h>
#include "passwd.h"
static const char *usage = "-lib so_path -key num -pass str [-in file] [-out file]";
static const char *usage = "-lib so_path -key num [-pass str] [-in file] [-out file]";
static const char *options =
"\n"
@@ -29,7 +30,7 @@ static const char *options =
"\n"
" -lib so_path Vendor's SDF dynamic library\n"
" -key num Decryption private key index number\n"
" -pass str Password to get the private key access right\n"
" -pass str Password to get the private key access right, prompt if not given\n"
" -in file | stdin Input data\n"
" -out file | stdout Output data\n"
"\n"
@@ -47,6 +48,7 @@ int sdfdecrypt_main(int argc, char **argv)
char *lib = NULL;
int key_index = -1;
char *pass = NULL;
char passbuf[GMSSL_PASSWORD_MAX_SIZE] = {0};
char *infile = NULL;
char *outfile = NULL;
FILE *infp = stdin;
@@ -139,8 +141,8 @@ bad:
fprintf(stderr, "gmssl %s: '-key' option required\n", prog);
goto end;
}
if (!pass) {
fprintf(stderr, "gmssl %s: '-pass' option required\n", prog);
if (gmssl_tool_get_password(prog, "Password to access SDF private key", NULL, &pass,
passbuf, sizeof(passbuf)) != 1) {
goto end;
}
@@ -220,6 +222,7 @@ end:
(void)sdf_close_device(&dev);
(void)sdf_unload_library();
gmssl_secure_clear(iv, sizeof(iv));
gmssl_secure_clear(passbuf, sizeof(passbuf));
if (infile && infp) fclose(infp);
if (outfile && outfp) fclose(outfp);
return ret;