Use seperate nonces for thumbnails and full images

Corresponds to dd2748c in aviary-cli
This commit is contained in:
Emi Simpson 2022-11-09 15:54:33 -05:00
parent 0895108c07
commit 3802543623
Signed by: Emi
GPG Key ID: A12F2C2FFDC3D847
3 changed files with 10 additions and 8 deletions

View File

@ -2,7 +2,7 @@ module Aviary.Logic where
import Prelude import Prelude
import AviaryFormat.Format (Format(..), Image, Index, parseIndex) as Format 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 Aviary.Model (formatToMime, GalleryError(..), Image, ImageData(..), ImageError(..), Model(..))
import Control.Monad.Error.Class (try) import Control.Monad.Error.Class (try)
@ -106,8 +106,8 @@ fetchImageAsBlobUrl nonce format key fileID = do
else UnknownStatusCodeForImage status else UnknownStatusCodeForImage status
Left e -> pure $ IError $ NetworkError $ message e Left e -> pure $ IError $ NetworkError $ message e
_fetchImg :: ImageData -> Format.Format -> Aff (Maybe CryptoKey) -> Aff ImageData _fetchImg :: ArrayBuffer -> ImageData -> Format.Format -> Aff (Maybe CryptoKey) -> Aff ImageData
_fetchImg imgdata format cryptokey = case imgdata of _fetchImg nonce imgdata format cryptokey = case imgdata of
Unloaded fileID -> do Unloaded fileID -> do
key' <- cryptokey key' <- cryptokey
case key' of case key' of
@ -116,10 +116,10 @@ _fetchImg imgdata format cryptokey = case imgdata of
loadedOrError -> pure loadedOrError loadedOrError -> pure loadedOrError
fetchThumb :: Image -> Aff ImageData 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 -> Aff ImageData
fetchFull image = _fetchImg image.full image.format image.key fetchFull image = _fetchImg nonce_a image.full image.format image.key
type Parameters = type Parameters =
{ fileId :: String { fileId :: String
@ -148,7 +148,7 @@ fetch_and_decrypt_gallery params = do
case result of case result of
Right {status: 200, arrayBuffer} -> do Right {status: 200, arrayBuffer} -> do
encryptedIndex <- arrayBuffer encryptedIndex <- arrayBuffer
serializedIndex <- try $ decryptBlob params.key encryptedIndex nonce serializedIndex <- try $ decryptBlob params.key encryptedIndex nonce_a
case serializedIndex of case serializedIndex of
Left _ -> pure $ GError DecryptFailed Left _ -> pure $ GError DecryptFailed
Right serializedIndex' -> do Right serializedIndex' -> do

View File

@ -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) { export function decodeBlurhashImpl(just) {
return function(nothing) { return function(nothing) {

View File

@ -11,7 +11,8 @@ import Web.File.Blob (Blob)
-- blobData :: ArrayBuffer -- blobData :: ArrayBuffer
foreign import arrayBufferToBlob :: String -> ArrayBuffer -> Blob 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 foreign import decodeBlurhashImpl :: (forall x. x -> Maybe x) -> (forall x. Maybe x) -> Int -> Int -> String -> Maybe String
decodeBlurhash :: Int -> Int -> String -> Maybe String decodeBlurhash :: Int -> Int -> String -> Maybe String