From 7d9efa71b5eeb95d7e850d53ba2684087fe7e671 Mon Sep 17 00:00:00 2001 From: ducklol2 <140205571+ducklol2@users.noreply.github.com> Date: Fri, 7 Feb 2025 13:26:42 +0100 Subject: [PATCH] Remove padding = from openssl base64 public key When I attempt to register/subscribe to web push notifications, and the base64 public key contains padding (one or two `=` terminal characters) browsers yield these errors: - Chrome 132: "_InvalidCharacterError: Failed to execute 'subscribe' on 'PushManager': The provided applicationServerKey is not encoded as base64url without padding._" - Firefox 134: "_DOMException: String contains an invalid character_" Simply deleting these seems to work for me, so this change adds `=` to the `tr` deleted character set in the public key `openssl` command. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index eb64b6eb..86950405 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ openssl ecparam -genkey -name prime256v1 -out private_key.pem To derive a public key from the just-generated private key, to be used in the JavaScript client: ``` -openssl ec -in private_key.pem -pubout -outform DER|tail -c 65|base64|tr '/+' '_-'|tr -d '\n' +openssl ec -in private_key.pem -pubout -outform DER|tail -c 65|base64|tr '/+' '_-'|tr -d '\n=' ``` The signature is created with `VapidSignatureBuilder`. It automatically adds the required claims `aud` and `exp`. Adding