mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-08-07 12:33:39 +08:00
Update CLI -pass option
This commit is contained in:
@@ -14,14 +14,15 @@
|
||||
#include <stdlib.h>
|
||||
#include <gmssl/mem.h>
|
||||
#include <gmssl/sm2.h>
|
||||
#include "passwd.h"
|
||||
|
||||
|
||||
static const char *usage = "-pass str [-out pem] [-pubout pem]\n";
|
||||
static const char *usage = "[-pass str] [-out pem] [-pubout pem]\n";
|
||||
|
||||
static const char *options =
|
||||
"Options\n"
|
||||
"\n"
|
||||
" -pass pass Password to encrypt the private key\n"
|
||||
" -pass pass Password to encrypt the private key, prompt if not given\n"
|
||||
" -out pem Output password-encrypted PKCS #8 private key in PEM format\n"
|
||||
" -pubout pem Output public key in PEM format\n"
|
||||
"\n"
|
||||
@@ -36,6 +37,7 @@ int sm2keygen_main(int argc, char **argv)
|
||||
int ret = 1;
|
||||
char *prog = argv[0];
|
||||
char *pass = NULL;
|
||||
char passbuf[GMSSL_PASSWORD_MAX_SIZE] = {0};
|
||||
char *outfile = NULL;
|
||||
char *puboutfile = NULL;
|
||||
FILE *outfp = stdout;
|
||||
@@ -85,8 +87,8 @@ bad:
|
||||
argv++;
|
||||
}
|
||||
|
||||
if (!pass) {
|
||||
fprintf(stderr, "gmssl %s: `-pass` option required\n", prog);
|
||||
if (gmssl_tool_get_password(prog, "Password to encrypt private key", outfile, &pass,
|
||||
passbuf, sizeof(passbuf)) != 1) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
@@ -100,6 +102,7 @@ bad:
|
||||
|
||||
end:
|
||||
gmssl_secure_clear(&key, sizeof(key));
|
||||
gmssl_secure_clear(passbuf, sizeof(passbuf));
|
||||
if (outfile && outfp) fclose(outfp);
|
||||
if (puboutfile && puboutfp) fclose(puboutfp);
|
||||
return ret;
|
||||
|
||||
Reference in New Issue
Block a user