summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJameson Graef Rollins <jrollins@finestructure.net>2009-03-23 14:41:07 -0400
committerJameson Graef Rollins <jrollins@finestructure.net>2009-03-23 14:41:07 -0400
commitfa172c0f2c97fb468277ce2e4ba2fab786c0759e (patch)
treea70f24d1178039c060e89a1abb5270b7677fc721 /src
parenta2761ab6c74d9794eb1650c8249ba8bcfc6f439a (diff)
proposed patch for issue #660, to properly specify host and port number in known_hosts lines.
Diffstat (limited to 'src')
-rw-r--r--src/share/common29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/share/common b/src/share/common
index ea872ba..5a11817 100644
--- a/src/share/common
+++ b/src/share/common
@@ -464,14 +464,19 @@ gpg2ssh() {
# output known_hosts line from ssh key
ssh2known_hosts() {
local host
+ local port
local key
- host="$1"
+ host=${1%%:*}
+ port=${1##*:}
key="$2"
- echo -n "$host "
- echo -n "$key" | tr -d '\n'
- echo " MonkeySphere${DATE}"
+ # specify the host and port properly for new ssh known_hosts
+ # format
+ if [ "$port" != "$host" ] ; then
+ host="[${host}]:${port}"
+ fi
+ printf "%s %s MonkeySphere%s\n" "$host" "$key" "$DATE"
}
# output authorized_keys line from ssh key
@@ -482,41 +487,43 @@ ssh2authorized_keys() {
userID="$1"
key="$2"
- echo -n "$key" | tr -d '\n'
- echo " MonkeySphere${DATE} ${userID}"
+ printf "%s MonkeySphere%s %s\n" "$key" "$DATE" "$userID"
}
# convert key from gpg to ssh known_hosts format
gpg2known_hosts() {
local host
local keyID
+ local key
host="$1"
keyID="$2"
+ key=$(gpg2ssh "$keyID")
+
# NOTE: it seems that ssh-keygen -R removes all comment fields from
# all lines in the known_hosts file. why?
# NOTE: just in case, the COMMENT can be matched with the
# following regexp:
# '^MonkeySphere[[:digit:]]{4}(-[[:digit:]]{2}){2}T[[:digit:]]{2}(:[[:digit:]]{2}){2}$'
- echo -n "$host "
- gpg2ssh "$keyID" | tr -d '\n'
- echo " MonkeySphere${DATE}"
+ printf "%s %s MonkeySphere%s\n" "$host" "$key" "$DATE"
}
# convert key from gpg to ssh authorized_keys format
gpg2authorized_keys() {
local userID
local keyID
+ local key
userID="$1"
keyID="$2"
+ key=$(gpg2ssh "$keyID")
+
# NOTE: just in case, the COMMENT can be matched with the
# following regexp:
# '^MonkeySphere[[:digit:]]{4}(-[[:digit:]]{2}){2}T[[:digit:]]{2}(:[[:digit:]]{2}){2}$'
- gpg2ssh "$keyID" | tr -d '\n'
- echo " MonkeySphere${DATE} ${userID}"
+ printf "%s MonkeySphere%s %s\n" "$key" "$DATE" "$userID"
}
### GPG UTILITIES