1 |
# $Header: /home/cvsd/alx-cvs/alx-src/tinyalxconfig-ng/functions/config_ssh_auth.sh,v 1.1 2008-06-04 16:47:56 niro Exp $ |
# $Header: /home/cvsd/alx-cvs/alx-src/tinyalxconfig-ng/functions/config_ssh_auth.sh,v 1.2 2008-06-04 17:13:19 niro Exp $ |
2 |
# exchanges the public server and client ssh keys |
# exchanges the public server and client ssh keys |
3 |
|
|
4 |
gen_keys() |
gen_keys() |
5 |
{ |
{ |
6 |
if [ ! -e /etc/ssh/ssh_host_key ] |
if [ ! -e /etc/dropbear/dropbear_dss_host_key ] |
7 |
then |
then |
8 |
echo -e ${COLOREDSTAR}"Generating SSH-Hostkey ..." |
echo -e ${COLOREDSTAR}"Generating DSS-Hostkey ..." |
9 |
/usr/bin/ssh-keygen -t rsa1 -b 1024 -f /etc/ssh/ssh_host_key -N '' |
/usr/bin/dropbearkey -t dss -f /etc/dropbear/dropbear_dss_host_key |
10 |
fi |
fi |
11 |
|
|
12 |
if [ ! -e /etc/ssh/ssh_host_dsa_key ] |
if [ ! -e /etc/dropbear/dropbear_rsa_host_key ] |
13 |
then |
then |
14 |
echo -e ${COLREDSTAR}"Generating DSA-Hostkey ..." |
echo -e ${COLOREDSTAR}"Generating RSA-Hostkey ..." |
15 |
/usr/bin/ssh-keygen -d -f /etc/ssh/ssh_host_dsa_key -N '' |
/usr/bin/dropbearkey -t rsa -f /etc/dropbear/dropbear_rsa_host_key |
16 |
fi |
fi |
17 |
|
|
18 |
if [ ! -e /etc/ssh/ssh_host_rsa_key ] |
if [ ! -e /etc/dropbear/dropbear_rsa_host_key.pub ] |
19 |
then |
then |
20 |
echo -e ${COLOREDSTAR}"Generating RSA-Hostkey ..." |
echo -e ${COLOREDSTAR}"Generating Public RSA-Hostkey ..." |
21 |
/usr/bin/ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N '' |
# note: the key is stored in the second line of the output |
22 |
|
/usr/bin/dropbearkey -y -f /etc/dropbear/dropbear_rsa_host_key | sed -n '2p' \ |
23 |
|
> /etc/dropbear/dropbear_rsa_host_key.pub |
24 |
fi |
fi |
25 |
} |
} |
26 |
|
|
35 |
# write the public key of the server to the host system |
# write the public key of the server to the host system |
36 |
PUB_KEY_SERVER="$(mysqldo "select public_key from ssh_auth_server where id=1;")" |
PUB_KEY_SERVER="$(mysqldo "select public_key from ssh_auth_server where id=1;")" |
37 |
|
|
38 |
if [ -n "${PUB_KEY_SERVER}" ] |
if [[ -n ${PUB_KEY_SERVER} ]] |
39 |
then |
then |
40 |
HOME=/root |
HOME=/root |
41 |
# only if not empty |
# only if not empty |
46 |
# put the public key of the host into the db |
# put the public key of the host into the db |
47 |
ID=$(mysqldo "select serial from ssh_auth_clients where serial=${ALX_SERIAL};") |
ID=$(mysqldo "select serial from ssh_auth_clients where serial=${ALX_SERIAL};") |
48 |
|
|
49 |
if [ -n "${ID}" ] |
if [[ -n ${ID} ]] |
50 |
then |
then |
51 |
# run an update |
# run an update |
52 |
mysqldo "update ssh_auth_clients set public_key='$(< /etc/ssh/ssh_host_rsa_key.pub)' where serial=${ALX_SERIAL};" |
mysqldo "update ssh_auth_clients set public_key='$(< /etc/dropbear/dropbear_rsa_host_key.pub)' where serial=${ALX_SERIAL};" |
53 |
else |
else |
54 |
# run an insert |
# run an insert |
55 |
mysqldo "insert into ssh_auth_clients(serial,public_key) values('${ALX_SERIAL}','$(< /etc/ssh/ssh_host_rsa_key.pub)')" |
mysqldo "insert into ssh_auth_clients(serial,public_key) values('${ALX_SERIAL}','$(< /etc/ssh/ssh_host_rsa_key.pub)')" |