diff --git a/elm.json b/elm.json index 97309e70..9c2c17ad 100644 --- a/elm.json +++ b/elm.json @@ -32,6 +32,8 @@ "icidasset/elm-sha": "2.0.0", "jorgengranseth/elm-string-format": "1.0.1", "justgage/tachyons-elm": "4.1.1", + "ktonon/elm-crypto": "1.1.2", + "ktonon/elm-word": "2.1.2", "noahzgordon/elm-color-extra": "1.0.1", "pilatch/flip": "1.0.0", "rluiten/elm-text-search": "5.0.0", diff --git a/src/Library/Crypto/Hmac.elm b/src/Library/Cryptography/Hmac.elm similarity index 97% rename from src/Library/Crypto/Hmac.elm rename to src/Library/Cryptography/Hmac.elm index 21e3a2f2..820ceb03 100644 --- a/src/Library/Crypto/Hmac.elm +++ b/src/Library/Cryptography/Hmac.elm @@ -1,4 +1,4 @@ -module Crypto.HMAC exposing (encrypt128, encrypt64) +module Cryptography.HMAC exposing (encrypt128, encrypt64) {-| Cryptography – HMAC -} diff --git a/src/Library/Sources/Services/AmazonS3/Presign.elm b/src/Library/Sources/Services/AmazonS3/Presign.elm index 47c376bb..c7cf63c6 100644 --- a/src/Library/Sources/Services/AmazonS3/Presign.elm +++ b/src/Library/Sources/Services/AmazonS3/Presign.elm @@ -1,7 +1,7 @@ module Sources.Services.AmazonS3.Presign exposing (presignedUrl) -import Binary exposing (Bits) -import Crypto.HMAC as HMAC +import Crypto.HMAC +import Crypto.Hash import DateFormat as Date import Dict import Dict.Ext as Dict @@ -15,6 +15,8 @@ import String.Ext as String import Time import Url import Url.Builder as Url +import Word.Bytes as Bytes +import Word.Hex as Hex @@ -153,24 +155,19 @@ presignedUrl method lifeExpectancyInSeconds extraParams currentTime srcData path , String.join "/" [ date, region, "s3", "aws4_request" ] -- - , request - |> Binary.fromStringAsUtf8 - |> SHA.sha256 - |> Binary.toHex - |> String.toLower + , Crypto.Hash.sha256 request ] -- Signature signature = ("AWS4" ++ Dict.fetchUnknown "secretKey" aws) - |> Binary.fromStringAsUtf8 + |> Bytes.fromUTF8 |> hmacSha256 date |> hmacSha256 region |> hmacSha256 "s3" |> hmacSha256 "aws4_request" |> hmacSha256 stringToSign - |> Binary.toHex - |> String.toLower + |> Hex.fromByteList in String.concat [ protocol @@ -200,6 +197,8 @@ encodeAdditionalCharacters query = query -hmacSha256 : String -> Bits -> Bits -hmacSha256 = - HMAC.encrypt64 SHA.sha256 +hmacSha256 : String -> List Int -> List Int +hmacSha256 message key = + Crypto.HMAC.digestBytes Crypto.HMAC.sha256 + key + (Bytes.fromUTF8 message)