Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for ES256 #413

Merged
merged 1 commit into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ CSAnW8Md2j56RkvCnSPGab8eh5BjoGEInmSZWpUXvLJt91pZqX1jSbs1ZNg=
-----END RSA PRIVATE KEY-----
"""

ec_pem_key = """
-----BEGIN EC PRIVATE KEY-----
MHcCAQEEIBEdk34npuxz13CvGk/BS39dZ+2XAR6k9S4uNhtEMd3AoAoGCCqGSM49
AwEHoUQDQgAExCkF/6mwf3HoEv4m+1+Pi702herRxJeycLHXiRpA8Nkj8tVjU9C6
5CRx1TdE4q4I8ympW4HrBm2qpPi3z6mEGw==
-----END EC PRIVATE KEY-----
"""

# generated with openssl genrsa -aes256 4096
rsa_encrypted_passphrase = "passphrase"

Expand Down Expand Up @@ -183,6 +191,10 @@ config :joken,
signer_alg: "RS256",
key_pem: rsa_pem_key
],
pem_es256: [
signer_alg: "ES256",
key_pem: ec_pem_key
],
pem_encrypted_rs256: [
signer_alg: "RS256",
key_pem: rsa_encrypted_pem_key,
Expand Down
13 changes: 13 additions & 0 deletions test/joken_signer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ defmodule Joken.Signer.Test do
} = signer
end

test "can create a signer from an EC private key" do
pem = Application.get_env(:joken, :pem_es256)[:key_pem]
signer = Signer.create("ES256", %{"pem" => pem})

assert %Signer{
alg: "ES256",
jws: %JOSE.JWS{
alg: {:jose_jws_alg_ecdsa, :ES256}
},
jwk: %JOSE.JWK{}
} = signer
end

test "can create a signer from an encrypted key" do
pem = Application.get_env(:joken, :pem_encrypted_rs256)[:key_pem]
passphrase = Application.get_env(:joken, :pem_encrypted_rs256)[:passphrase]
Expand Down