Browse Source

improved mpass

master
mort 8 years ago
parent
commit
390c5305af
1 changed files with 43 additions and 12 deletions
  1. 43
    12
      bin/mpass

+ 43
- 12
bin/mpass View File

@@ -9,6 +9,28 @@ function cleanup
rm "$TMP_OUT" 2>&1 > /dev/null
}

function getpass
{
echo -n $(cat ~/.mpassword)
}

function tryerr
{
if [ "$?" != "0" ]; then
merror "An error occurred."
cleanup
exit 1
fi

if [ "$1" != "" ]; then
if [ "$1" != "0" ]; then
merror "An error occurred." "$1"
cleanup
exit 1
fi
fi
}

# Create password: mpass create <name> [chars]
if [ "$1" = "create" ]; then
if [ "$2" = "" ]; then
@@ -28,22 +50,20 @@ if [ "$1" = "create" ]; then
echo "$chars" > "$TMP_IN"
echo "$chars" | mclip

openssl enc -aes-256-cbc -salt -a -in "$TMP_IN" -out "$TMP_OUT" -pass "file:$HOME/.mpassword"
getpass | openssl enc -aes-256-cbc -a -in "$TMP_IN" -out "$TMP_OUT" -pass stdin
tryerr

enc=$(cat "$TMP_OUT")

passsum=$(shasum -a 512 < ~/.mpassword | cut -d ' ' -f 1)
passsum=$(getpass | shasum -a 512 | cut -d ' ' -f 1)

code=$(curl -s -X POST -d "$enc" "http://pass.mort.coffee/put/$2/$passsum")

if [ "$code" != "200" ]; then
echo "Error: $code"
cleanup
exit 1
fi
tryerr "$code"

echo "$chars"

mnotify "Password created" "$2"

# Get password: mpass get <name>
elif [ "$1" = "get" ]; then
if [ "$2" = "" ]; then
@@ -52,12 +72,23 @@ elif [ "$1" = "get" ]; then
exit 1
fi

curl -s "http://pass.mort.coffee/get/$2" > $TMP_IN
curl -s "http://pass.mort.coffee/get/$2" > "$TMP_IN"
tryerr
if [ ! -s "$TMP_IN" ]; then
tryerr "Pasword doesn't exist."
fi

echo -n "$enc" >> "$TMP_IN"

getpass | openssl enc -aes-256-cbc -a -d -in "$TMP_IN" -out "$TMP_OUT" -pass stdin
tryerr

openssl enc -aes-256-cbc -d -a -in "$TMP_IN" -out "$TMP_OUT" -pass "file:$HOME/.mpassword"
chars=$(cat "$TMP_OUT")

echo -n "$chars" | mclip
echo "$chars"

echo $(cat "$TMP_OUT") | mclip
echo $(cat "$TMP_OUT")
mnotify "Password received" "$2"
fi

cleanup

Loading…
Cancel
Save