{-# LANGUAGE OverloadedStrings, GeneralizedNewtypeDeriving, MultiParamTypeClasses, FlexibleInstances #-} {- Copyright 2016 Joey Hess - - Licensed under the GNU AGPL version 3 or higher. -} module Types where import Types.Cost import Entropy import qualified Data.ByteString as B import Data.String -- | keysafe stores secret keys. newtype SecretKey = SecretKey B.ByteString -- | The secret key, encrypted with a password. data EncryptedSecretKey = EncryptedSecretKey B.ByteString (CostCalc BruteForceOp UnknownPassword) instance Show EncryptedSecretKey where show (EncryptedSecretKey b _) = show b instance Bruteforceable EncryptedSecretKey UnknownPassword where getBruteCostCalc (EncryptedSecretKey _ cc) = cc -- | Objects stored on a keysafe server are (probably) a shard of an -- encrypted secret key. newtype StorableObject = StorableObject { fromStorableObject :: B.ByteString } deriving (Show) -- | An identifier for a StorableObject newtype StorableObjectIdent = StorableObjectIdent B.ByteString deriving (Show) -- | A shard, with a known number (N of M). data Shard = Shard ShardNum StorableObject type ShardNum = Int -- | A password used to encrypt a key stored in keysafe. newtype Password = Password B.ByteString deriving (IsString) -- | Naive calculation of the entropy of a password. -- Does not take common passwords and password generation patterns into -- account, so this is an overestimation of how hard a password -- is to crack. passwordEntropy :: Password -> Entropy UnknownPassword passwordEntropy (Password p) = Entropy $ floor $ totalEntropy p -- | A name associated with a key stored in keysafe. newtype Name = Name B.ByteString deriving (Show) -- | Very naive calculation of the entropy of a name. -- Assumes that the attacker is not targeting a particular list of names. nameEntropy :: Name -> Entropy UnknownName nameEntropy (Name n) = Entropy $ floor $ totalEntropy n -- | The type of the key that is stored in keysafe. newtype KeyType = KeyType B.ByteString deriving (Show) gpgKey :: KeyType gpgKey = KeyType "gpg" -- | The keyid is any value that is unique to a private key, and can be -- looked up somehow without knowing the private key. -- -- A gpg keyid is the obvious example. data KeyId = KeyId KeyType B.ByteString deriving (Show) data Benchmark t = Benchmark { expectedBenchmark :: t, actualBenchmark :: t } deriving (Show)