From 3802543623184a405977175c496b4d400fe56f7d Mon Sep 17 00:00:00 2001 From: Emi Simpson Date: Wed, 9 Nov 2022 15:54:33 -0500 Subject: [PATCH] Use seperate nonces for thumbnails and full images Corresponds to dd2748c in aviary-cli --- src/Logic.purs | 12 ++++++------ src/ffi.js | 3 ++- src/ffi.purs | 3 ++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Logic.purs b/src/Logic.purs index 83338cb..e0d3b71 100644 --- a/src/Logic.purs +++ b/src/Logic.purs @@ -2,7 +2,7 @@ module Aviary.Logic where import Prelude import AviaryFormat.Format (Format(..), Image, Index, parseIndex) as Format -import Aviary.FFI (arrayBufferToBlob, nonce, decodeBlurhash32) +import Aviary.FFI (arrayBufferToBlob, nonce_a, nonce_b, decodeBlurhash32) import Aviary.Model (formatToMime, GalleryError(..), Image, ImageData(..), ImageError(..), Model(..)) import Control.Monad.Error.Class (try) @@ -106,8 +106,8 @@ fetchImageAsBlobUrl nonce format key fileID = do else UnknownStatusCodeForImage status Left e -> pure $ IError $ NetworkError $ message e -_fetchImg :: ImageData -> Format.Format -> Aff (Maybe CryptoKey) -> Aff ImageData -_fetchImg imgdata format cryptokey = case imgdata of +_fetchImg :: ArrayBuffer -> ImageData -> Format.Format -> Aff (Maybe CryptoKey) -> Aff ImageData +_fetchImg nonce imgdata format cryptokey = case imgdata of Unloaded fileID -> do key' <- cryptokey case key' of @@ -116,10 +116,10 @@ _fetchImg imgdata format cryptokey = case imgdata of loadedOrError -> pure loadedOrError fetchThumb :: Image -> Aff ImageData -fetchThumb image = _fetchImg image.thumb Format.Format_WEBP image.key +fetchThumb image = _fetchImg nonce_b image.thumb Format.Format_WEBP image.key fetchFull :: Image -> Aff ImageData -fetchFull image = _fetchImg image.full image.format image.key +fetchFull image = _fetchImg nonce_a image.full image.format image.key type Parameters = { fileId :: String @@ -148,7 +148,7 @@ fetch_and_decrypt_gallery params = do case result of Right {status: 200, arrayBuffer} -> do encryptedIndex <- arrayBuffer - serializedIndex <- try $ decryptBlob params.key encryptedIndex nonce + serializedIndex <- try $ decryptBlob params.key encryptedIndex nonce_a case serializedIndex of Left _ -> pure $ GError DecryptFailed Right serializedIndex' -> do diff --git a/src/ffi.js b/src/ffi.js index 39e2c11..1479286 100644 --- a/src/ffi.js +++ b/src/ffi.js @@ -4,7 +4,8 @@ export function arrayBufferToBlob(mime) { } } -export const nonce = new Uint8Array([0xd0, 0xc3, 0x75, 0x56, 0x58, 0xc1, 0x7e, 0x5f, 0xd6, 0xcc, 0xb6, 0x76]).buffer +export const nonce_a = new Uint8Array([0xd0, 0xc3, 0x75, 0x56, 0x58, 0xc1, 0x7e, 0x5f, 0xd6, 0xcc, 0xb6, 0x76]).buffer +export const nonce_b = new Uint8Array([0x77, 0xe7, 0xf7, 0x64, 0x33, 0x80, 0x25, 0x49, 0xec, 0xef, 0x57, 0x3f]).buffer export function decodeBlurhashImpl(just) { return function(nothing) { diff --git a/src/ffi.purs b/src/ffi.purs index d2a4059..2899478 100644 --- a/src/ffi.purs +++ b/src/ffi.purs @@ -11,7 +11,8 @@ import Web.File.Blob (Blob) -- blobData :: ArrayBuffer foreign import arrayBufferToBlob :: String -> ArrayBuffer -> Blob -foreign import nonce :: ArrayBuffer +foreign import nonce_a :: ArrayBuffer +foreign import nonce_b :: ArrayBuffer foreign import decodeBlurhashImpl :: (forall x. x -> Maybe x) -> (forall x. Maybe x) -> Int -> Int -> String -> Maybe String decodeBlurhash :: Int -> Int -> String -> Maybe String