mirror of
https://github.com/5im-0n/sshenc.sh.git
synced 2025-08-02 11:20:05 +02:00
add support to automatically pull ssh keys from github handles
This commit is contained in:
32
sshenc.sh
32
sshenc.sh
@@ -6,7 +6,7 @@ me=sshenc.sh
|
|||||||
|
|
||||||
show_help() {
|
show_help() {
|
||||||
cat << EOF
|
cat << EOF
|
||||||
usage: $me [-p <public ssh key> | -s <private ssh key>] [-h]
|
usage: $me [[-p <public ssh key> | -g <github handle>]| -s <private ssh key>] [-h]
|
||||||
|
|
||||||
examples:
|
examples:
|
||||||
- encrypt a file
|
- encrypt a file
|
||||||
@@ -15,6 +15,9 @@ examples:
|
|||||||
- decrypt a file
|
- decrypt a file
|
||||||
$me -s ~/.ssh/id_rsa < encrypted.txt
|
$me -s ~/.ssh/id_rsa < encrypted.txt
|
||||||
|
|
||||||
|
- encrypt a file to a GitHub user (requires curl and bash 4)
|
||||||
|
$me -g foo < plain-text-file.txt > encrypted.txt
|
||||||
|
|
||||||
$me home page: https://sshenc.sh/
|
$me home page: https://sshenc.sh/
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
@@ -23,7 +26,7 @@ cleanup() {
|
|||||||
rm -rf "$temp_dir"
|
rm -rf "$temp_dir"
|
||||||
}
|
}
|
||||||
|
|
||||||
while getopts "h?p:s:" opt; do
|
while getopts "h?p:s:g:" opt; do
|
||||||
case "$opt" in
|
case "$opt" in
|
||||||
h|\?)
|
h|\?)
|
||||||
show_help
|
show_help
|
||||||
@@ -33,6 +36,7 @@ while getopts "h?p:s:" opt; do
|
|||||||
;;
|
;;
|
||||||
s) private_key=$OPTARG
|
s) private_key=$OPTARG
|
||||||
;;
|
;;
|
||||||
|
g) github_handle+=("$OPTARG")
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
@@ -45,6 +49,30 @@ temp_file_key="$(mktemp "$temp_dir/$me.XXXXXX.key")"
|
|||||||
temp_file="$(mktemp "$temp_dir/$me.XXXXXX.cypher")"
|
temp_file="$(mktemp "$temp_dir/$me.XXXXXX.cypher")"
|
||||||
trap cleanup EXIT
|
trap cleanup EXIT
|
||||||
|
|
||||||
|
# retrieve ssh keys from github
|
||||||
|
OLDMASK=$(umask)
|
||||||
|
umask 0266
|
||||||
|
if [[ "${#github_handle[@]}" -gt 0 ]]; then
|
||||||
|
for handle in "${github_handle[@]}"
|
||||||
|
do
|
||||||
|
curl -s "https://github.com/$handle.keys" | grep ssh-rsa > "$temp_dir/$handle"
|
||||||
|
if [ -s "$temp_dir/$handle" ]; then
|
||||||
|
# dont do this with big files
|
||||||
|
mapfile -t handle_keys < "$temp_dir/$handle"
|
||||||
|
for key in "${!handle_keys[@]}"
|
||||||
|
do
|
||||||
|
echo "${handle_keys[key]}"
|
||||||
|
printf "%s" "${handle_keys[key]}" > "$temp_dir/$handle.$key"
|
||||||
|
echo "$temp_dir/$handle.$key"
|
||||||
|
public_key+=("$temp_dir/$handle.$key")
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
umask "$OLDMASK"
|
||||||
|
|
||||||
#encrypt
|
#encrypt
|
||||||
if [[ "${#public_key[@]}" > 0 ]]; then
|
if [[ "${#public_key[@]}" > 0 ]]; then
|
||||||
openssl rand 32 > $temp_file_key
|
openssl rand 32 > $temp_file_key
|
||||||
|
Reference in New Issue
Block a user