mirror of
https://github.com/cathugger/mkp224o.git
synced 2025-04-20 13:59:11 +00:00
tweak pass functionality control
This commit is contained in:
parent
db303cf8f6
commit
9ac54f6db3
1 changed files with 41 additions and 27 deletions
56
main.c
56
main.c
|
@ -695,6 +695,7 @@ static void printhelp(FILE *out,const char *progname)
|
||||||
"\t-Y [filename [host.onion]] - parse YAML encoded input and extract key(s) to filesystem\n"
|
"\t-Y [filename [host.onion]] - parse YAML encoded input and extract key(s) to filesystem\n"
|
||||||
#ifdef PASSPHRASE
|
#ifdef PASSPHRASE
|
||||||
"\t-p passphrase - use passphrase to initialize the random seed with\n"
|
"\t-p passphrase - use passphrase to initialize the random seed with\n"
|
||||||
|
"\t-P - same as -p, but takes passphrase from PASSPHRASE environment variable\n"
|
||||||
#endif
|
#endif
|
||||||
,progname,progname);
|
,progname,progname);
|
||||||
fflush(out);
|
fflush(out);
|
||||||
|
@ -742,6 +743,22 @@ static void setworkdir(const char *wd)
|
||||||
fprintf(stderr,"set workdir: %s\n",workdir);
|
fprintf(stderr,"set workdir: %s\n",workdir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef PASSPHRASE
|
||||||
|
static void setpassphrase(const char *pass)
|
||||||
|
{
|
||||||
|
static u8 salt[crypto_pwhash_SALTBYTES] = {0};
|
||||||
|
fprintf(stderr,"expanding passphrase (may take a while)...");
|
||||||
|
if (crypto_pwhash(determseed,sizeof(determseed),
|
||||||
|
pass,strlen(pass),salt,
|
||||||
|
PWHASH_OPSLIMIT,PWHASH_MEMLIMIT,PWHASH_ALG) != 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr," out of memory!\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
fprintf(stderr," done.\n");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
VEC_STRUCT(threadvec, pthread_t);
|
VEC_STRUCT(threadvec, pthread_t);
|
||||||
|
|
||||||
int main(int argc,char **argv)
|
int main(int argc,char **argv)
|
||||||
|
@ -929,34 +946,26 @@ int main(int argc,char **argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#ifdef PASSPHRASE
|
#ifdef PASSPHRASE
|
||||||
} else if (*arg == 'p') {
|
else if (*arg == 'p') {
|
||||||
if (argc--) {
|
if (argc--) {
|
||||||
const char *phrase = *argv++;
|
setpassphrase(*argv++);
|
||||||
|
|
||||||
deterministic = 1;
|
deterministic = 1;
|
||||||
static unsigned char salt[crypto_pwhash_SALTBYTES] = {0};
|
}
|
||||||
if (!strcmp(phrase,"@")) {
|
else
|
||||||
phrase = getenv("PASSPHRASE");
|
e_additional();
|
||||||
if (phrase == NULL) {
|
}
|
||||||
|
else if (*arg == 'P') {
|
||||||
|
const char *pass = getenv("PASSPHRASE");
|
||||||
|
if (!pass) {
|
||||||
fprintf(stderr,"store passphrase in PASSPHRASE environment variable\n");
|
fprintf(stderr,"store passphrase in PASSPHRASE environment variable\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
setpassphrase(pass);
|
||||||
|
deterministic = 1;
|
||||||
}
|
}
|
||||||
|
#endif // PASSPHRASE
|
||||||
fprintf(stderr,"expanding passphrase...");
|
|
||||||
if (crypto_pwhash(determseed,sizeof(determseed),
|
|
||||||
phrase,strlen(phrase),salt,
|
|
||||||
PWHASH_OPSLIMIT,PWHASH_MEMLIMIT,PWHASH_ALG) != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr," out of memory!\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
fprintf(stderr," done.\n");
|
|
||||||
} else
|
|
||||||
e_additional();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
fprintf(stderr,"unrecognised argument: -%c\n",*arg);
|
fprintf(stderr,"unrecognised argument: -%c\n",*arg);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -1052,6 +1061,11 @@ int main(int argc,char **argv)
|
||||||
fprintf(stderr,"using %d %s\n",
|
fprintf(stderr,"using %d %s\n",
|
||||||
numthreads,numthreads == 1 ? "thread" : "threads");
|
numthreads,numthreads == 1 ? "thread" : "threads");
|
||||||
|
|
||||||
|
#ifdef PASSPHRASE
|
||||||
|
if (!quietflag && deterministic && numneedgenerate != 1)
|
||||||
|
fprintf(stderr,"CAUTION: avoid using keys generated with same password for unrelated services, as single leaked key may help attacker to regenerate related keys.\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
signal(SIGTERM,termhandler);
|
signal(SIGTERM,termhandler);
|
||||||
signal(SIGINT,termhandler);
|
signal(SIGINT,termhandler);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue