comparison mod_push2/mod_push2.lua @ 5663:a1d22d6efb3d

mod_push2: Need to include the public key with the JWT
author Stephen Paul Weber <singpolyma@singpolyma.net>
date Wed, 20 Sep 2023 23:05:29 -0500
parents bebb10fa5787
children 4b052598e435
comparison
equal deleted inserted replaced
5662:81f1c617f4c7 5663:a1d22d6efb3d
283 if match.jwt_alg ~= "HS256" then 283 if match.jwt_alg ~= "HS256" then
284 -- keypairs are in PKCS#8 PEM format without header/footer 284 -- keypairs are in PKCS#8 PEM format without header/footer
285 key = "-----BEGIN PRIVATE KEY-----\n"..key.."\n-----END PRIVATE KEY-----" 285 key = "-----BEGIN PRIVATE KEY-----\n"..key.."\n-----END PRIVATE KEY-----"
286 end 286 end
287 287
288 local public_key = pkey.new(key):getParameters().pub_key:toBinary()
288 local signer = jwt.new_signer(match.jwt_alg, key) 289 local signer = jwt.new_signer(match.jwt_alg, key)
289 local payload = {} 290 local payload = {}
290 for k, v in pairs(match.jwt_claims or {}) do 291 for k, v in pairs(match.jwt_claims or {}) do
291 payload[k] = v 292 payload[k] = v
292 end 293 end
293 payload.sub = contact_uri 294 payload.sub = contact_uri
294 push_notification_payload:text_tag("jwt", signer(payload)) 295 push_notification_payload:text_tag("jwt", signer(payload), { key = base64.encode(public_key) })
295 end 296 end
296 297
297 local function handle_notify_request(stanza, node, user_push_services, log_push_decline) 298 local function handle_notify_request(stanza, node, user_push_services, log_push_decline)
298 local pushes = 0; 299 local pushes = 0;
299 if not #user_push_services then return pushes end 300 if not #user_push_services then return pushes end