Update for OpenSSL-1.0.0c.
[dragonfly.git] / secure / lib / libssh / generate-blacklist.sh
1 #!/bin/bash
2 # $DragonFly: src/secure/lib/libssh/generate-blacklist.sh,v 1.1 2008/05/21 14:07:41 corecode Exp $
3 set -e
4
5 LIBSSL=$(apt-cache policy libssl0.9.8 | grep Installed | awk '{print $NF}')
6 dpkg --compare-versions "$LIBSSL" lt 0.9.8g-9 || {
7     echo "Your libssl0.9.8 is newer than the fixed version (0.9.8g-9)." >&2
8     echo "This script is only sensible to run with a broken version.  :)" >&2
9     exit 1
10 }
11
12 KEYTYPE=$(echo "$1" | tr A-Z a-z)
13 KEYSIZE="$2"
14 if [ -z "$KEYTYPE" ] || [ -z "$KEYSIZE" ]; then
15     echo "Usage: $0 KEYTYPE KEYSIZE" >&2
16     exit 1
17 fi
18
19 WORKDIR=$(mktemp -d -t blacklist-XXXXXX)
20 cd "$WORKDIR"
21
22 cat >getpid.c <<EOM
23 /*
24  * Compile:
25
26 gcc -fPIC -c getpid.c -o getpid.o
27 gcc -shared -o getpid.so getpid.o
28
29  * Use:
30  
31 FORCE_PID=1234 LD_PRELOAD=./getpid.so bash
32
33 #
34 # Copyright (C) 2001-2008 Kees Cook
35 # kees@outflux.net, http://outflux.net/
36
37 # This program is free software; you can redistribute it and/or
38 # modify it under the terms of the GNU General Public License
39 # as published by the Free Software Foundation; either version 2
40 # of the License, or (at your option) any later version.
41
42 # This program is distributed in the hope that it will be useful,
43 # but WITHOUT ANY WARRANTY; without even the implied warranty of
44 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
45 # GNU General Public License for more details.
46
47 # You should have received a copy of the GNU General Public License
48 # along with this program; if not, write to the Free Software
49 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
50 # http://www.gnu.org/copyleft/gpl.html
51
52 */
53
54 #include <sys/types.h>
55 #include <unistd.h>
56 #include <stdlib.h>
57
58 pid_t getpid(void)
59 {
60     return atoi(getenv("FORCE_PID"));
61 }
62 EOM
63
64 gcc -fPIC -c getpid.c -o getpid.o
65 gcc -shared -o getpid.so getpid.o
66
67 echo "# generated on $(uname -m) at $(date)"
68
69 for pid in $(seq 1 32767)
70 do
71     FILE="key-$pid"
72     HASH=$(FORCE_PID="$pid" LD_PRELOAD=./getpid.so \
73         ssh-keygen -P "" -t "$KEYTYPE" -b "$KEYSIZE" -f "$FILE" | \
74             grep :..: | cut -d" " -f1 | sed -e 's/://g')
75     rm -f "$FILE" "$FILE".pub
76     echo "$HASH"
77 done
78
79 rm -f getpid.*
80 cd /
81 rmdir "$WORKDIR"