From 94cab1c9d49f30288d5aed4b210a709a4abba7d8 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Fri, 21 Feb 2014 07:16:04 +0200 Subject: [PATCH] RSA 2.0 support --- authenticate-oauth/Web/Authenticate/OAuth.hs | 8 ++++++++ authenticate-oauth/authenticate-oauth.cabal | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/authenticate-oauth/Web/Authenticate/OAuth.hs b/authenticate-oauth/Web/Authenticate/OAuth.hs index 87ce2f53..e7dc6dbe 100644 --- a/authenticate-oauth/Web/Authenticate/OAuth.hs +++ b/authenticate-oauth/Web/Authenticate/OAuth.hs @@ -35,7 +35,11 @@ import Data.Digest.Pure.SHA import Data.ByteString.Base64 import Data.Time import Numeric +#if MIN_VERSION_RSA(2, 0, 0) +import Codec.Crypto.RSA (rsassa_pkcs1_v1_5_sign, hashSHA1) +#else import Codec.Crypto.RSA (rsassa_pkcs1_v1_5_sign, ha_SHA1) +#endif import Crypto.Types.PubKey.RSA (PrivateKey(..), PublicKey(..)) import Network.HTTP.Types (Header) import Blaze.ByteString.Builder (toByteString) @@ -344,7 +348,11 @@ genSign oa tok req = PLAINTEXT -> return $ BS.intercalate "&" $ map paramEncode [oauthConsumerSecret oa, tokenSecret tok] RSASHA1 pr -> +#if MIN_VERSION_RSA(2, 0, 0) + liftM (encode . toStrict . rsassa_pkcs1_v1_5_sign hashSHA1 pr) (getBaseString tok req) +#else liftM (encode . toStrict . rsassa_pkcs1_v1_5_sign ha_SHA1 pr) (getBaseString tok req) +#endif #if MIN_VERSION_http_conduit(2, 0, 0) addAuthHeader :: BS.ByteString -> Credential -> Request -> Request diff --git a/authenticate-oauth/authenticate-oauth.cabal b/authenticate-oauth/authenticate-oauth.cabal index 2abf7c63..ea4db124 100644 --- a/authenticate-oauth/authenticate-oauth.cabal +++ b/authenticate-oauth/authenticate-oauth.cabal @@ -19,7 +19,7 @@ library , transformers >= 0.1 && < 0.4 , bytestring >= 0.9 , crypto-pubkey-types >= 0.1 && < 0.5 - , RSA >= 1.2 && < 1.3 + , RSA >= 1.2 && < 2.1 , time , data-default , base64-bytestring >= 0.1 && < 1.1