diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | Makefile.in | 2 | ||||
-rw-r--r-- | README | 9 | ||||
-rw-r--r-- | acconfig.h | 30 | ||||
-rw-r--r-- | bsd-misc.c | 68 | ||||
-rw-r--r-- | bsd-misc.h | 61 | ||||
-rw-r--r-- | configure.in | 51 | ||||
-rw-r--r-- | entropy.c | 436 | ||||
-rw-r--r-- | entropy.h | 35 | ||||
-rw-r--r-- | random.c | 124 | ||||
-rw-r--r-- | random.h | 41 | ||||
-rw-r--r-- | rsa.c | 19 |
12 files changed, 597 insertions, 283 deletions
@@ -1,3 +1,7 @@ | |||
1 | 20000403 | ||
2 | - Wrote entropy collection routines for systems that lack /dev/random | ||
3 | and EGD | ||
4 | |||
1 | 20000401 | 5 | 20000401 |
2 | - Big OpenBSD CVS update (mainly beginnings of SSH2 infrastructure) | 6 | - Big OpenBSD CVS update (mainly beginnings of SSH2 infrastructure) |
3 | - [auth.c session.c sshd.c auth.h] | 7 | - [auth.c session.c sshd.c auth.h] |
diff --git a/Makefile.in b/Makefile.in index 43870d5f9..89b408487 100644 --- a/Makefile.in +++ b/Makefile.in | |||
@@ -31,7 +31,7 @@ LDFLAGS=-L. @LDFLAGS@ | |||
31 | 31 | ||
32 | TARGETS=ssh sshd ssh-add ssh-keygen ssh-agent scp $(EXTRA_TARGETS) | 32 | TARGETS=ssh sshd ssh-add ssh-keygen ssh-agent scp $(EXTRA_TARGETS) |
33 | 33 | ||
34 | LIBOBJS= atomicio.o authfd.o authfile.o bsd-bindresvport.o bsd-daemon.o bsd-misc.o bsd-mktemp.o bsd-rresvport.o bsd-setenv.o bsd-snprintf.o bsd-strlcat.o bsd-strlcpy.o bufaux.o buffer.o canohost.o channels.o cipher.o compat.o compress.o crc32.o deattack.o dispatch.o fake-getaddrinfo.o fake-getnameinfo.o fingerprint.o hostfile.o key.o log.o match.o mpaux.o nchan.o packet.o radix.o random.o readpass.o rsa.o tildexpand.o ttymodes.o uidswap.o xmalloc.o | 34 | LIBOBJS= atomicio.o authfd.o authfile.o bsd-bindresvport.o bsd-daemon.o bsd-misc.o bsd-mktemp.o bsd-rresvport.o bsd-setenv.o bsd-snprintf.o bsd-strlcat.o bsd-strlcpy.o bufaux.o buffer.o canohost.o channels.o cipher.o compat.o compress.o crc32.o deattack.o dispatch.o fake-getaddrinfo.o fake-getnameinfo.o fingerprint.o hostfile.o key.o log.o match.o mpaux.o nchan.o packet.o radix.o entropy.o readpass.o rsa.o tildexpand.o ttymodes.o uidswap.o xmalloc.o |
35 | 35 | ||
36 | SSHOBJS= ssh.o sshconnect.o log-client.o readconf.o clientloop.o | 36 | SSHOBJS= ssh.o sshconnect.o log-client.o readconf.o clientloop.o |
37 | 37 | ||
@@ -32,11 +32,6 @@ The PAM support is now more functional than the popular packages of | |||
32 | commercial ssh-1.2.x. It checks "account" and "session" modules for | 32 | commercial ssh-1.2.x. It checks "account" and "session" modules for |
33 | all logins, not just when using password authentication. | 33 | all logins, not just when using password authentication. |
34 | 34 | ||
35 | All new code is released under a XFree style license, which is very | ||
36 | liberal. Please refer to the source files for details. The code in | ||
37 | bsd-*.[ch] is from the OpenBSD project and has its own license (again, | ||
38 | see the source files for details). | ||
39 | |||
40 | OpenSSH depends on Zlib[2], OpenSSL[3] and optionally PAM[4] and | 35 | OpenSSH depends on Zlib[2], OpenSSL[3] and optionally PAM[4] and |
41 | Dante[6]. To build the GNOME[5] pass-phrase requester | 36 | Dante[6]. To build the GNOME[5] pass-phrase requester |
42 | (--with-gnome-askpass), you will need the GNOME libraries installed. | 37 | (--with-gnome-askpass), you will need the GNOME libraries installed. |
@@ -64,10 +59,6 @@ This version of SSH is based upon code retrieved from the OpenBSD CVS | |||
64 | repository which in turn was based on the last free | 59 | repository which in turn was based on the last free |
65 | version of SSH released by Tatu Ylonen. | 60 | version of SSH released by Tatu Ylonen. |
66 | 61 | ||
67 | Code in bsd-misc.[ch] and gnome-ssh-askpass.c is Copyright 1999 Damien | ||
68 | Miller & Internet Business Solutions and is released under a X11-style | ||
69 | license (see source files for details). | ||
70 | |||
71 | References - | 62 | References - |
72 | 63 | ||
73 | [1] http://www.lothar.com/tech/crypto/ | 64 | [1] http://www.lothar.com/tech/crypto/ |
diff --git a/acconfig.h b/acconfig.h index 32764f092..cbb3a97cd 100644 --- a/acconfig.h +++ b/acconfig.h | |||
@@ -24,17 +24,8 @@ | |||
24 | /* Location of random number pool */ | 24 | /* Location of random number pool */ |
25 | #undef RANDOM_POOL | 25 | #undef RANDOM_POOL |
26 | 26 | ||
27 | /* Are we using the Entropy gathering daemon */ | 27 | /* Location of EGD random number socket */ |
28 | #undef HAVE_EGD | 28 | #undef EGD_SOCKET |
29 | |||
30 | /* Define if using the Dante SOCKS library. */ | ||
31 | #undef HAVE_DANTE | ||
32 | |||
33 | /* Define if using the Socks4 SOCKS library. */ | ||
34 | #undef HAVE_SOCKS4 | ||
35 | |||
36 | /* Define if using the Socks5 SOCKS library. */ | ||
37 | #undef HAVE_SOCKS5 | ||
38 | 29 | ||
39 | /* Define if you want to install preformatted manpages.*/ | 30 | /* Define if you want to install preformatted manpages.*/ |
40 | #undef MANTYPE | 31 | #undef MANTYPE |
@@ -159,6 +150,23 @@ | |||
159 | /* Detect IPv4 in IPv6 mapped addresses and treat as IPv4 */ | 150 | /* Detect IPv4 in IPv6 mapped addresses and treat as IPv4 */ |
160 | #undef IPV4_IN_IPV6 | 151 | #undef IPV4_IN_IPV6 |
161 | 152 | ||
153 | /* Programs used in entropy collection */ | ||
154 | #undef PROG_LS | ||
155 | #undef PROG_NETSTAT | ||
156 | #undef PROG_ARP | ||
157 | #undef PROG_IFCONFIG | ||
158 | #undef PROG_PS | ||
159 | #undef PROG_W | ||
160 | #undef PROG_WHO | ||
161 | #undef PROG_LAST | ||
162 | #undef PROG_LASTLOG | ||
163 | #undef PROG_DF | ||
164 | #undef PROG_VMSTAT | ||
165 | #undef PROG_UPTIME | ||
166 | #undef PROG_IPCS | ||
167 | #undef PROG_TAIL | ||
168 | |||
169 | |||
162 | @BOTTOM@ | 170 | @BOTTOM@ |
163 | 171 | ||
164 | /* ******************* Shouldn't need to edit below this line ************** */ | 172 | /* ******************* Shouldn't need to edit below this line ************** */ |
diff --git a/bsd-misc.c b/bsd-misc.c index dd1f6a476..3186c86d8 100644 --- a/bsd-misc.c +++ b/bsd-misc.c | |||
@@ -1,38 +1,31 @@ | |||
1 | /* | 1 | /* |
2 | ** | 2 | * Copyright (c) 1999-2000 Damien Miller. All rights reserved. |
3 | ** OpenBSD replacement routines | 3 | * |
4 | ** | 4 | * Redistribution and use in source and binary forms, with or without |
5 | ** Damien Miller <djm@ibs.com.au> | 5 | * modification, are permitted provided that the following conditions |
6 | ** | 6 | * are met: |
7 | ** Copyright 1999 Damien Miller | 7 | * 1. Redistributions of source code must retain the above copyright |
8 | ** Copyright 1999 Internet Business Solutions | 8 | * notice, this list of conditions and the following disclaimer. |
9 | ** | 9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | ** Permission is hereby granted, free of charge, to any person | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | ** obtaining a copy of this software and associated documentation | 11 | * documentation and/or other materials provided with the distribution. |
12 | ** files (the "Software"), to deal in the Software without | 12 | * 3. All advertising materials mentioning features or use of this software |
13 | ** restriction, including without limitation the rights to use, copy, | 13 | * must display the following acknowledgement: |
14 | ** modify, merge, publish, distribute, sublicense, and/or sell copies | 14 | * This product includes software developed by Markus Friedl. |
15 | ** of the Software, and to permit persons to whom the Software is | 15 | * 4. The name of the author may not be used to endorse or promote products |
16 | ** furnished to do so, subject to the following conditions: | 16 | * derived from this software without specific prior written permission. |
17 | ** | 17 | * |
18 | ** The above copyright notice and this permission notice shall be | 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
19 | ** included in all copies or substantial portions of the Software. | 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
20 | ** | 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
21 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY | 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
22 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE | 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
23 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE | 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 | ** AND NONINFRINGEMENT. IN NO EVENT SHALL DAMIEN MILLER OR INTERNET | 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 | ** BUSINESS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | ** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
27 | ** ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE | 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | ** OR OTHER DEALINGS IN THE SOFTWARE. | 28 | */ |
29 | ** | ||
30 | ** Except as contained in this notice, the name of Internet Business | ||
31 | ** Solutions shall not be used in advertising or otherwise to promote | ||
32 | ** the sale, use or other dealings in this Software without prior | ||
33 | ** written authorization from Internet Business Solutions. | ||
34 | ** | ||
35 | */ | ||
36 | 29 | ||
37 | #include "config.h" | 30 | #include "config.h" |
38 | 31 | ||
@@ -52,7 +45,7 @@ | |||
52 | #include "xmalloc.h" | 45 | #include "xmalloc.h" |
53 | #include "ssh.h" | 46 | #include "ssh.h" |
54 | #include "bsd-misc.h" | 47 | #include "bsd-misc.h" |
55 | #include "random.h" | 48 | #include "entropy.h" |
56 | 49 | ||
57 | #ifndef HAVE_ARC4RANDOM | 50 | #ifndef HAVE_ARC4RANDOM |
58 | 51 | ||
@@ -125,8 +118,11 @@ void arc4random_stir(void) | |||
125 | 118 | ||
126 | if (rc4 == NULL) | 119 | if (rc4 == NULL) |
127 | rc4 = xmalloc(sizeof(*rc4)); | 120 | rc4 = xmalloc(sizeof(*rc4)); |
121 | |||
122 | seed_rng(); | ||
123 | RAND_bytes(rand_buf, sizeof(rand_buf)); | ||
124 | seed_rng(); | ||
128 | 125 | ||
129 | get_random_bytes(rand_buf, sizeof(rand_buf)); | ||
130 | rc4_key(rc4, rand_buf, sizeof(rand_buf)); | 126 | rc4_key(rc4, rand_buf, sizeof(rand_buf)); |
131 | memset(rand_buf, 0, sizeof(rand_buf)); | 127 | memset(rand_buf, 0, sizeof(rand_buf)); |
132 | } | 128 | } |
diff --git a/bsd-misc.h b/bsd-misc.h index 9d499c805..cdf8e2b67 100644 --- a/bsd-misc.h +++ b/bsd-misc.h | |||
@@ -1,38 +1,31 @@ | |||
1 | /* | 1 | /* |
2 | ** | 2 | * Copyright (c) 1999-2000 Damien Miller. All rights reserved. |
3 | ** OpenBSD replacement routines | 3 | * |
4 | ** | 4 | * Redistribution and use in source and binary forms, with or without |
5 | ** Damien Miller <djm@ibs.com.au> | 5 | * modification, are permitted provided that the following conditions |
6 | ** | 6 | * are met: |
7 | ** Copyright 1999 Damien Miller | 7 | * 1. Redistributions of source code must retain the above copyright |
8 | ** Copyright 1999 Internet Business Solutions | 8 | * notice, this list of conditions and the following disclaimer. |
9 | ** | 9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | ** Permission is hereby granted, free of charge, to any person | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | ** obtaining a copy of this software and associated documentation | 11 | * documentation and/or other materials provided with the distribution. |
12 | ** files (the "Software"), to deal in the Software without | 12 | * 3. All advertising materials mentioning features or use of this software |
13 | ** restriction, including without limitation the rights to use, copy, | 13 | * must display the following acknowledgement: |
14 | ** modify, merge, publish, distribute, sublicense, and/or sell copies | 14 | * This product includes software developed by Markus Friedl. |
15 | ** of the Software, and to permit persons to whom the Software is | 15 | * 4. The name of the author may not be used to endorse or promote products |
16 | ** furnished to do so, subject to the following conditions: | 16 | * derived from this software without specific prior written permission. |
17 | ** | 17 | * |
18 | ** The above copyright notice and this permission notice shall be | 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
19 | ** included in all copies or substantial portions of the Software. | 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
20 | ** | 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
21 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY | 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
22 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE | 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
23 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE | 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 | ** AND NONINFRINGEMENT. IN NO EVENT SHALL DAMIEN MILLER OR INTERNET | 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 | ** BUSINESS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | ** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
27 | ** ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE | 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | ** OR OTHER DEALINGS IN THE SOFTWARE. | 28 | */ |
29 | ** | ||
30 | ** Except as contained in this notice, the name of Internet Business | ||
31 | ** Solutions shall not be used in advertising or otherwise to promote | ||
32 | ** the sale, use or other dealings in this Software without prior | ||
33 | ** written authorization from Internet Business Solutions. | ||
34 | ** | ||
35 | */ | ||
36 | 29 | ||
37 | #ifndef _BSD_MISC_H | 30 | #ifndef _BSD_MISC_H |
38 | #define _BSD_MISC_H | 31 | #define _BSD_MISC_H |
diff --git a/configure.in b/configure.in index 2d2fbe1ac..6c9ea3129 100644 --- a/configure.in +++ b/configure.in | |||
@@ -12,6 +12,36 @@ AC_CHECK_PROG(AR, ar, ar) | |||
12 | AC_PATH_PROG(PERL, perl) | 12 | AC_PATH_PROG(PERL, perl) |
13 | AC_SUBST(PERL) | 13 | AC_SUBST(PERL) |
14 | 14 | ||
15 | # We may need these for entropy collection | ||
16 | AC_PATH_PROG(PROG_LS, ls) | ||
17 | AC_DEFINE_UNQUOTED(PROG_LS, "$PROG_LS") | ||
18 | AC_PATH_PROG(PROG_NETSTAT, netstat) | ||
19 | AC_DEFINE_UNQUOTED(PROG_NETSTAT, "$PROG_NETSTAT") | ||
20 | AC_PATH_PROG(PROG_ARP, arp) | ||
21 | AC_DEFINE_UNQUOTED(PROG_ARP, "$PROG_ARP") | ||
22 | AC_PATH_PROG(PROG_IFCONFIG, ifconfig) | ||
23 | AC_DEFINE_UNQUOTED(PROG_IFCONFIG, "$PROG_IFCONFIG") | ||
24 | AC_PATH_PROG(PROG_PS, ps) | ||
25 | AC_DEFINE_UNQUOTED(PROG_PS, "$PROG_PS") | ||
26 | AC_PATH_PROG(PROG_W, w) | ||
27 | AC_DEFINE_UNQUOTED(PROG_W, "$PROG_W") | ||
28 | AC_PATH_PROG(PROG_WHO, who) | ||
29 | AC_DEFINE_UNQUOTED(PROG_WHO, "$PROG_WHO") | ||
30 | AC_PATH_PROG(PROG_LAST, last) | ||
31 | AC_DEFINE_UNQUOTED(PROG_LAST, "$PROG_LAST") | ||
32 | AC_PATH_PROG(PROG_LASTLOG, lastlog) | ||
33 | AC_DEFINE_UNQUOTED(PROG_LASTLOG, "$PROG_LASTLOG") | ||
34 | AC_PATH_PROG(PROG_DF, df) | ||
35 | AC_DEFINE_UNQUOTED(PROG_DF, "$PROG_DF") | ||
36 | AC_PATH_PROG(PROG_VMSTAT, vmstat) | ||
37 | AC_DEFINE_UNQUOTED(PROG_VMSTAT, "$PROG_VMSTAT") | ||
38 | AC_PATH_PROG(PROG_UPTIME, uptime) | ||
39 | AC_DEFINE_UNQUOTED(PROG_UPTIME, "$PROG_UPTIME") | ||
40 | AC_PATH_PROG(PROG_IPCS, ipcs) | ||
41 | AC_DEFINE_UNQUOTED(PROG_UPTIME, "$PROG_UPTIME") | ||
42 | AC_PATH_PROG(PROG_TAIL, tail) | ||
43 | AC_DEFINE_UNQUOTED(PROG_TAIL, "$PROG_TAIL") | ||
44 | |||
15 | if test -z "$LD" ; then | 45 | if test -z "$LD" ; then |
16 | LD=$CC | 46 | LD=$CC |
17 | fi | 47 | fi |
@@ -110,7 +140,7 @@ fi | |||
110 | AC_CHECK_HEADERS(bstring.h endian.h lastlog.h login.h maillock.h netdb.h netgroup.h paths.h poll.h pty.h shadow.h security/pam_appl.h sys/bitypes.h sys/bsdtty.h sys/cdefs.h sys/poll.h sys/select.h sys/stropts.h sys/sysmacros.h sys/time.h sys/ttcompat.h stddef.h util.h utmp.h utmpx.h) | 140 | AC_CHECK_HEADERS(bstring.h endian.h lastlog.h login.h maillock.h netdb.h netgroup.h paths.h poll.h pty.h shadow.h security/pam_appl.h sys/bitypes.h sys/bsdtty.h sys/cdefs.h sys/poll.h sys/select.h sys/stropts.h sys/sysmacros.h sys/time.h sys/ttcompat.h stddef.h util.h utmp.h utmpx.h) |
111 | 141 | ||
112 | # Checks for library functions. | 142 | # Checks for library functions. |
113 | AC_CHECK_FUNCS(arc4random bindresvport_af freeaddrinfo gai_strerror getaddrinfo getnameinfo innetgr md5_crypt mkdtemp openpty rresvport_af setenv seteuid setlogin setproctitle setreuid snprintf strlcat strlcpy updwtmpx vsnprintf _getpty) | 143 | AC_CHECK_FUNCS(arc4random bindresvport_af clock freeaddrinfo gai_strerror getaddrinfo getnameinfo getrusage innetgr md5_crypt mkdtemp openpty rresvport_af setenv seteuid setlogin setproctitle setreuid snprintf strlcat strlcpy updwtmpx vsnprintf _getpty) |
114 | 144 | ||
115 | AC_CHECK_FUNC(login, | 145 | AC_CHECK_FUNC(login, |
116 | [AC_DEFINE(HAVE_LOGIN)], | 146 | [AC_DEFINE(HAVE_LOGIN)], |
@@ -604,8 +634,10 @@ AC_CHECK_FILE("/dev/ptc", | |||
604 | AC_ARG_WITH(random, | 634 | AC_ARG_WITH(random, |
605 | [ --with-random=FILE read randomness from FILE (default=/dev/urandom)], | 635 | [ --with-random=FILE read randomness from FILE (default=/dev/urandom)], |
606 | [ | 636 | [ |
607 | RANDOM_POOL="$withval"; | 637 | if test "x$withval" != "xno" ; then |
608 | AC_DEFINE_UNQUOTED(RANDOM_POOL, "$RANDOM_POOL") | 638 | RANDOM_POOL="$withval"; |
639 | AC_DEFINE_UNQUOTED(RANDOM_POOL, "$RANDOM_POOL") | ||
640 | fi | ||
609 | ], | 641 | ], |
610 | [ | 642 | [ |
611 | # Check for random device | 643 | # Check for random device |
@@ -623,18 +655,13 @@ AC_ARG_WITH(random, | |||
623 | AC_ARG_WITH(egd-pool, | 655 | AC_ARG_WITH(egd-pool, |
624 | [ --with-egd-pool=FILE read randomness from EGD pool FILE (default none)], | 656 | [ --with-egd-pool=FILE read randomness from EGD pool FILE (default none)], |
625 | [ | 657 | [ |
626 | RANDOM_POOL="$withval"; | 658 | if test "x$withval" != "xno" ; then |
627 | AC_DEFINE(HAVE_EGD) | 659 | EGD_SOCKET="$withval"; |
628 | AC_SUBST(RANDOM_POOL) | 660 | AC_DEFINE_UNQUOTED(EGD_SOCKET, "$EGD_SOCKET") |
629 | AC_DEFINE_UNQUOTED(RANDOM_POOL, "$RANDOM_POOL") | 661 | fi |
630 | ] | 662 | ] |
631 | ) | 663 | ) |
632 | 664 | ||
633 | # Make sure we have some random number support | ||
634 | if test -z "$RANDOM_POOL" -a -z "$EGD_POOL"; then | ||
635 | AC_MSG_ERROR([No random device found, and no EGD random pool specified]) | ||
636 | fi | ||
637 | |||
638 | AC_ARG_WITH(catman, | 665 | AC_ARG_WITH(catman, |
639 | [ --with-catman=man|cat Install preformatted manpages[no]], | 666 | [ --with-catman=man|cat Install preformatted manpages[no]], |
640 | [ | 667 | [ |
diff --git a/entropy.c b/entropy.c new file mode 100644 index 000000000..16731775c --- /dev/null +++ b/entropy.c | |||
@@ -0,0 +1,436 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2000 Damien Miller. All rights reserved. | ||
3 | * | ||
4 | * Redistribution and use in source and binary forms, with or without | ||
5 | * modification, are permitted provided that the following conditions | ||
6 | * are met: | ||
7 | * 1. Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * 2. Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * 3. All advertising materials mentioning features or use of this software | ||
13 | * must display the following acknowledgement: | ||
14 | * This product includes software developed by Markus Friedl. | ||
15 | * 4. The name of the author may not be used to endorse or promote products | ||
16 | * derived from this software without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
28 | */ | ||
29 | |||
30 | #include "includes.h" | ||
31 | |||
32 | #include "ssh.h" | ||
33 | #include "xmalloc.h" | ||
34 | |||
35 | #ifdef HAVE_OPENSSL | ||
36 | # include <openssl/rand.h> | ||
37 | # include <openssl/sha.h> | ||
38 | #endif | ||
39 | #ifdef HAVE_SSL | ||
40 | # include <ssl/rand.h> | ||
41 | # include <ssl/sha.h> | ||
42 | #endif | ||
43 | |||
44 | RCSID("$Id: entropy.c,v 1.1 2000/04/03 04:50:45 damien Exp $"); | ||
45 | |||
46 | #ifdef EGD_SOCKET | ||
47 | #ifndef offsetof | ||
48 | # define offsetof(type, member) ((size_t) &((type *)0)->member) | ||
49 | #endif | ||
50 | /* Collect entropy from EGD */ | ||
51 | void get_random_bytes(unsigned char *buf, int len) | ||
52 | { | ||
53 | static int egd_socket = -1; | ||
54 | int c; | ||
55 | char egd_message[2] = { 0x02, 0x00 }; | ||
56 | struct sockaddr_un addr; | ||
57 | int addr_len; | ||
58 | |||
59 | memset(&addr, '\0', sizeof(addr)); | ||
60 | addr.sun_family = AF_UNIX; | ||
61 | |||
62 | /* FIXME: compile time check? */ | ||
63 | if (sizeof(EGD_SOCKET) > sizeof(addr.sun_path)) | ||
64 | fatal("Random pool path is too long"); | ||
65 | |||
66 | strcpy(addr.sun_path, EGD_SOCKET); | ||
67 | |||
68 | addr_len = offsetof(struct sockaddr_un, sun_path) + sizeof(EGD_SOCKET); | ||
69 | |||
70 | if (egd_socket == -1) { | ||
71 | egd_socket = socket(AF_UNIX, SOCK_STREAM, 0); | ||
72 | if (egd_socket == -1) | ||
73 | fatal("Couldn't create AF_UNIX socket: %s", strerror(errno)); | ||
74 | if (connect(egd_socket, (struct sockaddr*)&addr, addr_len) == -1) | ||
75 | fatal("Couldn't connect to EGD socket \"%s\": %s", addr.sun_path, strerror(errno)); | ||
76 | } | ||
77 | |||
78 | if (len > 255) | ||
79 | fatal("Too many bytes to read from EGD"); | ||
80 | |||
81 | /* Send blocking read request to EGD */ | ||
82 | egd_message[1] = len; | ||
83 | |||
84 | c = atomicio(write, egd_socket, egd_message, sizeof(egd_message)); | ||
85 | if (c == -1) | ||
86 | fatal("Couldn't write to EGD socket \"%s\": %s", EGD_SOCKET, strerror(errno)); | ||
87 | |||
88 | c = atomicio(read, egd_socket, buf, len); | ||
89 | if (c <= 0) | ||
90 | fatal("Couldn't read from EGD socket \"%s\": %s", EGD_SOCKET, strerror(errno)); | ||
91 | |||
92 | close(EGD_SOCKET); | ||
93 | } | ||
94 | #else /* !EGD_SOCKET */ | ||
95 | #ifdef RANDOM_POOL | ||
96 | /* Collect entropy from /dev/urandom or pipe */ | ||
97 | void get_random_bytes(unsigned char *buf, int len) | ||
98 | { | ||
99 | static int random_pool = -1; | ||
100 | int c; | ||
101 | |||
102 | if (random_pool == -1) { | ||
103 | random_pool = open(RANDOM_POOL, O_RDONLY); | ||
104 | if (random_pool == -1) | ||
105 | fatal("Couldn't open random pool \"%s\": %s", RANDOM_POOL, strerror(errno)); | ||
106 | } | ||
107 | |||
108 | verbose("randfd: %i", random_pool); | ||
109 | |||
110 | c = atomicio(read, random_pool, buf, len); | ||
111 | if (c <= 0) | ||
112 | fatal("Couldn't read from random pool \"%s\": %s", RANDOM_POOL, strerror(errno)); | ||
113 | } | ||
114 | #endif /* RANDOM_POOL */ | ||
115 | #endif /* EGD_SOCKET */ | ||
116 | |||
117 | #if !defined(EGD_SOCKET) && !defined(RANDOM_POOL) | ||
118 | /* | ||
119 | * FIXME: proper entropy estimations. All current values are guesses | ||
120 | * FIXME: Need timeout for slow moving programs | ||
121 | * FIXME: More entropy sources | ||
122 | */ | ||
123 | |||
124 | double stir_from_system(void); | ||
125 | double stir_from_programs(void); | ||
126 | double stir_gettimeofday(double entropy_estimate); | ||
127 | double stir_clock(double entropy_estimate); | ||
128 | double stir_rusage(int who, double entropy_estimate); | ||
129 | double hash_output_from_command(const char *path, const char **args, char *hash); | ||
130 | |||
131 | typedef struct | ||
132 | { | ||
133 | /* Proportion of data that is entropy */ | ||
134 | double rate; | ||
135 | /* Path to executable */ | ||
136 | const char *path; | ||
137 | /* argv to pass to executable */ | ||
138 | const char *args[5]; | ||
139 | } entropy_source_t; | ||
140 | |||
141 | entropy_source_t entropy_sources[] = { | ||
142 | #ifdef PROG_LS | ||
143 | { 0.002, PROG_LS, { "ls", "-alni", "/var/log", NULL } }, | ||
144 | { 0.002, PROG_LS, { "ls", "-alni", "/var/adm", NULL } }, | ||
145 | { 0.002, PROG_LS, { "ls", "-alni", "/var/mail", NULL } }, | ||
146 | { 0.002, PROG_LS, { "ls", "-alni", "/var/spool/mail", NULL } }, | ||
147 | { 0.002, PROG_LS, { "ls", "-alni", "/proc", NULL } }, | ||
148 | { 0.002, PROG_LS, { "ls", "-alni", "/tmp", NULL } }, | ||
149 | #endif | ||
150 | #ifdef PROG_NETSTAT | ||
151 | { 0.005, PROG_NETSTAT, { "netstat","-an", NULL, NULL } }, | ||
152 | { 0.010, PROG_NETSTAT, { "netstat","-in", NULL, NULL } }, | ||
153 | { 0.002, PROG_NETSTAT, { "netstat","-rn", NULL, NULL } }, | ||
154 | { 0.002, PROG_NETSTAT, { "netstat","-s", NULL, NULL } }, | ||
155 | #endif | ||
156 | #ifdef PROG_ARP | ||
157 | { 0.002, PROG_ARP, { "arp","-a","-n", NULL } }, | ||
158 | #endif | ||
159 | #ifdef PROG_IFCONFIG | ||
160 | { 0.002, PROG_IFCONFIG, { "ifconfig", "-a", NULL, NULL } }, | ||
161 | #endif | ||
162 | #ifdef PROG_PS | ||
163 | { 0.003, PROG_PS, { "ps", "laxww", NULL, NULL } }, | ||
164 | { 0.003, PROG_PS, { "ps", "-al", NULL, NULL } }, | ||
165 | { 0.003, PROG_PS, { "ps", "-efl", NULL, NULL } }, | ||
166 | #endif | ||
167 | #ifdef PROG_W | ||
168 | { 0.005, PROG_W, { "w", NULL, NULL, NULL } }, | ||
169 | #endif | ||
170 | #ifdef PROG_WHO | ||
171 | { 0.001, PROG_WHO, { "who","-i", NULL, NULL } }, | ||
172 | #endif | ||
173 | #ifdef PROG_LAST | ||
174 | { 0.001, PROG_LAST, { "last", NULL, NULL, NULL } }, | ||
175 | #endif | ||
176 | #ifdef PROG_LASTLOG | ||
177 | { 0.001, PROG_LASTLOG, { "lastlog", NULL, NULL, NULL } }, | ||
178 | #endif | ||
179 | #ifdef PROG_DF | ||
180 | { 0.010, PROG_DF, { "df", NULL, NULL, NULL } }, | ||
181 | { 0.010, PROG_DF, { "df", "-i", NULL, NULL } }, | ||
182 | #endif | ||
183 | #ifdef PROG_VMSTAT | ||
184 | { 0.010, PROG_VMSTAT, { "vmstat", NULL, NULL, NULL } }, | ||
185 | #endif | ||
186 | #ifdef PROG_UPTIME | ||
187 | { 0.001, PROG_UPTIME, { "uptime", NULL, NULL, NULL } }, | ||
188 | #endif | ||
189 | #ifdef PROG_IPCS | ||
190 | { 0.001, PROG_IPCS, { "-a", NULL, NULL, NULL } }, | ||
191 | #endif | ||
192 | #ifdef PROG_TAIL | ||
193 | { 0.001, PROG_TAIL, { "tail", "-200", "/var/log/messages", NULL, NULL } }, | ||
194 | { 0.001, PROG_TAIL, { "tail", "-200", "/var/log/syslog", NULL, NULL } }, | ||
195 | { 0.001, PROG_TAIL, { "tail", "-200", "/var/adm/messages", NULL, NULL } }, | ||
196 | { 0.001, PROG_TAIL, { "tail", "-200", "/var/adm/syslog", NULL, NULL } }, | ||
197 | { 0.001, PROG_TAIL, { "tail", "-200", "/var/log/maillog", NULL, NULL } }, | ||
198 | { 0.001, PROG_TAIL, { "tail", "-200", "/var/adm/maillog", NULL, NULL } }, | ||
199 | #endif | ||
200 | { 0.000, NULL, { NULL, NULL, NULL, NULL, NULL } }, | ||
201 | }; | ||
202 | |||
203 | |||
204 | double | ||
205 | stir_from_system(void) | ||
206 | { | ||
207 | double total_entropy_estimate; | ||
208 | long int i; | ||
209 | |||
210 | total_entropy_estimate = 0; | ||
211 | |||
212 | i = getpid(); | ||
213 | RAND_add(&i, sizeof(i), 0.1); | ||
214 | total_entropy_estimate += 0.1; | ||
215 | |||
216 | i = getppid(); | ||
217 | RAND_add(&i, sizeof(i), 0.1); | ||
218 | total_entropy_estimate += 0.1; | ||
219 | |||
220 | i = getuid(); | ||
221 | RAND_add(&i, sizeof(i), 0.0); | ||
222 | i = getgid(); | ||
223 | RAND_add(&i, sizeof(i), 0.0); | ||
224 | |||
225 | total_entropy_estimate += stir_gettimeofday(1.0); | ||
226 | total_entropy_estimate += stir_clock(0.2); | ||
227 | total_entropy_estimate += stir_rusage(RUSAGE_SELF, 2.0); | ||
228 | |||
229 | return(total_entropy_estimate); | ||
230 | } | ||
231 | |||
232 | double | ||
233 | stir_from_programs(void) | ||
234 | { | ||
235 | int i; | ||
236 | int c; | ||
237 | double entropy_estimate; | ||
238 | double total_entropy_estimate; | ||
239 | char hash[SHA_DIGEST_LENGTH]; | ||
240 | |||
241 | /* | ||
242 | * Run through list of programs twice to catch differences | ||
243 | */ | ||
244 | total_entropy_estimate = 0; | ||
245 | for(i = 0; i < 2; i++) { | ||
246 | c = 0; | ||
247 | while (entropy_sources[c].path != NULL) { | ||
248 | /* Hash output from command */ | ||
249 | entropy_estimate = hash_output_from_command(entropy_sources[c].path, | ||
250 | entropy_sources[c].args, hash); | ||
251 | |||
252 | /* Scale back entropy estimate according to command's rate */ | ||
253 | entropy_estimate *= entropy_sources[c].rate; | ||
254 | |||
255 | /* Upper bound of entropy estimate is SHA_DIGEST_LENGTH */ | ||
256 | if (entropy_estimate > SHA_DIGEST_LENGTH) | ||
257 | entropy_estimate = SHA_DIGEST_LENGTH; | ||
258 | |||
259 | /* * Scale back estimates for subsequent passes through list */ | ||
260 | entropy_estimate /= 10.0 * (i + 1.0); | ||
261 | |||
262 | /* Stir it in */ | ||
263 | RAND_add(hash, sizeof(hash), entropy_estimate); | ||
264 | |||
265 | /* FIXME: turn this off later */ | ||
266 | #if 1 | ||
267 | debug("Got %0.2f bytes of entropy from %s", entropy_estimate, | ||
268 | entropy_sources[c].path); | ||
269 | #endif | ||
270 | |||
271 | total_entropy_estimate += entropy_estimate; | ||
272 | |||
273 | /* Execution times should be a little unpredictable */ | ||
274 | total_entropy_estimate += stir_gettimeofday(0.05); | ||
275 | total_entropy_estimate += stir_clock(0.05); | ||
276 | total_entropy_estimate += stir_rusage(RUSAGE_SELF, 0.1); | ||
277 | total_entropy_estimate += stir_rusage(RUSAGE_CHILDREN, 0.1); | ||
278 | |||
279 | c++; | ||
280 | } | ||
281 | } | ||
282 | |||
283 | return(total_entropy_estimate); | ||
284 | } | ||
285 | |||
286 | double | ||
287 | stir_gettimeofday(double entropy_estimate) | ||
288 | { | ||
289 | struct timeval tv; | ||
290 | |||
291 | if (gettimeofday(&tv, NULL) == -1) | ||
292 | fatal("Couldn't gettimeofday: %s", strerror(errno)); | ||
293 | |||
294 | RAND_add(&tv, sizeof(tv), entropy_estimate); | ||
295 | |||
296 | return(entropy_estimate); | ||
297 | } | ||
298 | |||
299 | double | ||
300 | stir_clock(double entropy_estimate) | ||
301 | { | ||
302 | #ifdef HAVE_CLOCK | ||
303 | clock_t c; | ||
304 | |||
305 | c = clock(); | ||
306 | RAND_add(&c, sizeof(c), entropy_estimate); | ||
307 | |||
308 | return(entropy_estimate); | ||
309 | #else /* _HAVE_CLOCK */ | ||
310 | return(0); | ||
311 | #endif /* _HAVE_CLOCK */ | ||
312 | } | ||
313 | |||
314 | double | ||
315 | stir_rusage(int who, double entropy_estimate) | ||
316 | { | ||
317 | #ifdef HAVE_GETRUSAGE | ||
318 | struct rusage ru; | ||
319 | |||
320 | if (getrusage(who, &ru) == -1) | ||
321 | fatal("Couldn't getrusage: %s", strerror(errno)); | ||
322 | |||
323 | RAND_add(&ru, sizeof(ru), 0.1); | ||
324 | |||
325 | return(entropy_estimate); | ||
326 | #else /* _HAVE_GETRUSAGE */ | ||
327 | return(0); | ||
328 | #endif /* _HAVE_GETRUSAGE */ | ||
329 | } | ||
330 | |||
331 | double | ||
332 | hash_output_from_command(const char *path, const char **args, char *hash) | ||
333 | { | ||
334 | static int devnull = -1; | ||
335 | int p[2]; | ||
336 | pid_t pid; | ||
337 | int status; | ||
338 | char buf[2048]; | ||
339 | int bytes_read; | ||
340 | int total_bytes_read; | ||
341 | SHA_CTX sha; | ||
342 | |||
343 | if (devnull == -1) { | ||
344 | devnull = open("/dev/null", O_RDWR); | ||
345 | if (devnull == -1) | ||
346 | fatal("Couldn't open /dev/null: %s", strerror(errno)); | ||
347 | } | ||
348 | |||
349 | if (pipe(p) == -1) | ||
350 | fatal("Couldn't open pipe: %s", strerror(errno)); | ||
351 | |||
352 | switch (pid = fork()) { | ||
353 | case -1: /* Error */ | ||
354 | close(p[0]); | ||
355 | close(p[1]); | ||
356 | fatal("Couldn't fork: %s", strerror(errno)); | ||
357 | /* NOTREACHED */ | ||
358 | case 0: /* Child */ | ||
359 | close(0); | ||
360 | close(1); | ||
361 | close(2); | ||
362 | dup2(devnull, 0); | ||
363 | dup2(p[1], 1); | ||
364 | dup2(p[1], 2); | ||
365 | close(p[0]); | ||
366 | close(p[1]); | ||
367 | close(devnull); | ||
368 | |||
369 | execv(path, (char**)args); | ||
370 | debug("(child) Couldn't exec '%s': %s", path, strerror(errno)); | ||
371 | _exit(-1); | ||
372 | default: /* Parent */ | ||
373 | break; | ||
374 | } | ||
375 | |||
376 | RAND_add(&pid, sizeof(&pid), 0.0); | ||
377 | |||
378 | close(p[1]); | ||
379 | |||
380 | /* Hash output from child */ | ||
381 | SHA1_Init(&sha); | ||
382 | total_bytes_read = 0; | ||
383 | while ((bytes_read = read(p[0], buf, sizeof(buf))) > 0) { | ||
384 | SHA1_Update(&sha, buf, bytes_read); | ||
385 | total_bytes_read += bytes_read; | ||
386 | RAND_add(&bytes_read, sizeof(&bytes_read), 0.0); | ||
387 | } | ||
388 | SHA1_Final(hash, &sha); | ||
389 | |||
390 | close(p[0]); | ||
391 | |||
392 | if (waitpid(pid, &status, 0) == -1) { | ||
393 | error("Couldn't wait for child '%s' completion: %s", path, | ||
394 | strerror(errno)); | ||
395 | return(-1); | ||
396 | } | ||
397 | |||
398 | RAND_add(&status, sizeof(&status), 0.0); | ||
399 | |||
400 | if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) | ||
401 | return(0.0); | ||
402 | else | ||
403 | return(total_bytes_read); | ||
404 | } | ||
405 | #endif /* defined(EGD_SOCKET) || defined(RANDOM_POOL) */ | ||
406 | |||
407 | #if defined(EGD_SOCKET) || defined(RANDOM_POOL) | ||
408 | /* | ||
409 | * Seed OpenSSL's random number pool from Kernel random number generator | ||
410 | * or EGD | ||
411 | */ | ||
412 | void | ||
413 | seed_rng(void) | ||
414 | { | ||
415 | char buf[32]; | ||
416 | |||
417 | debug("Seeding random number generator"); | ||
418 | get_random_bytes(buf, sizeof(buf)); | ||
419 | RAND_add(buf, sizeof(buf), sizeof(buf)); | ||
420 | memset(buf, '\0', sizeof(buf)); | ||
421 | } | ||
422 | #else /* defined(EGD_SOCKET) || defined(RANDOM_POOL) */ | ||
423 | /* | ||
424 | * Conditionally Seed OpenSSL's random number pool syscalls and program output | ||
425 | */ | ||
426 | void | ||
427 | seed_rng(void) | ||
428 | { | ||
429 | if (!RAND_status()) { | ||
430 | debug("Seeding random number generator."); | ||
431 | debug("%i bytes from system calls", (int)stir_from_system()); | ||
432 | debug("%i bytes from programs", (int)stir_from_programs()); | ||
433 | debug("OpenSSL random status is now %i\n", RAND_status()); | ||
434 | } | ||
435 | } | ||
436 | #endif /* defined(EGD_SOCKET) || defined(RANDOM_POOL) */ | ||
diff --git a/entropy.h b/entropy.h new file mode 100644 index 000000000..ec425a0cb --- /dev/null +++ b/entropy.h | |||
@@ -0,0 +1,35 @@ | |||
1 | /* | ||
2 | * Copyright (c) 1999-2000 Damien Miller. All rights reserved. | ||
3 | * | ||
4 | * Redistribution and use in source and binary forms, with or without | ||
5 | * modification, are permitted provided that the following conditions | ||
6 | * are met: | ||
7 | * 1. Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * 2. Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * 3. All advertising materials mentioning features or use of this software | ||
13 | * must display the following acknowledgement: | ||
14 | * This product includes software developed by Markus Friedl. | ||
15 | * 4. The name of the author may not be used to endorse or promote products | ||
16 | * derived from this software without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
28 | */ | ||
29 | |||
30 | #ifndef _RANDOMS_H | ||
31 | #define _RANDOMS_H | ||
32 | |||
33 | void seed_rng(void); | ||
34 | |||
35 | #endif /* _RANDOMS_H */ | ||
diff --git a/random.c b/random.c deleted file mode 100644 index 06c8d2b3c..000000000 --- a/random.c +++ /dev/null | |||
@@ -1,124 +0,0 @@ | |||
1 | /* | ||
2 | ** | ||
3 | ** Random number collection | ||
4 | ** | ||
5 | ** Damien Miller <djm@ibs.com.au> | ||
6 | ** | ||
7 | ** Copyright 1999 Damien Miller | ||
8 | ** | ||
9 | ** Permission is hereby granted, free of charge, to any person | ||
10 | ** obtaining a copy of this software and associated documentation | ||
11 | ** files (the "Software"), to deal in the Software without | ||
12 | ** restriction, including without limitation the rights to use, copy, | ||
13 | ** modify, merge, publish, distribute, sublicense, and/or sell copies | ||
14 | ** of the Software, and to permit persons to whom the Software is | ||
15 | ** furnished to do so, subject to the following conditions: | ||
16 | ** | ||
17 | ** The above copyright notice and this permission notice shall be | ||
18 | ** included in all copies or substantial portions of the Software. | ||
19 | ** | ||
20 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY | ||
21 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE | ||
22 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE | ||
23 | ** AND NONINFRINGEMENT. IN NO EVENT SHALL DAMIEN MILLER OR INTERNET | ||
24 | ** BUSINESS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
25 | ** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
26 | ** ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE | ||
27 | ** OR OTHER DEALINGS IN THE SOFTWARE. | ||
28 | ** | ||
29 | ** Except as contained in this notice, the name of Internet Business | ||
30 | ** Solutions shall not be used in advertising or otherwise to promote | ||
31 | ** the sale, use or other dealings in this Software without prior | ||
32 | ** written authorization from Internet Business Solutions. | ||
33 | ** | ||
34 | */ | ||
35 | |||
36 | #include <stdio.h> | ||
37 | #include <stdlib.h> | ||
38 | #include <string.h> | ||
39 | #include <errno.h> | ||
40 | #include <unistd.h> | ||
41 | |||
42 | #include <sys/types.h> | ||
43 | #include <sys/stat.h> | ||
44 | #include <sys/socket.h> | ||
45 | #include <sys/un.h> | ||
46 | #include <fcntl.h> | ||
47 | #ifdef HAVE_STDDEF_H | ||
48 | #include <stddef.h> | ||
49 | #endif | ||
50 | |||
51 | #include "ssh.h" | ||
52 | #include "xmalloc.h" | ||
53 | #include "random.h" | ||
54 | |||
55 | #ifndef offsetof | ||
56 | # define offsetof(type, member) ((size_t) &((type *)0)->member) | ||
57 | #endif | ||
58 | |||
59 | #ifdef HAVE_EGD | ||
60 | |||
61 | /* Collect entropy from EGD */ | ||
62 | void get_random_bytes(unsigned char *buf, int len) | ||
63 | { | ||
64 | static int random_pool; | ||
65 | int c; | ||
66 | char egd_message[2] = { 0x02, 0x00 }; | ||
67 | struct sockaddr_un addr; | ||
68 | int addr_len; | ||
69 | |||
70 | memset(&addr, '\0', sizeof(addr)); | ||
71 | addr.sun_family = AF_UNIX; | ||
72 | |||
73 | /* FIXME: compile time check? */ | ||
74 | if (sizeof(RANDOM_POOL) > sizeof(addr.sun_path)) | ||
75 | fatal("Random pool path is too long"); | ||
76 | |||
77 | strcpy(addr.sun_path, RANDOM_POOL); | ||
78 | |||
79 | addr_len = offsetof(struct sockaddr_un, sun_path) + sizeof(RANDOM_POOL); | ||
80 | |||
81 | random_pool = socket(AF_UNIX, SOCK_STREAM, 0); | ||
82 | |||
83 | if (random_pool == -1) | ||
84 | fatal("Couldn't create AF_UNIX socket: %s", strerror(errno)); | ||
85 | |||
86 | if (connect(random_pool, (struct sockaddr*)&addr, addr_len) == -1) | ||
87 | fatal("Couldn't connect to EGD socket \"%s\": %s", addr.sun_path, strerror(errno)); | ||
88 | |||
89 | if (len > 255) | ||
90 | fatal("Too many bytes to read from EGD"); | ||
91 | |||
92 | /* Send blocking read request to EGD */ | ||
93 | egd_message[1] = len; | ||
94 | |||
95 | c = atomicio(write, random_pool, egd_message, sizeof(egd_message)); | ||
96 | if (c == -1) | ||
97 | fatal("Couldn't write to EGD socket \"%s\": %s", RANDOM_POOL, strerror(errno)); | ||
98 | |||
99 | c = atomicio(read, random_pool, buf, len); | ||
100 | if (c <= 0) | ||
101 | fatal("Couldn't read from random pool \"%s\": %s", RANDOM_POOL, strerror(errno)); | ||
102 | |||
103 | close(random_pool); | ||
104 | } | ||
105 | #else /* HAVE_EGD */ | ||
106 | |||
107 | /* Collect entropy from /dev/urandom or pipe */ | ||
108 | void get_random_bytes(unsigned char *buf, int len) | ||
109 | { | ||
110 | static int random_pool; | ||
111 | int c; | ||
112 | |||
113 | random_pool = open(RANDOM_POOL, O_RDONLY); | ||
114 | if (random_pool == -1) | ||
115 | fatal("Couldn't open random pool \"%s\": %s", RANDOM_POOL, strerror(errno)); | ||
116 | |||
117 | c = atomicio(read, random_pool, buf, len); | ||
118 | if (c <= 0) | ||
119 | fatal("Couldn't read from random pool \"%s\": %s", RANDOM_POOL, strerror(errno)); | ||
120 | |||
121 | close(random_pool); | ||
122 | } | ||
123 | |||
124 | #endif /* HAVE_EGD */ | ||
diff --git a/random.h b/random.h deleted file mode 100644 index 6eb9f3a94..000000000 --- a/random.h +++ /dev/null | |||
@@ -1,41 +0,0 @@ | |||
1 | /* | ||
2 | ** | ||
3 | ** Random number collection | ||
4 | ** | ||
5 | ** Damien Miller <djm@ibs.com.au> | ||
6 | ** | ||
7 | ** Copyright 1999 Damien Miller | ||
8 | ** | ||
9 | ** Permission is hereby granted, free of charge, to any person | ||
10 | ** obtaining a copy of this software and associated documentation | ||
11 | ** files (the "Software"), to deal in the Software without | ||
12 | ** restriction, including without limitation the rights to use, copy, | ||
13 | ** modify, merge, publish, distribute, sublicense, and/or sell copies | ||
14 | ** of the Software, and to permit persons to whom the Software is | ||
15 | ** furnished to do so, subject to the following conditions: | ||
16 | ** | ||
17 | ** The above copyright notice and this permission notice shall be | ||
18 | ** included in all copies or substantial portions of the Software. | ||
19 | ** | ||
20 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY | ||
21 | ** KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE | ||
22 | ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE | ||
23 | ** AND NONINFRINGEMENT. IN NO EVENT SHALL DAMIEN MILLER OR INTERNET | ||
24 | ** BUSINESS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
25 | ** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
26 | ** ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE | ||
27 | ** OR OTHER DEALINGS IN THE SOFTWARE. | ||
28 | ** | ||
29 | ** Except as contained in this notice, the name of Internet Business | ||
30 | ** Solutions shall not be used in advertising or otherwise to promote | ||
31 | ** the sale, use or other dealings in this Software without prior | ||
32 | ** written authorization from Internet Business Solutions. | ||
33 | ** | ||
34 | */ | ||
35 | |||
36 | #ifndef _RANDOM_H | ||
37 | #define _RANDOM_H | ||
38 | |||
39 | void get_random_bytes(unsigned char *buf, int len); | ||
40 | |||
41 | #endif /* _RANDOM_H */ | ||
@@ -35,28 +35,15 @@ | |||
35 | */ | 35 | */ |
36 | 36 | ||
37 | #include "includes.h" | 37 | #include "includes.h" |
38 | RCSID("$Id: rsa.c,v 1.11 2000/03/17 12:40:16 damien Exp $"); | 38 | RCSID("$Id: rsa.c,v 1.12 2000/04/03 04:50:46 damien Exp $"); |
39 | 39 | ||
40 | #include "rsa.h" | 40 | #include "rsa.h" |
41 | #include "ssh.h" | 41 | #include "ssh.h" |
42 | #include "xmalloc.h" | 42 | #include "xmalloc.h" |
43 | #include "random.h" | 43 | #include "entropy.h" |
44 | 44 | ||
45 | int rsa_verbose = 1; | 45 | int rsa_verbose = 1; |
46 | 46 | ||
47 | /* | ||
48 | * Seed OpenSSL's random number generator | ||
49 | */ | ||
50 | void | ||
51 | seed_rng() | ||
52 | { | ||
53 | char buf[64]; | ||
54 | |||
55 | get_random_bytes(buf, sizeof(buf)); | ||
56 | RAND_seed(buf, sizeof(buf)); | ||
57 | memset(buf, 0, sizeof(buf)); | ||
58 | } | ||
59 | |||
60 | int | 47 | int |
61 | rsa_alive() | 48 | rsa_alive() |
62 | { | 49 | { |
@@ -109,6 +96,8 @@ rsa_generate_key(RSA *prv, RSA *pub, unsigned int bits) | |||
109 | if (key == NULL) | 96 | if (key == NULL) |
110 | fatal("rsa_generate_key: key generation failed."); | 97 | fatal("rsa_generate_key: key generation failed."); |
111 | 98 | ||
99 | seed_rng(); | ||
100 | |||
112 | /* Copy public key parameters */ | 101 | /* Copy public key parameters */ |
113 | pub->n = BN_new(); | 102 | pub->n = BN_new(); |
114 | BN_copy(pub->n, key->n); | 103 | BN_copy(pub->n, key->n); |