Commit f5e0fd13 authored by Niels Möller's avatar Niels Möller

New option --server.

(main): If invoked with the quiet option (-q), never ask the user
to type randomly.

Rev: src/lsh-make-seed.c:1.7
parent ac0a0a6a
...@@ -113,11 +113,14 @@ const char *argp_program_version ...@@ -113,11 +113,14 @@ const char *argp_program_version
const char *argp_program_bug_address = BUG_ADDRESS; const char *argp_program_bug_address = BUG_ADDRESS;
#define OPT_SLOPPY 0x200 #define OPT_SLOPPY 0x200
#define OPT_SERVER 0x201
/* GABA: /* GABA:
(class (class
(name lsh_make_seed_options) (name lsh_make_seed_options)
(vars (vars
; Directory that should be created if needed
(directory string)
(filename string) (filename string)
(force . int) (force . int)
(sloppy . int))) (sloppy . int)))
...@@ -128,6 +131,7 @@ make_options(void) ...@@ -128,6 +131,7 @@ make_options(void)
{ {
NEW(lsh_make_seed_options, self); NEW(lsh_make_seed_options, self);
self->directory = NULL;
self->filename = NULL; self->filename = NULL;
self->force = 0; self->force = 0;
...@@ -139,9 +143,11 @@ main_options[] = ...@@ -139,9 +143,11 @@ main_options[] =
{ {
/* Name, key, arg-name, flags, doc, group */ /* Name, key, arg-name, flags, doc, group */
{ "output-file", 'o', "Filename", 0, "Default is ~/.lsh/seed-file", 0 }, { "output-file", 'o', "Filename", 0, "Default is ~/.lsh/seed-file", 0 },
{ "server", OPT_SERVER, NULL, 0,
"Save seed file where the lshd server expects it", 0 },
{ "force", 'f', NULL, 0, "Overwrite any existing seed file.", 0 }, { "force", 'f', NULL, 0, "Overwrite any existing seed file.", 0 },
{ "sloppy", OPT_SLOPPY, NULL, 0, "Generate seed file even if we can't " { "sloppy", OPT_SLOPPY, NULL, 0, "Generate seed file even if we can't "
collect a good amount of randomness from the environment.", 0 }, "collect a good amount of randomness from the environment.", 0 },
{ NULL, 0, NULL, 0, NULL, 0 } { NULL, 0, NULL, 0, NULL, 0 }
}; };
...@@ -170,7 +176,6 @@ main_argp_parser(int key, char *arg, struct argp_state *state) ...@@ -170,7 +176,6 @@ main_argp_parser(int key, char *arg, struct argp_state *state)
if (!self->filename) if (!self->filename)
{ {
char *home = getenv("HOME"); char *home = getenv("HOME");
struct lsh_string *s;
if (!home) if (!home)
{ {
...@@ -179,26 +184,33 @@ main_argp_parser(int key, char *arg, struct argp_state *state) ...@@ -179,26 +184,33 @@ main_argp_parser(int key, char *arg, struct argp_state *state)
} }
else else
{ {
s = ssh_format("%lz/.lsh", home); self->directory = ssh_format("%lz/.lsh", home);
if (mkdir(lsh_get_cstring(s), 0755) < 0)
{
if (errno != EEXIST)
argp_failure(state, EXIT_FAILURE, errno, "Creating directory %s failed.", s->data);
}
lsh_string_free(s);
self->filename = ssh_format("%lz/.lsh/yarrow-seed-file", home); self->filename = ssh_format("%lz/.lsh/yarrow-seed-file", home);
} }
} }
break; break;
case 'o': case 'o':
self->filename = make_string(arg); if (self->filename)
argp_error(state, "You can use at most one -o or --server option.");
else
self->filename = make_string(arg);
break; break;
case OPT_SLOPPY: case OPT_SLOPPY:
self->sloppy = 1; self->sloppy = 1;
break; break;
case OPT_SERVER:
if (self->filename)
argp_error(state, "You can use at most one -o or --server option.");
else
{
self->directory = make_string("/var/spool/lsh");
self->filename = make_string("/var/spool/lsh/yarrow-seed-file");
}
break;
case 'f': case 'f':
self->force = 1; self->force = 1;
break; break;
...@@ -1032,7 +1044,7 @@ get_system(struct yarrow256_ctx *ctx, enum source_type source) ...@@ -1032,7 +1044,7 @@ get_system(struct yarrow256_ctx *ctx, enum source_type source)
{ {
unsigned entropy = 0; unsigned entropy = 0;
if (res > linux_proc_sources[i].limit) if (res > linux_proc_sources[i].limit)
entropy = linux_proc_sources[i].entropy;; entropy = linux_proc_sources[i].entropy;
verbose("Read %i bytes from %z, entropy estimate: %i bits\n", verbose("Read %i bytes from %z, entropy estimate: %i bits\n",
res, linux_proc_sources[i].name, entropy); res, linux_proc_sources[i].name, entropy);
...@@ -1091,7 +1103,7 @@ get_time_accuracy(void) ...@@ -1091,7 +1103,7 @@ get_time_accuracy(void)
werror("gettimeofday accuracy seems too bad to be useful"); werror("gettimeofday accuracy seems too bad to be useful");
return 0; return 0;
} }
return diff; return diff;
} }
...@@ -1126,7 +1138,7 @@ get_interact(struct yarrow256_ctx *ctx, enum source_type source) ...@@ -1126,7 +1138,7 @@ get_interact(struct yarrow256_ctx *ctx, enum source_type source)
struct termios tty_mode = tty_original_mode; struct termios tty_mode = tty_original_mode;
tty_needs_reset = 1; tty_needs_reset = 1;
tty_mode.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON); tty_mode.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
tty_mode.c_cflag &= ~(CSIZE|PARENB); tty_mode.c_cflag |= CS8; tty_mode.c_cflag &= ~(CSIZE|PARENB); tty_mode.c_cflag |= CS8;
tty_mode.c_lflag &= ~(ECHO|ECHONL|ICANON|IEXTEN); tty_mode.c_lflag &= ~(ECHO|ECHONL|ICANON|IEXTEN);
...@@ -1173,22 +1185,22 @@ get_interact(struct yarrow256_ctx *ctx, enum source_type source) ...@@ -1173,22 +1185,22 @@ get_interact(struct yarrow256_ctx *ctx, enum source_type source)
/* We only look at the microsecond data, */ /* We only look at the microsecond data, */
entropy = yarrow_key_event_estimate(&estimator, entropy = yarrow_key_event_estimate(&estimator,
event.c, time); event.c, time);
debug("Got char `%c', time: %i, entropy: %i\n", event.c, time, entropy); debug("Got char `%c', time: %i, entropy: %i\n", event.c, time, entropy);
yarrow256_update(ctx, source, yarrow256_update(ctx, source,
entropy, entropy,
sizeof(event), (uint8_t *) &event); sizeof(event), (uint8_t *) &event);
count += entropy; count += entropy;
if (count >= progress) if (count >= progress)
{ {
werror_progress("."); werror_progress(".");
progress += 5; progress += 5;
} }
} }
werror_progress("\n"); werror_progress("\n");
werror("Got %i keystrokes, estimating %i bits of entropy.\n", werror("Got %i keystrokes, estimating %i bits of entropy.\n",
keys, count); keys, count);
...@@ -1199,7 +1211,7 @@ get_interact(struct yarrow256_ctx *ctx, enum source_type source) ...@@ -1199,7 +1211,7 @@ get_interact(struct yarrow256_ctx *ctx, enum source_type source)
{ {
/* Wait a moment for the user to stop typing */ /* Wait a moment for the user to stop typing */
sleep(1); sleep(1);
/* Reset terminal mode, and disgard buffered input. */ /* Reset terminal mode, and disgard buffered input. */
tcsetattr(STDIN_FILENO, TCSAFLUSH, &tty_original_mode); tcsetattr(STDIN_FILENO, TCSAFLUSH, &tty_original_mode);
tty_needs_reset = 0; tty_needs_reset = 0;
...@@ -1227,7 +1239,16 @@ main(int argc, char **argv) ...@@ -1227,7 +1239,16 @@ main(int argc, char **argv)
werror("atexit failed!?\n"); werror("atexit failed!?\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (options->directory
&& (mkdir(lsh_get_cstring(options->directory), 0755) < 0)
&& (errno != EEXIST) )
{
werror("Creating `%S' failed (errno = %i): %z.\n",
options->directory, errno, STRERROR(errno));
return EXIT_FAILURE;
}
lock_info = make_lsh_file_lock_info(ssh_format("%lS.lock", lock_info = make_lsh_file_lock_info(ssh_format("%lS.lock",
options->filename)); options->filename));
...@@ -1264,7 +1285,8 @@ main(int argc, char **argv) ...@@ -1264,7 +1285,8 @@ main(int argc, char **argv)
return EXIT_FAILURE; return EXIT_FAILURE;
} }
get_interact(&yarrow, SOURCE_USER); if (!quiet_flag)
get_interact(&yarrow, SOURCE_USER);
} }
if (!options->sloppy && !yarrow256_is_seeded(&yarrow)) if (!options->sloppy && !yarrow256_is_seeded(&yarrow))
...@@ -1276,7 +1298,7 @@ main(int argc, char **argv) ...@@ -1276,7 +1298,7 @@ main(int argc, char **argv)
yarrow256_force_reseed(&yarrow); yarrow256_force_reseed(&yarrow);
lock = LSH_FILE_LOCK(lock_info); lock = LSH_FILE_LOCK(lock_info, 5);
if (!lock) if (!lock)
{ {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment