From 355be4b75a4e5f9dc0e6c278677a0f77793fc178 Mon Sep 17 00:00:00 2001 From: Stephan Bodmer Date: Thu, 14 Apr 2022 13:11:59 +0200 Subject: [PATCH] Fixed the google webpush backend not supporting base64 padding in encoded keys (vapid) --- .../nl/martijndwars/webpush/AbstractPushService.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/nl/martijndwars/webpush/AbstractPushService.java b/src/main/java/nl/martijndwars/webpush/AbstractPushService.java index 22db83b..c59ab21 100644 --- a/src/main/java/nl/martijndwars/webpush/AbstractPushService.java +++ b/src/main/java/nl/martijndwars/webpush/AbstractPushService.java @@ -207,11 +207,16 @@ protected final HttpRequest prepareRequest(Notification notification, Encoding e headers.put("Authorization", "WebPush " + jws.getCompactSerialization()); } + //--- Remove padding as spec + //--- https://datatracker.ietf.org/doc/html/draft-ietf-webpush-vapid-01#section-4 + String b64 = Base64.getUrlEncoder().encodeToString(pk); + if (b64.endsWith("=")) b64 = b64.substring(0, b64.length()-1); if (headers.containsKey("Crypto-Key")) { - headers.put("Crypto-Key", headers.get("Crypto-Key") + ";p256ecdsa=" + Base64.getUrlEncoder().encodeToString(pk)); + headers.put("Crypto-Key", headers.get("Crypto-Key") + ";p256ecdsa=" + b64); } else { - headers.put("Crypto-Key", "p256ecdsa=" + Base64.getUrlEncoder().encodeToString(pk)); + headers.put("Crypto-Key", "p256ecdsa=" + b64); } + } else if (notification.isFcm() && getGcmApiKey() != null) { headers.put("Authorization", "key=" + getGcmApiKey()); }