| 1 |
#! /bin/sh |
| 2 |
|
| 3 |
# A script for upgrading files under .lsh for lsh-2.0 |
| 4 |
|
| 5 |
# FIXME: Fix private keys as well, at least unencrypted keys like the |
| 6 |
# server host key. |
| 7 |
|
| 8 |
werror () { |
| 9 |
echo "$1" >&2 |
| 10 |
} |
| 11 |
|
| 12 |
die () { |
| 13 |
werror "$1" |
| 14 |
exit 1 |
| 15 |
} |
| 16 |
|
| 17 |
if [ $# -ne 0 ] ; then |
| 18 |
werror "Updates older lsh files to work with lsh-2.0" |
| 19 |
werror "" |
| 20 |
werror "Usage: lsh-upgrade" |
| 21 |
exit 1 |
| 22 |
fi |
| 23 |
|
| 24 |
: ${SEXP_CONV:=sexp-conv} |
| 25 |
|
| 26 |
cd "$HOME/.lsh" || die "No .lsh directory, so nothing to do." |
| 27 |
|
| 28 |
if [ -s host-acls ] ; then |
| 29 |
werror "~/.lsh/host-acls already exists, so I won't touch that." |
| 30 |
else |
| 31 |
if [ -s known_hosts ] ; then |
| 32 |
werror "Converting known_hosts to host-acls" |
| 33 |
# These are the changes we must make: |
| 34 |
# |
| 35 |
# * The subject of an acl must be enclosed in a subject-expression |
| 36 |
# |
| 37 |
# * Numbers are signed, so the most significant bit of all our |
| 38 |
# numbers must be 0. So we add a leading zero octet to numbers |
| 39 |
# that need it. |
| 40 |
|
| 41 |
"$SEXP_CONV" -s hex <known_hosts \ |
| 42 |
| sed -e 's,(entry ,(entry (subject ,' \ |
| 43 |
-e 's,(tag ,)(tag ,' \ |
| 44 |
-e 's,(\(.\) #\([89a-fA-F]\),(\1 #00\2,' \ |
| 45 |
| "$SEXP_CONV" >host-acls |
| 46 |
fi |
| 47 |
fi |
| 48 |
|
| 49 |
if [ -d authorized_keys_sha1 ]; then |
| 50 |
# Upgrade authorized keys |
| 51 |
werror "Upgrading any authorized keys" |
| 52 |
|
| 53 |
for p in authorized_keys_sha1/*; do |
| 54 |
# Upgrade the current key and store it temporary |
| 55 |
"$SEXP_CONV" -s hex < "$p" | \ |
| 56 |
sed -e 's,(\(.\) #\([89a-fA-F]\),(\1 #00\2,' > tmp_upgraded_auth_key && \ |
| 57 |
lsh-authorize tmp_upgraded_auth_key |
| 58 |
done |
| 59 |
|
| 60 |
rm tmp_upgraded_auth_key |
| 61 |
fi |