diff options
author | Joey Hess <joeyh@joeyh.name> | 2016-08-11 20:39:45 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2016-08-11 20:39:45 -0400 |
commit | ab3594dacb0461ae5e253544f65c3e3d50eb721d (patch) | |
tree | 306ad29a1cde9ce31a8364a9529953f93239013e | |
parent | f5a53103a95b93f5cdb3cfe0c7043c190e591f0c (diff) | |
download | keysafe-ab3594dacb0461ae5e253544f65c3e3d50eb721d.tar.gz |
obscure shard timestamps
-rw-r--r-- | Storage.hs | 5 | ||||
-rw-r--r-- | Storage/LocalFiles.hs | 15 | ||||
-rw-r--r-- | keysafe.hs | 1 |
3 files changed, 21 insertions, 0 deletions
@@ -10,9 +10,14 @@ import Types data Storage = Storage { storeShard :: StorableObjectIdent -> Shard -> IO StoreResult , retrieveShard :: ShardNum -> StorableObjectIdent -> IO RetrieveResult + , obscureShards :: IO ObscureResult + -- ^ run after making some changes, to avoid correlation attacks } data StoreResult = StoreSuccess | StoreFailure String deriving (Show) data RetrieveResult = RetrieveSuccess Shard | RetrieveFailure String + +data ObscureResult = ObscureSuccess | ObscureFailure String + deriving (Show) diff --git a/Storage/LocalFiles.hs b/Storage/LocalFiles.hs index d339774..083a74e 100644 --- a/Storage/LocalFiles.hs +++ b/Storage/LocalFiles.hs @@ -13,6 +13,7 @@ import Serialization () import qualified Data.ByteString as B import qualified Data.ByteString.UTF8 as U8 import Data.Monoid +import Data.List import System.Posix.User import System.IO import System.Directory @@ -26,6 +27,7 @@ localFiles :: Storage localFiles = Storage { storeShard = store , retrieveShard = retrieve + , obscureShards = obscure } store :: StorableObjectIdent -> Shard -> IO StoreResult @@ -48,6 +50,19 @@ retrieve n i = onError (RetrieveFailure . show) $ do b `deepseq` hClose h return $ RetrieveSuccess $ Shard n (StorableObject b) +-- | Set atime and mtime to epoch, to obscure access and modification +-- patterns. +-- +-- There is no way to set the ctime to the epoch, but setting the other +-- times does at least set it to the current time, which makes all +-- currently stored files look alike. +obscure :: IO ObscureResult +obscure = onError (ObscureFailure . show) $ do + dir <- shardDir + fs <- filter (ext `isSuffixOf`) <$> getDirectoryContents dir + mapM_ (\f -> setFileTimes (dir </> f) 0 0) fs + return ObscureSuccess + onError :: (IOException -> a) -> IO a -> IO a onError f a = do v <- try a @@ -30,6 +30,7 @@ storedemo = do let sis = shardIdents tunables name keyid shards <- genShards esk tunables print =<< mapM (uncurry (storeShard localFiles)) (zip (getIdents sis) shards) + print =<< obscureShards localFiles where password = Password "correct horse battery staple" name = Name "bar" |