diff --git a/config/test.exs b/config/test.exs index 6b9708f..9f70ffb 100644 --- a/config/test.exs +++ b/config/test.exs @@ -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" @@ -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, diff --git a/test/joken_signer_test.exs b/test/joken_signer_test.exs index 091fab8..82fc23e 100644 --- a/test/joken_signer_test.exs +++ b/test/joken_signer_test.exs @@ -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]