Skip to content

Commit

Permalink
near passkeys skip/warn modes & help tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
cathugger committed Sep 5, 2023
1 parent 42e4d3a commit 80e1bd0
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 34 deletions.
73 changes: 44 additions & 29 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,43 +96,49 @@ static void printhelp(FILE *out,const char *progname)
" %s -f FILTERFILE [OPTION]\n"
"Options:\n"
" -f FILTERFILE specify filter file which contains filters separated\n"
" by newlines\n"
" -D deduplicate filters\n"
" -q do not print diagnostic output to stderr\n"
" -x do not print onion names\n"
" -v print more diagnostic data\n"
" -o FILENAME output onion names to specified file (append)\n"
" -O FILENAME output onion names to specified file (overwrite)\n"
" -F include directory names in onion names output\n"
" -d DIRNAME output directory\n"
" by newlines.\n"
" -D deduplicate filters.\n"
" -q do not print diagnostic output to stderr.\n"
" -x do not print onion names.\n"
" -v print more diagnostic data.\n"
" -o FILENAME output onion names to specified file (append).\n"
" -O FILENAME output onion names to specified file (overwrite).\n"
" -F include directory names in onion names output.\n"
" -d DIRNAME output directory.\n"
" -t NUMTHREADS specify number of threads to utilise\n"
" (default - try detecting CPU core count)\n"
" -j NUMTHREADS same as -t\n"
" -n NUMKEYS specify number of keys (default - 0 - unlimited)\n"
" -N NUMWORDS specify number of words per key (default - 1)\n"
" -Z deprecated, does nothing\n"
" -z deprecated, does nothing\n"
" -B use batching key generation method (current default)\n"
" -s print statistics each 10 seconds\n"
" -S SECONDS print statistics every specified amount of seconds\n"
" -T do not reset statistics counters when printing\n"
" (default - try detecting CPU core count).\n"
" -j NUMTHREADS same as -t.\n"
" -n NUMKEYS specify number of keys (default - 0 - unlimited).\n"
" -N NUMWORDS specify number of words per key (default - 1).\n"
" -Z deprecated, does nothing.\n"
" -z deprecated, does nothing.\n"
" -B use batching key generation method (current default).\n"
" -s print statistics each 10 seconds.\n"
" -S SECONDS print statistics every specified amount of seconds.\n"
" -T do not reset statistics counters when printing.\n"
" -y output generated keys in YAML format instead of\n"
" dumping them to filesystem\n"
" dumping them to filesystem.\n"
" -Y [FILENAME [host.onion]]\n"
" parse YAML encoded input and extract key(s) to\n"
" filesystem\n"
" filesystem.\n"
#ifdef PASSPHRASE
" -p PASSPHRASE use passphrase to initialize the random seed with\n"
" -p PASSPHRASE use passphrase to initialize the random seed with.\n"
" -P same as -p, but takes passphrase from PASSPHRASE\n"
" environment variable\n"
" environment variable.\n"
" --checkpoint filename\n"
" load/save checkpoint of progress to specified file\n"
" (requires passphrase)\n"
" (requires passphrase).\n"
" --skipnear skip near passphrase keys; you probably want this\n"
" because of improved safety unless you're trying to\n"
" regenerate an old key; possible future default.\n"
" --warnnear print warning about passphrase key being near another\n"
" (safety hazard); prefer --skipnear to this unless\n"
" you're regenerating an old key.\n"
#endif
" --rawyaml raw (unprefixed) public/secret keys for -y/-Y\n"
" (may be useful for tor controller API)\n"
" -h, --help, --usage print help to stdout and quit\n"
" -V, --version print version information to stdout and exit\n"
" (may be useful for tor controller API).\n"
" -h, --help, --usage print help to stdout and quit.\n"
" -V, --version print version information to stdout and exit.\n"
,progname,progname);
fflush(out);
}
Expand Down Expand Up @@ -332,6 +338,10 @@ int main(int argc,char **argv)
else
e_additional();
}
else if (!strcmp(arg,"skipnear"))
pw_skipnear = 1;
else if (!strcmp(arg,"warnnear"))
pw_warnnear = 1;
#endif // PASSPHRASE
else {
fprintf(stderr,"unrecognised argument: --%s\n",arg);
Expand Down Expand Up @@ -597,8 +607,13 @@ int main(int argc,char **argv)

#ifdef PASSPHRASE
if (deterministic) {
if (!quietflag && 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");
if (!quietflag && numneedgenerate != 1 && !pw_skipnear && !pw_warnnear)
fprintf(stderr,
// 0 1 2 3 4 5 6 7
// 01234567890123456789012345678901234567890123456789012345678901234567890123456789
"CAUTION: avoid using keys generated with the same password for unrelated\n"
" services, as single leaked key may help an attacker to regenerate\n"
" related keys; to silence this warning, pass --skipnear or --warnnear.\n");
if (checkpointfile) {
memcpy(orig_determseed,determseed,sizeof(determseed));
// Read current checkpoint position if file exists
Expand Down
11 changes: 10 additions & 1 deletion worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ size_t workdirlen = 0;

pthread_mutex_t determseed_mutex;
u8 determseed[SEED_LEN];
int pw_skipnear = 0;
int pw_warnnear = 0;
#endif


Expand All @@ -71,7 +73,7 @@ char *makesname(void)
return sname;
}

static void onionready(char *sname,const u8 *secret,const u8 *pubonion)
static void onionready(char *sname,const u8 *secret,const u8 *pubonion,int warnnear)
{
if (endwork)
return;
Expand Down Expand Up @@ -122,6 +124,13 @@ static void onionready(char *sname,const u8 *secret,const u8 *pubonion)
}
if (fout) {
pthread_mutex_lock(&fout_mutex);
#ifdef PASSPHRASE
const char * const pwarn = " warn:near\n";
if (warnnear)
strcpy(&sname[onionendpos],pwarn);
const size_t oprintlen = printlen;
const size_t printlen = oprintlen + (warnnear ? strlen(pwarn)-1 : 0);
#endif
fwrite(&sname[printstartpos],printlen,1,fout);
fflush(fout);
pthread_mutex_unlock(&fout_mutex);
Expand Down
2 changes: 2 additions & 0 deletions worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ VEC_STRUCT(statsvec,struct statstruct);
#ifdef PASSPHRASE
extern pthread_mutex_t determseed_mutex;
extern u8 determseed[SEED_LEN];
extern int pw_skipnear;
extern int pw_warnnear;
#endif

extern void worker_init(void);
Expand Down
2 changes: 1 addition & 1 deletion worker_batch.inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void *CRYPTO_NAMESPACE(worker_batch)(void *task)
pk[PUBLIC_LEN + 2] = 0x03;
// full name
strcpy(base32_to(&sname[direndpos],pk,PUBONION_LEN),".onion");
onionready(sname,secret,pubonion.raw);
onionready(sname,secret,pubonion.raw,0);
pk[PUBLIC_LEN] = 0; // what is this for?
// don't reuse same seed
goto initseed;
Expand Down
18 changes: 15 additions & 3 deletions worker_batch_pass.inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,21 @@ void *CRYPTO_NAMESPACE(worker_batch_pass)(void *task)

sname = makesname();

int seednear;

initseed:

#ifdef STATISTICS
++st->numrestart.v;
#endif

seednear = 0;

pthread_mutex_lock(&determseed_mutex);
for (int i = 0; i < SEED_LEN; i++)
if (++determseed[i])
break;
memcpy(seed, determseed, SEED_LEN);
memcpy(seed,determseed,SEED_LEN);
pthread_mutex_unlock(&determseed_mutex);

ed25519_seckey_expand(sk,seed);
Expand Down Expand Up @@ -112,8 +116,12 @@ void *CRYPTO_NAMESPACE(worker_batch_pass)(void *task)
pk[PUBLIC_LEN + 2] = 0x03;
// full name
strcpy(base32_to(&sname[direndpos],pk,PUBONION_LEN),".onion");
onionready(sname,secret,pubonion.raw);
onionready(sname,secret,pubonion.raw,seednear && pw_warnnear);
pk[PUBLIC_LEN] = 0; // what is this for?

if (pw_skipnear)
goto initseed;
seednear = 1;
});
next:
;
Expand Down Expand Up @@ -180,8 +188,12 @@ void *CRYPTO_NAMESPACE(worker_batch_pass)(void *task)
pk[PUBLIC_LEN + 2] = 0x03;
// full name
strcpy(base32_to(&sname[direndpos],pk,PUBONION_LEN),".onion");
onionready(sname,secret,pubonion.raw);
onionready(sname,secret,pubonion.raw,seednear && pw_warnnear);
pk[PUBLIC_LEN] = 0; // what is this for?

if (pw_skipnear)
goto initseed;
seednear = 1;
});
next2:
;
Expand Down

0 comments on commit 80e1bd0

Please sign in to comment.