Skip to content
This repository was archived by the owner on Feb 17, 2023. It is now read-only.

Commit 71ab0de

Browse files
committed
Merge pull request #79 from andsens/ecdsa-fix
Shred ECDSA keys when bootstrapping, regenerate at 1st boot
2 parents 96ee7dd + a3980a3 commit 71ab0de

File tree

7 files changed

+56
-8
lines changed

7 files changed

+56
-8
lines changed
File renamed without changes.

init.d/wheezy/generate-ssh-hostkeys

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/sh
2+
### BEGIN INIT INFO
3+
# Provides: generate-ssh-hostkeys
4+
# Required-Start: $local_fs
5+
# Required-Stop:
6+
# Should-Start:
7+
# Should-Stop:
8+
# Default-Start: S
9+
# Default-Stop:
10+
# Description: Generate ssh host keys if they do not exist
11+
### END INIT INFO
12+
13+
prog=$(basename $0)
14+
logger="logger -t $prog"
15+
16+
rsa_key="/etc/ssh/ssh_host_rsa_key"
17+
dsa_key="/etc/ssh/ssh_host_dsa_key"
18+
ecdsa_key="/etc/ssh/ssh_host_ecdsa_key"
19+
20+
# Exit if the hostkeys already exist
21+
if [ -f $rsa_key -a -f $dsa_key -a -f $ecdsa_key ]; then
22+
exit
23+
fi
24+
25+
# Generate the ssh host keys
26+
[ -f $rsa_key ] || ssh-keygen -f $rsa_key -t rsa -C 'host' -N ''
27+
[ -f $dsa_key ] || ssh-keygen -f $dsa_key -t dsa -C 'host' -N ''
28+
[ -f $ecdsa_key ] || ssh-keygen -f $ecdsa_key -t ecdsa -C 'host' -N ''
29+
30+
# Output the public keys to the console
31+
# This allows user to get host keys securely through console log
32+
echo "-----BEGIN SSH HOST KEY FINGERPRINTS-----" | $logger
33+
ssh-keygen -l -f $rsa_key.pub | $logger
34+
ssh-keygen -l -f $dsa_key.pub | $logger
35+
ssh-keygen -l -f $ecdsa_key.pub | $logger
36+
echo "------END SSH HOST KEY FINGERPRINTS------" | $logger

tasks/60-cleanup

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
#!/bin/bash
22
# Clean up the image
33

4-
# Remove the ssh host keys, they need to be shredded
5-
shred --remove \
6-
$imagedir/etc/ssh/ssh_host_dsa_key \
7-
$imagedir/etc/ssh/ssh_host_dsa_key.pub \
8-
$imagedir/etc/ssh/ssh_host_rsa_key \
9-
$imagedir/etc/ssh/ssh_host_rsa_key.pub
10-
114
# We do the same to the bash history, there shouldn't be anything sensitive in there,
125
# it's just in case plugins need to execute commands that have credentials in their parameters.
136
# In fact: The standard bootstrapping process does not even create it.

tasks/squeeze/50-add-init-scripts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
# Add standard startup scripts to the init_scripts list
3+
init_scripts+=("$scriptdir/init.d/squeeze/generate-ssh-hostkeys")

tasks/squeeze/62-delete-host-keys

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
# Remove the ssh host keys, they need to be shredded
3+
shred --remove \
4+
$imagedir/etc/ssh/ssh_host_dsa_key \
5+
$imagedir/etc/ssh/ssh_host_dsa_key.pub \
6+
$imagedir/etc/ssh/ssh_host_rsa_key \
7+
$imagedir/etc/ssh/ssh_host_rsa_key.pub
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/bash
22
# Add standard startup scripts to the init_scripts list
3-
init_scripts+=("$scriptdir/init.d/generate-ssh-hostkeys")
3+
init_scripts+=("$scriptdir/init.d/wheezy/generate-ssh-hostkeys")

tasks/wheezy/62-delete-host-keys

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
# Remove the ssh host keys, they need to be shredded
3+
shred --remove \
4+
$imagedir/etc/ssh/ssh_host_dsa_key \
5+
$imagedir/etc/ssh/ssh_host_dsa_key.pub \
6+
$imagedir/etc/ssh/ssh_host_rsa_key \
7+
$imagedir/etc/ssh/ssh_host_rsa_key.pub \
8+
$imagedir/etc/ssh/ssh_host_ecdsa_key \
9+
$imagedir/etc/ssh/ssh_host_ecdsa_key.pub

0 commit comments

Comments
 (0)