Skip to content

Commit

Permalink
feat: add --pass option
Browse files Browse the repository at this point in the history
  • Loading branch information
DakEnviy committed Apr 20, 2022
1 parent 9c876b1 commit 691bffc
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions sshp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,36 @@ list_creds() {
done | column -t
}

get_pass() {
creds_name="$1"

meta_filepath="$HOME/.ssh/meta/$creds_name"

if [[ ! -f "$meta_filepath" ]]; then
echo "Credentials $creds_name is not exist" >&2
exit 1
fi

meta=$(cat "$meta_filepath")
passenc=$(echo "$meta" | cut -d ' ' -f 2)

tries=0

while :; do
read -sp "$creds_name's passphrase: " passphrase && echo
pass=$(echo "$passenc" | openssl enc -d "${OPENSSL_ENC_FLAGS[@]}" -pass "pass:$passphrase" 2>&1)
(( ++tries ))

[[ "$pass" != *"bad decrypt"* ]] && break

echo 'Permission denied, please try again.' >&2
[[ $tries -ge 3 ]] && exit 1
done

echo -n "$pass" | xclip -selection clipboard && \
echo 'Password was copied to clipboard'
}

connect() {
clipoff=0

Expand All @@ -100,6 +130,7 @@ connect() {
fi

creds_name="$1"

meta_filepath="$HOME/.ssh/meta/$creds_name"

if [[ -z "$creds_name" || ! -f "$meta_filepath" ]]; then
Expand Down Expand Up @@ -160,6 +191,10 @@ case "$1" in
--list)
list_creds
;;
--pass)
shift
get_pass "$@"
;;
*)
connect "$@"
;;
Expand Down

0 comments on commit 691bffc

Please sign in to comment.