mirror of
https://github.com/aljazceru/gna.git
synced 2025-12-17 14:04:19 +01:00
store private key in pass
Signed-off-by: dzdidi <deniszalessky@gmail.com>
This commit is contained in:
@@ -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`
|
||||||
|
|||||||
59
gna.sh
59
gna.sh
@@ -6,38 +6,24 @@ 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
|
|
||||||
commit=$(git rev-parse HEAD)\n
|
|
||||||
privKey=$(cat ~/.nostr/key | jq -r '.private_key')\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
|
|
||||||
`
|
|
||||||
|
|
||||||
|
|
||||||
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
|
if ! [ -x "$(command -v pass)" ]; then
|
||||||
echo "$SK_PATH already exists. Skipping..."
|
echo 'Error: pass is not installed.' >&2
|
||||||
else
|
echo 'Please install pass from https://www.passwordstore.org/'
|
||||||
echo "Please insert you NSEC:"
|
|
||||||
read -s SK
|
|
||||||
echo $(nak decode $SK) > $SK_PATH
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "Please insert you NSEC:"
|
||||||
|
read -s SK
|
||||||
|
DECODED=$(nak decode $SK)
|
||||||
|
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!"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user