2013-09-26 20:09:45 +00:00
|
|
|
{- git-annex assistant gpg stuff
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2013 Joey Hess <id@joeyh.name>
|
2013-09-26 20:09:45 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2013-09-26 20:09:45 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
module Assistant.Gpg where
|
|
|
|
|
|
|
|
import Utility.Gpg
|
|
|
|
import Utility.UserInfo
|
2019-10-10 19:31:10 +00:00
|
|
|
import Types.Remote (RemoteConfigField)
|
2019-10-10 19:46:12 +00:00
|
|
|
import Annex.SpecialRemote.Config
|
2020-01-10 18:10:20 +00:00
|
|
|
import Types.ProposedAccepted
|
2013-09-26 20:09:45 +00:00
|
|
|
|
|
|
|
import qualified Data.Map as M
|
2016-06-13 19:53:02 +00:00
|
|
|
import Control.Applicative
|
|
|
|
import Prelude
|
2013-09-26 20:09:45 +00:00
|
|
|
|
|
|
|
{- Generates a gpg user id that is not used by any existing secret key -}
|
2015-09-09 22:06:49 +00:00
|
|
|
newUserId :: GpgCmd -> IO UserId
|
|
|
|
newUserId cmd = do
|
|
|
|
oldkeys <- secretKeys cmd
|
2016-06-08 19:04:15 +00:00
|
|
|
username <- either (const "unknown") id <$> myUserName
|
2014-10-09 18:53:13 +00:00
|
|
|
let basekeyname = username ++ "'s git-annex encryption key"
|
2013-09-26 20:09:45 +00:00
|
|
|
return $ Prelude.head $ filter (\n -> M.null $ M.filter (== n) oldkeys)
|
|
|
|
( basekeyname
|
|
|
|
: map (\n -> basekeyname ++ show n) ([2..] :: [Int])
|
|
|
|
)
|
|
|
|
|
|
|
|
data EnableEncryption = HybridEncryption | SharedEncryption | NoEncryption
|
|
|
|
deriving (Eq)
|
|
|
|
|
|
|
|
{- Generates Remote configuration for encryption. -}
|
2020-01-10 18:10:20 +00:00
|
|
|
configureEncryption :: EnableEncryption -> (RemoteConfigField, ProposedAccepted String)
|
|
|
|
configureEncryption SharedEncryption = (encryptionField, Proposed "shared")
|
|
|
|
configureEncryption NoEncryption = (encryptionField, Proposed "none")
|
|
|
|
configureEncryption HybridEncryption = (encryptionField, Proposed "hybrid")
|