You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2022/05/24 20:25:20 UTC

[couchdb] 01/01: Cannot use EC algorithms on Erlang 20

This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch jwtf-es256-fail-erlang-20
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit cc1c6d7581cc91164d47745ccefec293fb88cd09
Author: Nick Vatamaniuc <va...@gmail.com>
AuthorDate: Tue May 24 16:21:37 2022 -0400

    Cannot use EC algorithms on Erlang 20
---
 src/jwtf/src/jwtf.erl        | 17 +++++++++++++++++
 src/jwtf/test/jwtf_tests.erl |  8 ++++++++
 2 files changed, 25 insertions(+)

diff --git a/src/jwtf/src/jwtf.erl b/src/jwtf/src/jwtf.erl
index f0a5bd6ca..e45a1ade1 100644
--- a/src/jwtf/src/jwtf.erl
+++ b/src/jwtf/src/jwtf.erl
@@ -29,6 +29,9 @@
 
 -include_lib("public_key/include/public_key.hrl").
 
+
+-ifdef(OTP_RELEASE).
+
 -define(ALGS, [
     % RSA PKCS#1 signature with SHA-256
     {<<"RS256">>, {public_key, sha256}},
@@ -42,6 +45,20 @@
     {<<"HS512">>, {hmac, sha512}}
 ]).
 
+-else.
+
+-define(ALGS, [
+    % RSA PKCS#1 signature with SHA-256
+    {<<"RS256">>, {public_key, sha256}},
+    {<<"RS384">>, {public_key, sha384}},
+    {<<"RS512">>, {public_key, sha512}},
+    {<<"HS256">>, {hmac, sha256}},
+    {<<"HS384">>, {hmac, sha384}},
+    {<<"HS512">>, {hmac, sha512}}
+]).
+
+-endif.
+
 -define(CHECKS, [
     alg,
     exp,
diff --git a/src/jwtf/test/jwtf_tests.erl b/src/jwtf/test/jwtf_tests.erl
index 2c66aa6db..a72e0d3ec 100644
--- a/src/jwtf/test/jwtf_tests.erl
+++ b/src/jwtf/test/jwtf_tests.erl
@@ -36,6 +36,8 @@ jwt_io_rsa_pubkey() ->
     [PEMEntry] = public_key:pem_decode(PublicKeyPEM),
     public_key:pem_entry_decode(PEMEntry).
 
+-ifdef(OTP_RELEASE).
+
 jwt_io_ec_pubkey() ->
     PublicKeyPEM = <<
         "-----BEGIN PUBLIC KEY-----\n"
@@ -46,6 +48,8 @@ jwt_io_ec_pubkey() ->
     [PEMEntry] = public_key:pem_decode(PublicKeyPEM),
     public_key:pem_entry_decode(PEMEntry).
 
+-endif.
+
 b64_badarg_test() ->
     Encoded = <<"0.0.0">>,
     ?assertEqual(
@@ -285,6 +289,8 @@ rs256_test() ->
 
     ?assertMatch({ok, ExpectedPayload}, jwtf:decode(EncodedToken, Checks, KS)).
 
+
+-ifdef(OTP_RELEASE).
 %% jwt.io generated
 es256_test() ->
     EncodedToken = <<
@@ -306,6 +312,8 @@ es256_test() ->
 
     ?assertMatch({ok, ExpectedPayload}, jwtf:decode(EncodedToken, Checks, KS)).
 
+-endif.
+
 encode_missing_alg_test() ->
     ?assertEqual(
         {error, {bad_request, <<"Missing alg header parameter">>}},