credentials: rename service -> account, 2fa,sfa -> mfa

This commit is contained in:
Lucas 2020-05-25 15:47:09 +00:00
parent aa6636e6a5
commit 82b8e95d7e

View File

@ -14,7 +14,7 @@ usage()
{ {
cat - <<. >&2 cat - <<. >&2
Usage: Usage:
${0##*/} [-2pu] service ${0##*/} [-mpu] account
. .
exit 1 exit 1
} }
@ -42,59 +42,55 @@ get_pass()
sekrit cp "$1/pass" && printf "\n" sekrit cp "$1/pass" && printf "\n"
} }
get_2fa() get_mfa()
{ {
printf 2fa printf mfa
otpcli_opts= otpcli_opts=
case $1 in case $1 in
isnic) otpcli_opts="-H sha512 -d 8" isnic) otpcli_opts="-H sha512 -d 8"
;; ;;
esac esac
sekrit get "$1/2fa" | otpcli $otpcli_opts | clip && printf "\n" sekrit get "$1/mfa" | otpcli $otpcli_opts | clip && printf "\n"
} }
get_service() get_account()
{ {
service=$1 account=$1
user=$2 user=$2
pass=$3 pass=$3
sfa=$4 mfa=$4
if [ $user = no ] && [ $pass = no ] && [ $sfa = no ]; then if [ $user = no ] && [ $pass = no ] && [ $mfa = no ]; then
sekrit has "$service/pass" || sekrit has "$account/pass" || err "unknown account $account"
err "unknown service $service"
pass=yes pass=yes
sekrit has "$service/user" && user=yes sekrit has "$account/user" && user=yes
sekrit has "$service/2fa" && sfa=yes sekrit has "$account/mfa" && mfa=yes
fi fi
if [ $user = check ]; then if [ $user = check ]; then
sekrit has "$service/user" || sekrit has "$account/user" || err "account $account has no user"
err "service $service has no user"
user=yes user=yes
fi fi
if [ $pass = check ]; then if [ $pass = check ]; then
sekrit has "$service/pass" || sekrit has "$account/pass" || err "account $account has no pass"
err "service $service has no pass"
pass=yes pass=yes
fi fi
if [ $sfa = check ]; then if [ $mfa = check ]; then
sekrit has "$service/2fa" || sekrit has "$account/mfa" || err "account $account has no MFA"
err "service $service has no 2fa" mfa=yes
sfa=yes
fi fi
[ $user = yes ] && get_user "$service" [ $user = yes ] && get_user "$account"
[ $pass = yes ] && get_pass "$service" [ $pass = yes ] && get_pass "$account"
[ $sfa = yes ] && get_2fa "$service" [ $mfa = yes ] && get_mfa "$account"
} }
sfa=no mfa=no
pass=no pass=no
user=no user=no
while getopts 2pu flag; do while getopts mpu flag; do
case $flag in case $flag in
2) sfa=check m) mfa=check
;; ;;
p) pass=check p) pass=check
;; ;;
@ -109,6 +105,6 @@ shift $((OPTIND - 1))
[ $# -eq 1 ] && [ -n "$1" ] || usage [ $# -eq 1 ] && [ -n "$1" ] || usage
key=$1 key=$1
: ${SEKRIT_DIR:=~/keep/sekrit/services} : ${SEKRIT_DIR:=~/keep/sekrit/accounts}
export SEKRIT_DIR export SEKRIT_DIR
get_account "$key" $user $pass $mfa get_account "$key" $user $pass $mfa