Browse Source

write out pem so pywebpush can use it, fixes push to chrome, fix private key write (trailing comma)

main
John-Mark Gurney 1 year ago
parent
commit
0a4617e927
3 changed files with 13 additions and 5 deletions
  1. +1
    -1
      Makefile
  2. +6
    -1
      S1_vapid.py
  3. +6
    -3
      pushnotify.sh

+ 1
- 1
Makefile View File

@@ -21,7 +21,7 @@ templates/S4_server.py: src/S4_server.py keys/private_key.txt
sed -e 's/your@email.com/$(EMAIL)/' -e 's/YOUR-PRIVATE-KEY/'"$$(cat keys/private_key.txt)"'/' < src/S4_server.py > templates/S4_server.py
# XXX - HOST_* and VAPID_SUBJECT

keys/public_key.txt keys/private_key.txt: venv S1_vapid.py
keys/public_key.txt keys/private_key.txt keys/private_key.pem: venv S1_vapid.py
( $(VENVACT) && python S1_vapid.py )

static/i-ico.png:


+ 6
- 1
S1_vapid.py View File

@@ -6,7 +6,7 @@ import ecdsa
# CREDITS : https://gist.github.com/cjies/cc014d55976db80f610cd94ccb2ab21e
pri = ecdsa.SigningKey.generate(curve=ecdsa.NIST256p)
pub = pri.get_verifying_key()
private = base64.urlsafe_b64encode(pri.to_string()).decode("utf-8").strip("="),
private = base64.urlsafe_b64encode(pri.to_string()).decode("utf-8").strip("=")
public = base64.urlsafe_b64encode(b"\x04" + pub.to_string()).decode("utf-8").strip("=")

import pathlib
@@ -19,3 +19,8 @@ with open(keydir / 'public_key.txt', 'w') as fp:

with open(keydir / 'private_key.txt', 'w') as fp:
print(private, file=fp)

with open(keydir / 'private_key.pem', 'wb') as fp:
#print(pri.to_pem(), file=fp)
# ecdsa is broken, to_pem returns bytes instead of a str
fp.write(pri.to_pem())

+ 6
- 3
pushnotify.sh View File

@@ -1,9 +1,11 @@
#!/bin/sh -

subinfo="$1"
privkey="$2"
claim="$3"

if ! [ -f "$1" ] || [ $# != 1 ]; then
echo "Usage: $0 <subinfo>"
if ! [ -f "$1" ] || [ $# != 1 -a $# != 3 ]; then
echo "Usage: $0 <subinfo> [ <pemprivkey> <claimtxt> ]"
exit 1
fi

@@ -13,6 +15,7 @@ cat - > "$tmpfname"
title=$(grep -i "^Subject:" "$tmpfname" | sed -e 's/.*:[ ]*//')

jq --rawfile msg "$tmpfname" --arg title "$title" -n '{ "title": $title, "body": $msg, "icon" : "static/i-ico.png", "image" : "static/i-banner.png" }' |
pywebpush -v --data /dev/stdin --info "$subinfo"
pywebpush -v --data /dev/stdin --info "$subinfo" \
--key "${privkey}" --claims "${claim}"

rm "$tmpfname"

Loading…
Cancel
Save