store private key in pass

Signed-off-by: dzdidi <deniszalessky@gmail.com>
This commit is contained in:
dzdidi
2024-01-22 12:57:31 +00:00
parent 4b0b82b5e7
commit 4de1033f64
2 changed files with 30 additions and 32 deletions

View File

@@ -5,9 +5,6 @@ Requires [nak](https://github.com/fiatjaf/nak/tree/master)
1. add `./gna` to you `$PATH` 1. add `./gna` to you `$PATH`
2. run `gna` and follow instructions 2. run `gna` and follow instructions
## TODO:
- [ ] store keys in secure env
# Sever # Sever
## TODO: ## TODO:
- [ ] inteceptor of `X-Authorization` - [ ] inteceptor of `X-Authorization`

57
gna.sh
View File

@@ -6,37 +6,23 @@ if ! [ -x "$(command -v nak)" ]; then
echo 'Please install nak from https://github.com/fiatjaf/nak/tree/master' echo 'Please install nak from https://github.com/fiatjaf/nak/tree/master'
fi fi
HOOK=`cat <<'EOF' if ! [ -x "$(command -v jq)" ]; then
#!/bin/sh\n echo 'Error: jq is not installed.' >&2
\n echo 'Please install jq from https://stedolan.github.io/jq/download/'
url="$2"\n fi
commit=$(git rev-parse HEAD)\n
privKey=$(cat ~/.nostr/key | jq -r '.private_key')\n if ! [ -x "$(command -v pass)" ]; then
EVENT="{\"content\":\"\",\"kind\":27235,\"created_at\":$(date +%s),\"tags\":[[\"u\",\"$url\"],[\"method\",\"push\"],[\"payload\",\"$commit\"]]}"\n echo 'Error: pass is not installed.' >&2
SIGNED=$(echo -n $EVENT | nak event -sec $privKey)\n echo 'Please install pass from https://www.passwordstore.org/'
NOSTR_AUTH_HEADER=$(echo -n $SIGNED | base64 -w 0)\n
git config http.$url.extraHeader "X-Authorization: Nostr $NOSTR_AUTH_HEADER"\n
EOF
`
APP_HOME="$HOME/.nostr"
SK_PATH="$APP_HOME/key"
if [ -d $APP_HOME ]; then
echo "$APP_HOME already exists. Skipping..."
else
echo "Creating $APP_HOME"
mkdir $APP_HOME
fi fi
if [ -f $SK_PATH ]; then
echo "$SK_PATH already exists. Skipping..."
else
echo "Please insert you NSEC:" echo "Please insert you NSEC:"
read -s SK read -s SK
echo $(nak decode $SK) > $SK_PATH DECODED=$(nak decode $SK)
fi PUBLIC_KEY=$(echo $DECODED | jq -r .pubkey)
PRIVATE_KEY=$(echo $DECODED | jq -r .private_key)
PASS_PATH="nostr/$PUBLIC_KEY"
{ echo $PRIVATE_KEY ; echo $PRIVATE_KEY ; } | pass insert $PASS_PATH
read -p "Provide path to git repository or press \"Enter\" to use curent directory:" GIT_REPO read -p "Provide path to git repository or press \"Enter\" to use curent directory:" GIT_REPO
GIT_REPO=${GIT_REPO:-.} GIT_REPO=${GIT_REPO:-.}
@@ -46,6 +32,22 @@ if [ ! -d "$GIT_REPO/.git" ]; then
exit 1 exit 1
fi fi
HOOK=`cat <<'EOF'
#!/bin/sh\n
\n
url="$2"\n
commit=$(git rev-parse HEAD)\n
privKey=$(pass PASS_PATH)\n
EVENT="{\"content\":\"\",\"kind\":27235,\"created_at\":$(date +%s),\"tags\":[[\"u\",\"$url\"],[\"method\",\"push\"],[\"payload\",\"$commit\"]]}"\n
SIGNED=$(echo -n $EVENT | nak event -sec $privKey)\n
NOSTR_AUTH_HEADER=$(echo -n $SIGNED | base64 -w 0)\n
git config http.$url.extraHeader "X-Authorization: Nostr $NOSTR_AUTH_HEADER"\n
EOF
`
PASS_PATH=$(sed 's/\//\\\//g' <<< "$PASS_PATH")
PATTERN="s/PASS_PATH/$PASS_PATH/g"
HOOK=$(sed "$PATTERN" <<< "$HOOK")
echo "Installing git hooks..." echo "Installing git hooks..."
if [ -f "$GIT_REPO/.git/hooks/pre-push" ]; then if [ -f "$GIT_REPO/.git/hooks/pre-push" ]; then
echo "pre-push hook already exists. Skipping..." echo "pre-push hook already exists. Skipping..."
@@ -56,4 +58,3 @@ else
fi fi
echo "Done!" echo "Done!"