diff --git a/dub.json b/dub.json index 1f6d0d5..259aa45 100644 --- a/dub.json +++ b/dub.json @@ -12,6 +12,6 @@ "copyright": "Copyright © 2021, HuntLabs", "license": "MIT", "dependencies": { - "hunt-openssl": "~>1.0.4" + "openssl": {"repository": "git+https://github.com/HenkKalkwater/openssl.git", "version": "163395f4d8ec04c41a5cf60ef19a327c2ef40770"} } -} \ No newline at end of file +} diff --git a/source/hunt/jwt/JwtOpenSSL.d b/source/hunt/jwt/JwtOpenSSL.d index 895addd..f7a8f53 100644 --- a/source/hunt/jwt/JwtOpenSSL.d +++ b/source/hunt/jwt/JwtOpenSSL.d @@ -2,6 +2,7 @@ module hunt.jwt.JwtOpenSSL; import deimos.openssl.ssl; import deimos.openssl.pem; +import deimos.openssl.ecdsa; import deimos.openssl.rsa; import deimos.openssl.hmac; import deimos.openssl.err; @@ -22,19 +23,11 @@ string sign(string msg, string key, JwtAlgorithm algo = JwtAlgorithm.HS256) { void sign_hs(const(EVP_MD)* evp, uint signLen) { sign = new ubyte[signLen]; - - HMAC_CTX ctx; - scope(exit) HMAC_CTX_reset(&ctx); - HMAC_CTX_reset(&ctx); - - if(0 == HMAC_Init_ex(&ctx, key.ptr, cast(int)key.length, evp, null)) { - throw new Exception("Can't initialize HMAC context."); - } - if(0 == HMAC_Update(&ctx, cast(const(ubyte)*)msg.ptr, cast(ulong)msg.length)) { - throw new Exception("Can't update HMAC."); - } - if(0 == HMAC_Final(&ctx, cast(ubyte*)sign.ptr, &signLen)) { - throw new Exception("Can't finalize HMAC."); + + if (null is HMAC(evp, key.ptr, cast(int) key.length, + cast(const(ubyte)*) msg.ptr, cast(ulong) msg.length, + cast(ubyte*) sign.ptr, &signLen)) { + throw new Exception("Cannot sign the data using HMAC"); } } @@ -434,4 +427,4 @@ private bool verifyShaPem(const(EVP_MD) *alg, int type, string head, const(ubyte return true; -} \ No newline at end of file +}