| 1 |
adx |
30 |
#!/bin/sh |
| 2 |
knight |
31 |
# $Id$ |
| 3 |
adx |
30 |
# |
| 4 |
|
|
# mkkeypair - short shell script to generate a OpenSSL RSA key suitable |
| 5 |
|
|
# for use with cryptlinks. |
| 6 |
|
|
# |
| 7 |
|
|
# (C) 2003 Joshua Kwan and the IRCD-Hybrid team |
| 8 |
|
|
# See LICENSE for the terms of copying. |
| 9 |
|
|
|
| 10 |
|
|
if test -f rsa.key; then |
| 11 |
|
|
echo Moving old key out of the way to rsa.key.old |
| 12 |
|
|
mv rsa.key rsa.key.old |
| 13 |
|
|
fi |
| 14 |
|
|
|
| 15 |
|
|
if test -f rsa.pub; then |
| 16 |
|
|
echo Moving old public key out of the way to rsa.pub.old |
| 17 |
|
|
mv rsa.pub rsa.pub.old |
| 18 |
|
|
fi |
| 19 |
|
|
|
| 20 |
|
|
echo Generating random bytes |
| 21 |
|
|
|
| 22 |
|
|
if test -c /dev/urandom; then |
| 23 |
|
|
RANDGEN=/dev/urandom |
| 24 |
|
|
elif test -c /dev/random; then |
| 25 |
|
|
RANDGEN=/dev/random |
| 26 |
|
|
else |
| 27 |
|
|
RANDGEN=input |
| 28 |
|
|
fi |
| 29 |
|
|
|
| 30 |
|
|
if test "$RANDGEN" = input; then |
| 31 |
|
|
echo "Your system doesn't have a suitable random data generator," |
| 32 |
|
|
echo "so type 150 characters of gibberish here to simulate it." |
| 33 |
|
|
read -n 150 randomdata |
| 34 |
|
|
echo |
| 35 |
|
|
echo "$randomdata" > randdata |
| 36 |
|
|
sort < randdata >> randdata.1 |
| 37 |
|
|
cat randdata.1 >> randdata |
| 38 |
|
|
rm -f randdata.1 |
| 39 |
|
|
else |
| 40 |
|
|
dd if=$RANDGEN of=randdata count=1 bs=2048 |
| 41 |
|
|
fi |
| 42 |
|
|
|
| 43 |
|
|
echo Creating the private key. |
| 44 |
|
|
openssl genrsa -rand randdata -out rsa.key 2048 || exit 1 |
| 45 |
|
|
chmod 600 rsa.key |
| 46 |
|
|
echo Creating the public key from the private key. |
| 47 |
|
|
openssl rsa -in rsa.key -out rsa.pub -pubout || exit 1 |
| 48 |
|
|
chmod 644 rsa.pub |
| 49 |
|
|
|
| 50 |
|
|
echo |
| 51 |
|
|
echo Private key now exists as rsa.key |
| 52 |
|
|
echo Public key now exists as rsa.pub |
| 53 |
|
|
|
| 54 |
|
|
rm -f randdata |