mirror of
https://github.com/aljazceru/gna.git
synced 2025-12-17 05:54:27 +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`
|
||||
2. run `gna` and follow instructions
|
||||
|
||||
## TODO:
|
||||
- [ ] store keys in secure env
|
||||
|
||||
# Sever
|
||||
## TODO:
|
||||
- [ ] 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'
|
||||
fi
|
||||
|
||||
HOOK=`cat <<'EOF'
|
||||
#!/bin/sh\n
|
||||
\n
|
||||
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
|
||||
if ! [ -x "$(command -v jq)" ]; then
|
||||
echo 'Error: jq is not installed.' >&2
|
||||
echo 'Please install jq from https://stedolan.github.io/jq/download/'
|
||||
fi
|
||||
|
||||
if [ -f $SK_PATH ]; then
|
||||
echo "$SK_PATH already exists. Skipping..."
|
||||
else
|
||||
echo "Please insert you NSEC:"
|
||||
read -s SK
|
||||
echo $(nak decode $SK) > $SK_PATH
|
||||
if ! [ -x "$(command -v pass)" ]; then
|
||||
echo 'Error: pass is not installed.' >&2
|
||||
echo 'Please install pass from https://www.passwordstore.org/'
|
||||
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
|
||||
GIT_REPO=${GIT_REPO:-.}
|
||||
|
||||
@@ -46,6 +32,22 @@ if [ ! -d "$GIT_REPO/.git" ]; then
|
||||
exit 1
|
||||
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..."
|
||||
if [ -f "$GIT_REPO/.git/hooks/pre-push" ]; then
|
||||
echo "pre-push hook already exists. Skipping..."
|
||||
@@ -56,4 +58,3 @@ else
|
||||
fi
|
||||
|
||||
echo "Done!"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user