Mercurial > prosody-modules
comparison mod_push2/mod_push2.lua @ 6523:c9836434a9d5
mod_push2: warn instead of crash on bad/empty key
| author | Stephen Paul Weber <singpolyma@singpolyma.net> |
|---|---|
| date | Tue, 28 Apr 2026 21:40:23 -0500 |
| parents | 0570f1e2edf4 |
| children |
comparison
equal
deleted
inserted
replaced
| 6522:c4d3f0c208e9 | 6523:c9836434a9d5 |
|---|---|
| 317 if match.jwt_alg ~= "HS256" then | 317 if match.jwt_alg ~= "HS256" then |
| 318 -- keypairs are in PKCS#8 PEM format without header/footer | 318 -- keypairs are in PKCS#8 PEM format without header/footer |
| 319 key = "-----BEGIN PRIVATE KEY-----\n"..key.."\n-----END PRIVATE KEY-----" | 319 key = "-----BEGIN PRIVATE KEY-----\n"..key.."\n-----END PRIVATE KEY-----" |
| 320 end | 320 end |
| 321 | 321 |
| 322 local public_key = crypto.import_private_pem(key):public_raw() | 322 local private_key = crypto.import_private_pem(key) |
| 323 if not private_key then | |
| 324 module:log("warn", "Bad key for %q", match) | |
| 325 return | |
| 326 end | |
| 327 | |
| 328 local public_key = private_key:public_raw() | |
| 323 local signer = jwt.new_signer(match.jwt_alg, key) | 329 local signer = jwt.new_signer(match.jwt_alg, key) |
| 324 local payload = {} | 330 local payload = {} |
| 325 for k, v in pairs(match.jwt_claims or {}) do | 331 for k, v in pairs(match.jwt_claims or {}) do |
| 326 payload[k] = v | 332 payload[k] = v |
| 327 end | 333 end |
