diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | Makefile.in | 11 | ||||
-rw-r--r-- | ssh-rand-helper.8 | 94 | ||||
-rw-r--r-- | ssh-rand-helper.c | 82 |
4 files changed, 178 insertions, 17 deletions
@@ -1,3 +1,9 @@ | |||
1 | 20020414 | ||
2 | - (djm) ssh-rand-helper improvements | ||
3 | - Add commandline debugging options | ||
4 | - Don't write binary data if stdout is a tty (use hex instead) | ||
5 | - Give it a manpage | ||
6 | |||
1 | 20020413 | 7 | 20020413 |
2 | - (djm) Add KrbV support patch from Simon Wilkinson <simon@sxw.org.uk> | 8 | - (djm) Add KrbV support patch from Simon Wilkinson <simon@sxw.org.uk> |
3 | 9 | ||
@@ -8234,4 +8240,4 @@ | |||
8234 | - Wrote replacements for strlcpy and mkdtemp | 8240 | - Wrote replacements for strlcpy and mkdtemp |
8235 | - Released 1.0pre1 | 8241 | - Released 1.0pre1 |
8236 | 8242 | ||
8237 | $Id: ChangeLog,v 1.2051 2002/04/13 01:04:40 djm Exp $ | 8243 | $Id: ChangeLog,v 1.2052 2002/04/14 09:27:12 djm Exp $ |
diff --git a/Makefile.in b/Makefile.in index 4e0744c3e..6a6977925 100644 --- a/Makefile.in +++ b/Makefile.in | |||
@@ -1,4 +1,4 @@ | |||
1 | # $Id: Makefile.in,v 1.202 2002/04/13 01:04:41 djm Exp $ | 1 | # $Id: Makefile.in,v 1.203 2002/04/14 09:27:13 djm Exp $ |
2 | 2 | ||
3 | prefix=@prefix@ | 3 | prefix=@prefix@ |
4 | exec_prefix=@exec_prefix@ | 4 | exec_prefix=@exec_prefix@ |
@@ -56,14 +56,15 @@ SSHOBJS= ssh.o sshconnect.o sshconnect1.o sshconnect2.o sshtty.o readconf.o clie | |||
56 | 56 | ||
57 | SSHDOBJS= sshd.o auth.o auth1.o auth2.o auth-chall.o auth2-chall.o auth-rhosts.o auth-options.o auth-krb4.o auth-krb5.o auth-pam.o auth2-pam.o auth-passwd.o auth-rsa.o auth-rh-rsa.o auth-sia.o sshpty.o sshlogin.o loginrec.o servconf.o serverloop.o md5crypt.o session.o groupaccess.o auth-skey.o auth-bsdauth.o monitor_mm.o monitor.o | 57 | SSHDOBJS= sshd.o auth.o auth1.o auth2.o auth-chall.o auth2-chall.o auth-rhosts.o auth-options.o auth-krb4.o auth-krb5.o auth-pam.o auth2-pam.o auth-passwd.o auth-rsa.o auth-rh-rsa.o auth-sia.o sshpty.o sshlogin.o loginrec.o servconf.o serverloop.o md5crypt.o session.o groupaccess.o auth-skey.o auth-bsdauth.o monitor_mm.o monitor.o |
58 | 58 | ||
59 | MANPAGES = scp.1.out ssh-add.1.out ssh-agent.1.out ssh-keygen.1.out ssh-keyscan.1.out ssh.1.out sshd.8.out sftp-server.8.out sftp.1.out | 59 | MANPAGES = scp.1.out ssh-add.1.out ssh-agent.1.out ssh-keygen.1.out ssh-keyscan.1.out ssh.1.out sshd.8.out sftp-server.8.out sftp.1.out ssh-rand-helper.8.out |
60 | MANPAGES_IN = scp.1 ssh-add.1 ssh-agent.1 ssh-keygen.1 ssh-keyscan.1 ssh.1 sshd.8 sftp-server.8 sftp.1 | 60 | MANPAGES_IN = scp.1 ssh-add.1 ssh-agent.1 ssh-keygen.1 ssh-keyscan.1 ssh.1 sshd.8 sftp-server.8 sftp.1 ssh-rand-helper.8 |
61 | MANTYPE = @MANTYPE@ | 61 | MANTYPE = @MANTYPE@ |
62 | 62 | ||
63 | CONFIGFILES=sshd_config.out ssh_config.out moduli.out | 63 | CONFIGFILES=sshd_config.out ssh_config.out moduli.out |
64 | CONFIGFILES_IN=sshd_config ssh_config moduli | 64 | CONFIGFILES_IN=sshd_config ssh_config moduli |
65 | 65 | ||
66 | PATHSUBS = \ | 66 | PATHSUBS = \ |
67 | -D/etc/ssh/ssh_prng_cmds=$(sysconfdir)/ssh_prng_cmds \ | ||
67 | -D/etc/ssh/ssh_config=$(sysconfdir)/ssh_config \ | 68 | -D/etc/ssh/ssh_config=$(sysconfdir)/ssh_config \ |
68 | -D/etc/ssh/ssh_known_hosts=$(sysconfdir)/ssh_known_hosts \ | 69 | -D/etc/ssh/ssh_known_hosts=$(sysconfdir)/ssh_known_hosts \ |
69 | -D/etc/ssh/sshd_config=$(sysconfdir)/sshd_config \ | 70 | -D/etc/ssh/sshd_config=$(sysconfdir)/sshd_config \ |
@@ -216,6 +217,9 @@ install-files: scard-install | |||
216 | $(INSTALL) -m 644 ssh-keygen.1.out $(DESTDIR)$(mandir)/$(mansubdir)1/ssh-keygen.1 | 217 | $(INSTALL) -m 644 ssh-keygen.1.out $(DESTDIR)$(mandir)/$(mansubdir)1/ssh-keygen.1 |
217 | $(INSTALL) -m 644 ssh-keyscan.1.out $(DESTDIR)$(mandir)/$(mansubdir)1/ssh-keyscan.1 | 218 | $(INSTALL) -m 644 ssh-keyscan.1.out $(DESTDIR)$(mandir)/$(mansubdir)1/ssh-keyscan.1 |
218 | $(INSTALL) -m 644 sshd.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/sshd.8 | 219 | $(INSTALL) -m 644 sshd.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/sshd.8 |
220 | if [ ! -z "$(INSTALL_SSH_PRNG_CMDS)" ]; then \ | ||
221 | $(INSTALL) -m 644 ssh-rand-helper.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/ssh-rand-helper.8 | ||
222 | fi | ||
219 | @NO_SFTP@$(INSTALL) -m 644 sftp.1.out $(DESTDIR)$(mandir)/$(mansubdir)1/sftp.1 | 223 | @NO_SFTP@$(INSTALL) -m 644 sftp.1.out $(DESTDIR)$(mandir)/$(mansubdir)1/sftp.1 |
220 | @NO_SFTP@$(INSTALL) -m 644 sftp-server.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/sftp-server.8 | 224 | @NO_SFTP@$(INSTALL) -m 644 sftp-server.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/sftp-server.8 |
221 | -rm -f $(DESTDIR)$(bindir)/slogin | 225 | -rm -f $(DESTDIR)$(bindir)/slogin |
@@ -309,5 +313,6 @@ uninstall: | |||
309 | -rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/sftp.1 | 313 | -rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/sftp.1 |
310 | -rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/ssh-keyscan.1 | 314 | -rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/ssh-keyscan.1 |
311 | -rm -f $(DESTDIR)$(mandir)/$(mansubdir)8/sshd.8 | 315 | -rm -f $(DESTDIR)$(mandir)/$(mansubdir)8/sshd.8 |
316 | -rm -f $(DESTDIR)$(mandir)/$(mansubdir)8/ssh-rand-helper.8 | ||
312 | -rm -f $(DESTDIR)$(mandir)/$(mansubdir)8/sftp-server.8 | 317 | -rm -f $(DESTDIR)$(mandir)/$(mansubdir)8/sftp-server.8 |
313 | -rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/slogin.1 | 318 | -rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/slogin.1 |
diff --git a/ssh-rand-helper.8 b/ssh-rand-helper.8 new file mode 100644 index 000000000..a89185c0a --- /dev/null +++ b/ssh-rand-helper.8 | |||
@@ -0,0 +1,94 @@ | |||
1 | .\" $Id: ssh-rand-helper.8,v 1.1 2002/04/14 09:27:13 djm Exp $ | ||
2 | .\" | ||
3 | .\" Copyright (c) 2002 Damien Miller. All rights reserved. | ||
4 | .\" | ||
5 | .\" Redistribution and use in source and binary forms, with or without | ||
6 | .\" modification, are permitted provided that the following conditions | ||
7 | .\" are met: | ||
8 | .\" 1. Redistributions of source code must retain the above copyright | ||
9 | .\" notice, this list of conditions and the following disclaimer. | ||
10 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
11 | .\" notice, this list of conditions and the following disclaimer in the | ||
12 | .\" documentation and/or other materials provided with the distribution. | ||
13 | .\" | ||
14 | .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
15 | .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
16 | .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
17 | .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
18 | .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
19 | .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
20 | .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
21 | .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
22 | .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
23 | .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
24 | .\" | ||
25 | .Dd April 14, 2002 | ||
26 | .Dt SSH-RAND-HELPER 8 | ||
27 | .Os | ||
28 | .Sh NAME | ||
29 | .Nm ssh-rand-helper | ||
30 | .Nd Random number gatherer for OpenSSH | ||
31 | .Sh SYNOPSIS | ||
32 | .Nm ssh-rand-hlper | ||
33 | .Op Fl vxXh | ||
34 | .Op Fl b Ar bytes | ||
35 | .Sh DESCRIPTION | ||
36 | .Nm | ||
37 | is a small helper program used by | ||
38 | .Xr ssh 1 , | ||
39 | .Xr ssh-add 1 , | ||
40 | .Xr ssh-agent 1 , | ||
41 | .Xr ssh-keygen 1 , | ||
42 | .Xr ssh-keyscan 1 | ||
43 | and | ||
44 | .Xr sshd 8 | ||
45 | to gather random numbers of cryptographic quality if the | ||
46 | .Xr openssl 4 | ||
47 | library has not been configured to provide them itself. | ||
48 | .Pp | ||
49 | Normally | ||
50 | .Nm | ||
51 | will generate a strong random seed and provide it to the calling | ||
52 | program via standard output. If standard output is a tty, | ||
53 | .Nm | ||
54 | will instead print the seed in hexidecimal format unless told otherwise. | ||
55 | .Pp | ||
56 | .Nm | ||
57 | will by default gather random numbers from the system commands listed | ||
58 | in | ||
59 | .Pa /etc/ssh/ssh_prng_cmds . | ||
60 | The output of each of the commands listed will be hashed and used to | ||
61 | generate a random seed for the calling program. | ||
62 | .Nm | ||
63 | will also store seed files in | ||
64 | .Pa ~/.ssh/prng_seed | ||
65 | between executions. | ||
66 | .Pp | ||
67 | Alternately, | ||
68 | .Nm | ||
69 | may be configured at build time to collect random numbers from a | ||
70 | EGD/PRNGd server via a unix domain or localhost tcp socket. | ||
71 | .Pp | ||
72 | This program is not intended to be run by the end-user, so the few | ||
73 | commandline options are for debugging purposes only. | ||
74 | .Bl -tag -width Ds | ||
75 | .It Fl b Ar bytes | ||
76 | Specify the number of random bytes to include in the output. | ||
77 | .It Fl x | ||
78 | Output a hexidecimal instead of a binary seed. | ||
79 | .It Fl X | ||
80 | Force output of a binary seed, even if standard output is a tty | ||
81 | .It Fl v | ||
82 | Turn on debugging message. Multiple | ||
83 | .Fl v | ||
84 | options will increase the debugging level. | ||
85 | .Fl h | ||
86 | Display a summary of options. | ||
87 | .El | ||
88 | .Sh AUTHORS | ||
89 | Damien Miller <djm@mindrot.org> | ||
90 | .Sh SEE ALSO | ||
91 | .Xr ssh 1 , | ||
92 | .Xr ssh-add 1 , | ||
93 | .Xr ssh-keygen 1 , | ||
94 | .Xr sshd 8 | ||
diff --git a/ssh-rand-helper.c b/ssh-rand-helper.c index 07856e5c3..8f2283ead 100644 --- a/ssh-rand-helper.c +++ b/ssh-rand-helper.c | |||
@@ -39,7 +39,7 @@ | |||
39 | #include "pathnames.h" | 39 | #include "pathnames.h" |
40 | #include "log.h" | 40 | #include "log.h" |
41 | 41 | ||
42 | RCSID("$Id: ssh-rand-helper.c,v 1.5 2002/02/10 07:32:30 djm Exp $"); | 42 | RCSID("$Id: ssh-rand-helper.c,v 1.6 2002/04/14 09:27:13 djm Exp $"); |
43 | 43 | ||
44 | /* Number of bytes we write out */ | 44 | /* Number of bytes we write out */ |
45 | #define OUTPUT_SEED_SIZE 48 | 45 | #define OUTPUT_SEED_SIZE 48 |
@@ -747,38 +747,88 @@ prng_read_commands(char *cmdfilename) | |||
747 | return cur_cmd < MIN_ENTROPY_SOURCES ? -1 : 0; | 747 | return cur_cmd < MIN_ENTROPY_SOURCES ? -1 : 0; |
748 | } | 748 | } |
749 | 749 | ||
750 | void | ||
751 | usage(void) | ||
752 | { | ||
753 | fprintf(stderr, "Usage: %s [options]\n", __progname); | ||
754 | fprintf(stderr, " -v Verbose; display verbose debugging messages.\n"); | ||
755 | fprintf(stderr, " Multiple -v increases verbosity.\n"); | ||
756 | fprintf(stderr, " -x Force output in hexidecimal (for debugging)\n"); | ||
757 | fprintf(stderr, " -X Force output in binary\n"); | ||
758 | fprintf(stderr, " -b bytes Number of bytes to output (default %d)\n", | ||
759 | OUTPUT_SEED_SIZE); | ||
760 | } | ||
761 | |||
750 | int | 762 | int |
751 | main(int argc, char **argv) | 763 | main(int argc, char **argv) |
752 | { | 764 | { |
753 | unsigned char buf[OUTPUT_SEED_SIZE]; | 765 | unsigned char *buf; |
754 | int ret; | 766 | int ret, ch, debug_level, output_hex, bytes; |
767 | extern char *optarg; | ||
768 | LogLevel ll; | ||
755 | 769 | ||
756 | __progname = get_progname(argv[0]); | 770 | __progname = get_progname(argv[0]); |
757 | /* XXX: need some debugging mode */ | ||
758 | log_init(argv[0], SYSLOG_LEVEL_INFO, SYSLOG_FACILITY_USER, 1); | 771 | log_init(argv[0], SYSLOG_LEVEL_INFO, SYSLOG_FACILITY_USER, 1); |
759 | 772 | ||
773 | ll = SYSLOG_LEVEL_INFO; | ||
774 | debug_level = output_hex = 0; | ||
775 | bytes = OUTPUT_SEED_SIZE; | ||
776 | |||
777 | /* Don't write binary data to a tty, unless we are forced to */ | ||
778 | if (isatty(STDOUT_FILENO)) | ||
779 | output_hex = 1; | ||
780 | |||
781 | while ((ch = getopt(argc, argv, "vxXhb:")) != -1) { | ||
782 | switch (ch) { | ||
783 | case 'v': | ||
784 | if (debug_level < 3) | ||
785 | ll = SYSLOG_LEVEL_DEBUG1 + debug_level++; | ||
786 | break; | ||
787 | case 'x': | ||
788 | output_hex = 1; | ||
789 | break; | ||
790 | case 'X': | ||
791 | output_hex = 0; | ||
792 | break; | ||
793 | case 'b': | ||
794 | if ((bytes = atoi(optarg)) <= 0) | ||
795 | fatal("Invalid number of output bytes"); | ||
796 | break; | ||
797 | case 'h': | ||
798 | usage(); | ||
799 | exit(0); | ||
800 | default: | ||
801 | error("Invalid commandline option"); | ||
802 | usage(); | ||
803 | } | ||
804 | } | ||
805 | |||
806 | log_init(argv[0], ll, SYSLOG_FACILITY_USER, 1); | ||
807 | |||
760 | #ifdef USE_SEED_FILES | 808 | #ifdef USE_SEED_FILES |
761 | prng_read_seedfile(); | 809 | prng_read_seedfile(); |
762 | #endif | 810 | #endif |
763 | 811 | ||
812 | buf = xmalloc(bytes); | ||
813 | |||
764 | /* | 814 | /* |
765 | * Seed the RNG from wherever we can | 815 | * Seed the RNG from wherever we can |
766 | */ | 816 | */ |
767 | 817 | ||
768 | /* Take whatever is on the stack, but don't credit it */ | 818 | /* Take whatever is on the stack, but don't credit it */ |
769 | RAND_add(buf, sizeof(buf), 0); | 819 | RAND_add(buf, bytes, 0); |
770 | 820 | ||
771 | debug("Seeded RNG with %i bytes from system calls", | 821 | debug("Seeded RNG with %i bytes from system calls", |
772 | (int)stir_from_system()); | 822 | (int)stir_from_system()); |
773 | 823 | ||
774 | #ifdef PRNGD_PORT | 824 | #ifdef PRNGD_PORT |
775 | if (get_random_bytes_prngd(buf, sizeof(buf), PRNGD_PORT, NULL) == -1) | 825 | if (get_random_bytes_prngd(buf, bytes, PRNGD_PORT, NULL) == -1) |
776 | fatal("Entropy collection failed"); | 826 | fatal("Entropy collection failed"); |
777 | RAND_add(buf, sizeof(buf), sizeof(buf)); | 827 | RAND_add(buf, bytes, bytes); |
778 | #elif defined(PRNGD_SOCKET) | 828 | #elif defined(PRNGD_SOCKET) |
779 | if (get_random_bytes_prngd(buf, sizeof(buf), 0, PRNGD_SOCKET) == -1) | 829 | if (get_random_bytes_prngd(buf, bytes, 0, PRNGD_SOCKET) == -1) |
780 | fatal("Entropy collection failed"); | 830 | fatal("Entropy collection failed"); |
781 | RAND_add(buf, sizeof(buf), sizeof(buf)); | 831 | RAND_add(buf, bytes, bytes); |
782 | #else | 832 | #else |
783 | /* Read in collection commands */ | 833 | /* Read in collection commands */ |
784 | if (prng_read_commands(SSH_PRNG_COMMAND_FILE) == -1) | 834 | if (prng_read_commands(SSH_PRNG_COMMAND_FILE) == -1) |
@@ -798,12 +848,18 @@ main(int argc, char **argv) | |||
798 | if (!RAND_status()) | 848 | if (!RAND_status()) |
799 | fatal("Not enough entropy in RNG"); | 849 | fatal("Not enough entropy in RNG"); |
800 | 850 | ||
801 | RAND_bytes(buf, sizeof(buf)); | 851 | RAND_bytes(buf, bytes); |
802 | 852 | ||
803 | ret = atomicio(write, STDOUT_FILENO, buf, sizeof(buf)); | 853 | if (output_hex) { |
854 | for(ret = 0; ret < bytes; ret++) | ||
855 | printf("%02x", (unsigned char)(buf[ret])); | ||
856 | printf("\n"); | ||
857 | } else | ||
858 | ret = atomicio(write, STDOUT_FILENO, buf, bytes); | ||
804 | 859 | ||
805 | memset(buf, '\0', sizeof(buf)); | 860 | memset(buf, '\0', bytes); |
861 | xfree(buf); | ||
806 | 862 | ||
807 | return ret == sizeof(buf) ? 0 : 1; | 863 | return ret == bytes ? 0 : 1; |
808 | } | 864 | } |
809 | 865 | ||