Skip to content

Commit 026a043

Browse files
committed
vapid: Handle ECPrivateKey extra element
1 parent d64db32 commit 026a043

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/web_push_encryption/vapid.ex

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@ defmodule WebPushEncryption.Vapid do
1919
}
2020
|> JOSE.JWT.from_map()
2121

22+
otp_version = :erlang.system_info(:otp_release) |> String.Chars.to_string() |> String.to_integer
23+
2224
jwk =
23-
{:ECPrivateKey, 1, private_key, {:namedCurve, {1, 2, 840, 10045, 3, 1, 7}}, public_key}
25+
if otp_version < 24 do
26+
{:ECPrivateKey, 1, private_key, {:namedCurve, {1, 2, 840, 10045, 3, 1, 7}}, public_key}
27+
else
28+
{:ECPrivateKey, 1, private_key, {:namedCurve, {1, 2, 840, 10045, 3, 1, 7}}, public_key, nil}
29+
end
2430
|> JOSE.JWK.from_key()
2531

2632
{_, jwt} = JOSE.JWS.compact(JOSE.JWT.sign(jwk, %{"alg" => "ES256"}, payload))

test/web_push_encryption/vapid_test.exs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,16 @@ defmodule WebPushEncryption.VapidTest do
77
assert %{"Authorization" => "WebPush " <> jwt, "Crypto-Key" => "p256ecdsa=" <> public_key} =
88
Vapid.get_headers("http://localhost/", "aesgcm")
99

10+
otp_version = :erlang.system_info(:otp_release) |> String.Chars.to_string() |> String.to_integer
11+
1012
jwk =
11-
{:ECPrivateKey, 1, <<>>, {:namedCurve, {1, 2, 840, 10045, 3, 1, 7}},
12-
Base.url_decode64!(public_key, padding: false)}
13+
if otp_version < 24 do
14+
{:ECPrivateKey, 1, <<>>, {:namedCurve, {1, 2, 840, 10045, 3, 1, 7}},
15+
Base.url_decode64!(public_key, padding: false)}
16+
else
17+
{:ECPrivateKey, 1, <<>>, {:namedCurve, {1, 2, 840, 10045, 3, 1, 7}},
18+
Base.url_decode64!(public_key, padding: false), nil}
19+
end
1320
|> JOSE.JWK.from_key()
1421

1522
assert {true, _, _} = JOSE.JWT.verify_strict(jwk, ["ES256"], jwt)

0 commit comments

Comments
 (0)