~ubuntu-branches/ubuntu/karmic/openssh-blacklist/karmic

« back to all changes in this revision

Viewing changes to generate-blacklist.sh

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2008-05-29 09:37:50 UTC
  • mfrom: (0.1.2 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080529093750-xvvhfshtxjapejir
Tags: 0.4.1
debian/openssh-blacklist{,-extra}.preinst: Correctly clean up old
/etc/ssh blacklist entries (Closes: 483549).

Show diffs side-by-side

added added

removed removed

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