bd5affa362
This deals with the possible security problem that someone could make an unusually low UUID and generate keys that are all constructed to hash to a number that, mod the number of repositories in the group, == 0. So balanced preferred content would always put those keys in the repository with the low UUID as long as the group contains the number of repositories that the attacker anticipated. Presumably the attacker than holds the data for ransom? Dunno. Anyway, the partial solution is to use HMAC (sha256) with all the UUIDs combined together as the "secret", and the key as the "message". Now any change in the set of UUIDs in a group will invalidate the attacker's constructed keys from hashing to anything in particular. Given that there are plenty of other things someone can do if they can write to the repository -- including modifying preferred content so only their repository wants files, and numcopies so other repositories drom them -- this seems like safeguard enough. Note that, in balancedPicker, combineduuids is memoized.
40 lines
834 B
Haskell
40 lines
834 B
Haskell
{- git-annex repo groups
|
|
-
|
|
- Copyright 2012-2024 Joey Hess <id@joeyh.name>
|
|
-
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
|
-}
|
|
|
|
module Types.Group (
|
|
Group(..),
|
|
fromGroup,
|
|
toGroup,
|
|
GroupMap(..),
|
|
emptyGroupMap
|
|
) where
|
|
|
|
import Types.UUID
|
|
import Utility.FileSystemEncoding
|
|
import Annex.Balanced
|
|
|
|
import qualified Data.Map as M
|
|
import qualified Data.Set as S
|
|
import qualified Data.ByteString as S
|
|
|
|
newtype Group = Group S.ByteString
|
|
deriving (Eq, Ord, Show)
|
|
|
|
fromGroup :: Group -> String
|
|
fromGroup (Group g) = decodeBS g
|
|
|
|
toGroup :: String -> Group
|
|
toGroup = Group . encodeBS
|
|
|
|
data GroupMap = GroupMap
|
|
{ groupsByUUID :: M.Map UUID (S.Set Group)
|
|
, uuidsByGroup :: M.Map Group (S.Set UUID)
|
|
, balancedPickerByGroup :: M.Map Group BalancedPicker
|
|
}
|
|
|
|
emptyGroupMap :: GroupMap
|
|
emptyGroupMap = GroupMap M.empty M.empty M.empty
|