From b0aa14ea3b12ab0559793bfb46df4625d7792bd4 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 28 Aug 2016 12:48:24 -0400 Subject: http: refuse to store object of unexpected size --- Tunables.hs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'Tunables.hs') diff --git a/Tunables.hs b/Tunables.hs index ce7aa6e..3fa700a 100644 --- a/Tunables.hs +++ b/Tunables.hs @@ -7,8 +7,10 @@ module Tunables where +import Types import Cost import qualified Crypto.Argon2 as Argon2 +import qualified Data.ByteString as B -- | To determine the tunables used for a key name the expensive hash of the -- name is calculated, using a particular configuration, and if the @@ -38,6 +40,8 @@ data Tunables = Tunables -- ^ a StorableObject is exactly this many bytes in size -- (must be a multiple of AES block size 16, and cannot be smaller -- than 256 bytes) + , shareOverhead :: Int + -- ^ Share encoding overhead as a multiple of the objectSize , nameGenerationTunable :: NameGenerationTunable , keyEncryptionKeyTunable :: KeyEncryptionKeyTunable , encryptionTunable :: EncryptionTunable @@ -82,7 +86,8 @@ data EncryptionTunable = UseAES256 defaultTunables :: Tunables defaultTunables = Tunables { shareParams = ShareParams { totalObjects = 3, neededObjects = 2 } - , objectSize = 1024*64 -- 64 kb + , objectSize = 1024*32 -- 32 kb + , shareOverhead = 2 -- The nameGenerationHash was benchmarked at 661 seconds CPU time -- on a 2 core Intel(R) Core(TM) i5-4210Y CPU @ 1.50GHz. -- Since cost is measured per core, we double that. @@ -114,7 +119,8 @@ defaultTunables = Tunables testModeTunables :: Tunables testModeTunables = Tunables { shareParams = ShareParams { totalObjects = 3, neededObjects = 2 } - , objectSize = 1024*64 + , objectSize = 1024*32 + , shareOverhead = 2 , nameGenerationTunable = NameGenerationTunable { nameGenerationHash = weakargon2 (CPUCost (Seconds (2*600))) } @@ -127,3 +133,10 @@ testModeTunables = Tunables } where weakargon2 c = UseArgon2 c Argon2.defaultHashOptions + +validObjectsize :: StorableObject -> Bool +validObjectsize o = any (sz ==) knownsizes + where + sz = B.length (fromStorableObject o) + knownsizes = map (\t -> objectSize t * shareOverhead t) + (map snd knownTunings) -- cgit v1.2.3