Christian Pfaffel-Janser
2007-Mar-01 13:19 UTC
Proposed patch: ssh-keygen allows writing to stdout for moduli generation
Hello all,
I propose the following patch to ssh-keygen.c for openssh version 4.5.
It allows to redirect output of the moduli operations to stdout, to do
something like e.g.:
$ ssh-keygen -G - -b 2048 | ssh-keygen -T - -f - >moduli
Best regards,
Christian
--- ssh/ssh-keygen.c.old 2007-03-01 12:43:06.000000000 +0100
+++ ssh/ssh-keygen.c 2007-03-01 12:47:32.000000000 +0100
@@ -1270,13 +1270,16 @@ main(int ac, char **av)
}
if (do_gen_candidates) {
- FILE *out = fopen(out_file, "w");
-
- if (out == NULL) {
- error("Couldn't open modulus candidate file \"%s\":
%s",
- out_file, strerror(errno));
- return (1);
- }
+ FILE *out;
+
+ if (strcmp(out_file, "-") != 0) {
+ if ((out = fopen(out_file, "w")) == NULL) {
+ fatal("Couldn't open modulus candidate file \"%s\":
%s",
+ out_file, strerror(errno));
+ }
+ } else
+ out = stdout;
+
if (bits == 0)
bits = DEFAULT_BITS;
if (gen_candidates(out, memory, bits, start) != 0)
@@ -1287,8 +1290,16 @@ main(int ac, char **av)
if (do_screen_candidates) {
FILE *in;
- FILE *out = fopen(out_file, "w");
+ FILE *out;
+ if (strcmp(out_file, "-") != 0) {
+ if ((out = fopen(out_file, "w")) == NULL) {
+ fatal("Couldn't open moduli file \"%s\": %s",
+ out_file, strerror(errno));
+ }
+ } else
+ out = stdout;
+
if (have_identity && strcmp(identity_file, "-") != 0) {
if ((in = fopen(identity_file, "r")) == NULL) {
fatal("Couldn't open modulus candidate "
@@ -1298,10 +1309,6 @@ main(int ac, char **av)
} else
in = stdin;
- if (out == NULL) {
- fatal("Couldn't open moduli file \"%s\": %s",
- out_file, strerror(errno));
- }
if (prime_test(in, out, trials, generator_wanted) != 0)
fatal("modulus screening failed");
return (0);
Darren Tucker
2007-Mar-01 23:09 UTC
Proposed patch: ssh-keygen allows writing to stdout for moduli generation
Christian Pfaffel-Janser wrote:> I propose the following patch to ssh-keygen.c for openssh version 4.5. > It allows to redirect output of the moduli operations to stdout, to do > something like e.g.: > > $ ssh-keygen -G - -b 2048 | ssh-keygen -T - -f - >moduliIf your platform has it you can use /dev/stdout for this: ssh-keygen -b 2048 -G /dev/stdout | ssh-keygen -T - -f - >moduli -- Darren Tucker (dtucker at zip.com.au) GPG key 8FF4FA69 / D9A3 86E9 7EEE AF4B B2D4 37C9 C982 80C7 8FF4 FA69 Good judgement comes with experience. Unfortunately, the experience usually comes from bad judgement.