@@ -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 | 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 | # 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 ) | ( $(VENVACT) && python S1_vapid.py ) | ||||
static/i-ico.png: | static/i-ico.png: | ||||
@@ -6,7 +6,7 @@ import ecdsa | |||||
# CREDITS : https://gist.github.com/cjies/cc014d55976db80f610cd94ccb2ab21e | # CREDITS : https://gist.github.com/cjies/cc014d55976db80f610cd94ccb2ab21e | ||||
pri = ecdsa.SigningKey.generate(curve=ecdsa.NIST256p) | pri = ecdsa.SigningKey.generate(curve=ecdsa.NIST256p) | ||||
pub = pri.get_verifying_key() | 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("=") | public = base64.urlsafe_b64encode(b"\x04" + pub.to_string()).decode("utf-8").strip("=") | ||||
import pathlib | import pathlib | ||||
@@ -19,3 +19,8 @@ with open(keydir / 'public_key.txt', 'w') as fp: | |||||
with open(keydir / 'private_key.txt', 'w') as fp: | with open(keydir / 'private_key.txt', 'w') as fp: | ||||
print(private, file=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()) |
@@ -1,9 +1,11 @@ | |||||
#!/bin/sh - | #!/bin/sh - | ||||
subinfo="$1" | 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 | exit 1 | ||||
fi | fi | ||||
@@ -13,6 +15,7 @@ cat - > "$tmpfname" | |||||
title=$(grep -i "^Subject:" "$tmpfname" | sed -e 's/.*:[ ]*//') | 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" }' | | 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" | rm "$tmpfname" |