diff options
author | Robert Newson <rnewson@apache.org> | 2017-05-10 21:54:21 +0100 |
---|---|---|
committer | Robert Newson <rnewson@apache.org> | 2017-05-10 21:54:21 +0100 |
commit | e0d61d06651b576b9b0a36600529028aae334e68 (patch) | |
tree | 94dfd5479060274f51e76a490056bfc10453b28e | |
parent | ae0e0f495db22069e6c811462cd974fea7ae7ad8 (diff) | |
download | couchdb-e0d61d06651b576b9b0a36600529028aae334e68.tar.gz |
test EC
-rw-r--r-- | src/jwks.erl | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/jwks.erl b/src/jwks.erl index a2231b2f4..b88c59068 100644 --- a/src/jwks.erl +++ b/src/jwks.erl @@ -54,10 +54,12 @@ parse_key({Props}) -> <<"P-256">> -> X = proplists:get_value(<<"x">>, Props), Y = proplists:get_value(<<"y">>, Props), - Point = <<4:8, X/binary, Y/binary>>, + Point = <<4:8, + (b64url:decode(X))/binary, + (b64url:decode(Y))/binary>>, [{{Kty, Kid}, { #'ECPoint'{point = Point}, - {namedCurve, secp256r1} + {namedCurve,{1,2,840,10045,3,1,7}} }}]; _ -> [] @@ -96,6 +98,13 @@ rs_test() -> ec_test() -> + PrivateKey = #'ECPrivateKey'{ + version = 1, + parameters = {namedCurve,{1,2,840,10045,3,1,7}}, + privateKey = b64url:decode("870MB6gfuTJ4HtUnUvYMyJpr5eUZNP4Bk43bVdj3eAE"), + publicKey = <<4:8, + (b64url:decode("MKBCTNIcKUSDii11ySs3526iDZ8AiTo7Tu6KPAqv7D4"))/binary, + (b64url:decode("4Etl6SRW2YiLUrN5vfvVHuhp7x8PxltmWWlbbM4IFyM"))/binary>>}, Ejson = {[ {<<"kty">>, <<"EC">>}, {<<"crv">>, <<"P-256">>}, @@ -104,8 +113,10 @@ ec_test() -> {<<"alg">>, <<"ES256">>}, {<<"kid">>, <<"1">>} ]}, - %% TODO figure out how to convert x,y to an ECPoint. - ?assertMatch([{{<<"EC">>, <<"1">>}, {{'ECPoint', _}, - {namedCurve, secp256r1}}}], parse_key(Ejson)). + ?assertMatch([{_Key, _Value}], parse_key(Ejson)), + {_, ECPublicKey} = parse_key(Ejson), + Msg = <<"foo">>, + Sig = public_key:sign(Msg, sha256, PrivateKey), + ?assert(public_key:verify(Msg, sha256, Sig, ECPublicKey)). -endif. |