2011-04-15 22:18:39 +00:00
|
|
|
{- git-annex crypto
|
2011-04-16 17:25:27 +00:00
|
|
|
-
|
2024-01-12 17:29:34 +00:00
|
|
|
- Currently using gpg by default, or optionally stateless OpenPGP.
|
2011-04-15 22:18:39 +00:00
|
|
|
-
|
2024-01-12 16:27:58 +00:00
|
|
|
- Copyright 2011-2024 Joey Hess <id@joeyh.name>
|
2011-04-15 22:18:39 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2011-04-15 22:18:39 +00:00
|
|
|
-}
|
|
|
|
|
2013-09-05 03:16:33 +00:00
|
|
|
{-# LANGUAGE FlexibleInstances #-}
|
2019-01-11 20:34:04 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
2014-07-29 20:22:19 +00:00
|
|
|
{-# LANGUAGE Rank2Types #-}
|
2013-09-05 03:16:33 +00:00
|
|
|
|
2011-04-15 22:18:39 +00:00
|
|
|
module Crypto (
|
2020-01-13 16:35:39 +00:00
|
|
|
EncryptionMethod(..),
|
2011-04-16 22:22:52 +00:00
|
|
|
Cipher,
|
2012-04-29 18:31:34 +00:00
|
|
|
KeyIds(..),
|
2014-07-27 00:14:09 +00:00
|
|
|
EncKey,
|
2012-04-29 18:02:18 +00:00
|
|
|
StorableCipher(..),
|
|
|
|
genEncryptedCipher,
|
|
|
|
genSharedCipher,
|
2016-05-10 20:50:31 +00:00
|
|
|
genSharedPubKeyCipher,
|
|
|
|
updateCipherKeyIds,
|
2022-05-18 19:32:40 +00:00
|
|
|
decryptCipher,
|
|
|
|
decryptCipher',
|
2011-04-15 22:18:39 +00:00
|
|
|
encryptKey,
|
2014-08-03 20:54:57 +00:00
|
|
|
isEncKey,
|
2012-11-18 19:27:44 +00:00
|
|
|
feedFile,
|
|
|
|
feedBytes,
|
|
|
|
readBytes,
|
2020-06-16 21:03:19 +00:00
|
|
|
readBytesStrictly,
|
2012-11-18 19:27:44 +00:00
|
|
|
encrypt,
|
2013-09-05 03:16:33 +00:00
|
|
|
decrypt,
|
2024-01-12 17:29:34 +00:00
|
|
|
LensEncParams(..),
|
2011-04-21 20:56:24 +00:00
|
|
|
|
2013-03-29 16:06:02 +00:00
|
|
|
prop_HmacSha1WithCipher_sane
|
2011-04-15 22:18:39 +00:00
|
|
|
) where
|
|
|
|
|
2019-01-11 20:34:04 +00:00
|
|
|
import qualified Data.ByteString as S
|
2012-06-20 17:13:40 +00:00
|
|
|
import qualified Data.ByteString.Lazy as L
|
2014-07-29 20:22:19 +00:00
|
|
|
import Control.Monad.IO.Class
|
2024-01-12 17:29:34 +00:00
|
|
|
import qualified Data.ByteString.Short as S (toShort)
|
2011-04-15 22:18:39 +00:00
|
|
|
|
2016-01-20 20:36:33 +00:00
|
|
|
import Annex.Common
|
2011-12-21 01:47:56 +00:00
|
|
|
import qualified Utility.Gpg as Gpg
|
2024-01-12 16:27:58 +00:00
|
|
|
import qualified Utility.StatelessOpenPGP as SOP
|
2011-06-02 01:56:04 +00:00
|
|
|
import Types.Crypto
|
2013-09-05 03:16:33 +00:00
|
|
|
import Types.Remote
|
2017-02-24 19:16:56 +00:00
|
|
|
import Types.Key
|
2019-10-10 19:46:12 +00:00
|
|
|
import Annex.SpecialRemote.Config
|
2024-01-12 17:29:34 +00:00
|
|
|
import Utility.Tmp.Dir
|
|
|
|
|
|
|
|
{- The number of bytes of entropy used to generate a Cipher.
|
|
|
|
-
|
|
|
|
- Since a Cipher is base-64 encoded, the actual size of a Cipher
|
|
|
|
- is larger than this. 512 bytes of date base-64 encodes to 684
|
|
|
|
- characters.
|
|
|
|
-}
|
|
|
|
cipherSize :: Int
|
|
|
|
cipherSize = 512
|
2011-04-15 22:18:39 +00:00
|
|
|
|
2013-03-29 16:06:02 +00:00
|
|
|
{- The beginning of a Cipher is used for MAC'ing; the remainder is used
|
2024-01-12 17:29:34 +00:00
|
|
|
- as the symmetric encryption passphrase.
|
2011-04-17 05:34:28 +00:00
|
|
|
-
|
2024-01-12 17:29:34 +00:00
|
|
|
- Due to the base-64 encoding of the Cipher, the beginning 265 characters
|
|
|
|
- represent at best 192 bytes of entropy. However that's more than enough
|
|
|
|
- for both the default MAC algorithm, namely HMAC-SHA1, and the "strongest"
|
2013-03-29 22:06:14 +00:00
|
|
|
- currently supported, namely HMAC-SHA512, which respectively need
|
2013-03-29 16:06:02 +00:00
|
|
|
- (ideally) 64 and 128 bytes of entropy.
|
2011-04-17 15:13:54 +00:00
|
|
|
-
|
2024-01-12 17:29:34 +00:00
|
|
|
- The remaining characters (320 bytes of entropy) is enough for
|
|
|
|
- the symmetric encryption passphrase; unlike weaker public key crypto,
|
|
|
|
- that does not need to be too large.
|
2011-04-17 05:34:28 +00:00
|
|
|
-}
|
2013-03-03 23:44:48 +00:00
|
|
|
cipherBeginning :: Int
|
|
|
|
cipherBeginning = 256
|
2011-04-17 05:34:28 +00:00
|
|
|
|
2023-11-01 18:27:22 +00:00
|
|
|
cipherPassphrase :: Cipher -> S.ByteString
|
|
|
|
cipherPassphrase (Cipher c) = S.drop cipherBeginning c
|
2023-04-10 17:38:14 +00:00
|
|
|
cipherPassphrase (MacOnlyCipher _) = giveup "MAC-only cipher"
|
2011-04-17 05:34:28 +00:00
|
|
|
|
2023-11-01 18:27:22 +00:00
|
|
|
cipherMac :: Cipher -> S.ByteString
|
|
|
|
cipherMac (Cipher c) = S.take cipherBeginning c
|
2013-09-05 06:09:39 +00:00
|
|
|
cipherMac (MacOnlyCipher c) = c
|
2011-04-17 05:34:28 +00:00
|
|
|
|
2013-09-05 02:18:33 +00:00
|
|
|
{- Creates a new Cipher, encrypted to the specified key id. -}
|
2024-01-12 17:29:34 +00:00
|
|
|
genEncryptedCipher :: LensEncParams c => Gpg.GpgCmd -> c -> Gpg.KeyId -> EncryptedCipherVariant -> Bool -> IO StorableCipher
|
2016-05-23 21:48:15 +00:00
|
|
|
genEncryptedCipher cmd c keyid variant highQuality = do
|
2015-09-09 22:06:49 +00:00
|
|
|
ks <- Gpg.findPubKeys cmd keyid
|
|
|
|
random <- Gpg.genRandom cmd highQuality size
|
2016-05-23 21:48:15 +00:00
|
|
|
encryptCipher cmd c (mkCipher random) variant ks
|
2013-09-01 18:12:00 +00:00
|
|
|
where
|
2013-09-05 06:09:39 +00:00
|
|
|
(mkCipher, size) = case variant of
|
2013-09-05 15:12:01 +00:00
|
|
|
Hybrid -> (Cipher, cipherSize) -- used for MAC + symmetric
|
|
|
|
PubKey -> (MacOnlyCipher, cipherBeginning) -- only used for MAC
|
2012-04-29 18:02:18 +00:00
|
|
|
|
|
|
|
{- Creates a new, shared Cipher. -}
|
2015-09-09 22:06:49 +00:00
|
|
|
genSharedCipher :: Gpg.GpgCmd -> Bool -> IO StorableCipher
|
|
|
|
genSharedCipher cmd highQuality =
|
|
|
|
SharedCipher <$> Gpg.genRandom cmd highQuality cipherSize
|
2012-04-29 18:02:18 +00:00
|
|
|
|
2016-05-10 20:50:31 +00:00
|
|
|
{- Creates a new, shared Cipher, and looks up the gpg public key that will
|
|
|
|
- be used for encrypting content. -}
|
|
|
|
genSharedPubKeyCipher :: Gpg.GpgCmd -> Gpg.KeyId -> Bool -> IO StorableCipher
|
|
|
|
genSharedPubKeyCipher cmd keyid highQuality = do
|
|
|
|
ks <- Gpg.findPubKeys cmd keyid
|
|
|
|
random <- Gpg.genRandom cmd highQuality cipherSize
|
|
|
|
return $ SharedPubKeyCipher random ks
|
|
|
|
|
|
|
|
{- Updates an existing Cipher, making changes to its keyids.
|
|
|
|
-
|
|
|
|
- When the Cipher is encrypted, re-encrypts it. -}
|
2024-01-12 17:29:34 +00:00
|
|
|
updateCipherKeyIds :: LensEncParams encparams => Gpg.GpgCmd -> encparams -> [(Bool, Gpg.KeyId)] -> StorableCipher -> IO StorableCipher
|
2016-11-16 01:29:54 +00:00
|
|
|
updateCipherKeyIds _ _ _ SharedCipher{} = giveup "Cannot update shared cipher"
|
2016-05-23 21:27:15 +00:00
|
|
|
updateCipherKeyIds _ _ [] c = return c
|
|
|
|
updateCipherKeyIds cmd encparams changes encipher@(EncryptedCipher _ variant ks) = do
|
2016-05-10 20:50:31 +00:00
|
|
|
ks' <- updateCipherKeyIds' cmd changes ks
|
2016-05-23 21:27:15 +00:00
|
|
|
cipher <- decryptCipher cmd encparams encipher
|
2016-05-23 21:48:15 +00:00
|
|
|
encryptCipher cmd encparams cipher variant ks'
|
2016-05-23 21:27:15 +00:00
|
|
|
updateCipherKeyIds cmd _ changes (SharedPubKeyCipher cipher ks) =
|
2016-05-10 20:50:31 +00:00
|
|
|
SharedPubKeyCipher cipher <$> updateCipherKeyIds' cmd changes ks
|
|
|
|
|
|
|
|
updateCipherKeyIds' :: Gpg.GpgCmd -> [(Bool, Gpg.KeyId)] -> KeyIds -> IO KeyIds
|
|
|
|
updateCipherKeyIds' cmd changes (KeyIds ks) = do
|
|
|
|
dropkeys <- listKeyIds [ k | (False, k) <- changes ]
|
|
|
|
forM_ dropkeys $ \k -> unless (k `elem` ks) $
|
2016-11-16 01:29:54 +00:00
|
|
|
giveup $ "Key " ++ k ++ " was not present; cannot remove."
|
2016-05-10 20:50:31 +00:00
|
|
|
addkeys <- listKeyIds [ k | (True, k) <- changes ]
|
|
|
|
let ks' = (addkeys ++ ks) \\ dropkeys
|
2013-09-05 01:54:10 +00:00
|
|
|
when (null ks') $
|
2016-11-16 01:29:54 +00:00
|
|
|
giveup "Cannot remove the last key."
|
2016-05-10 20:50:31 +00:00
|
|
|
return $ KeyIds ks'
|
2012-10-29 01:27:15 +00:00
|
|
|
where
|
2015-09-09 22:06:49 +00:00
|
|
|
listKeyIds = concat <$$> mapM (keyIds <$$> Gpg.findPubKeys cmd)
|
2011-04-15 22:18:39 +00:00
|
|
|
|
2013-09-05 02:18:33 +00:00
|
|
|
{- Encrypts a Cipher to the specified KeyIds. -}
|
2024-01-12 17:29:34 +00:00
|
|
|
encryptCipher :: LensEncParams c => Gpg.GpgCmd -> c -> Cipher -> EncryptedCipherVariant -> KeyIds -> IO StorableCipher
|
2016-05-23 21:48:15 +00:00
|
|
|
encryptCipher cmd c cip variant (KeyIds ks) = do
|
2013-03-12 09:05:33 +00:00
|
|
|
-- gpg complains about duplicate recipient keyids
|
|
|
|
let ks' = nub $ sort ks
|
2016-05-23 21:48:15 +00:00
|
|
|
let params = concat
|
|
|
|
[ getGpgEncParamsBase c
|
|
|
|
, Gpg.pkEncTo ks'
|
|
|
|
, Gpg.stdEncryptionParams False
|
|
|
|
]
|
2015-09-09 22:06:49 +00:00
|
|
|
encipher <- Gpg.pipeStrict cmd params cipher
|
2013-09-05 02:18:33 +00:00
|
|
|
return $ EncryptedCipher encipher variant (KeyIds ks')
|
2013-09-05 06:09:39 +00:00
|
|
|
where
|
2016-05-23 21:48:15 +00:00
|
|
|
cipher = case cip of
|
2013-09-05 06:09:39 +00:00
|
|
|
Cipher x -> x
|
|
|
|
MacOnlyCipher x -> x
|
2011-04-15 22:18:39 +00:00
|
|
|
|
|
|
|
{- Decrypting an EncryptedCipher is expensive; the Cipher should be cached. -}
|
2024-01-12 17:29:34 +00:00
|
|
|
decryptCipher :: LensEncParams c => Gpg.GpgCmd -> c -> StorableCipher -> IO Cipher
|
2022-05-18 19:32:40 +00:00
|
|
|
decryptCipher cmd c cip = decryptCipher' cmd Nothing c cip
|
|
|
|
|
2024-01-12 17:29:34 +00:00
|
|
|
decryptCipher' :: LensEncParams c => Gpg.GpgCmd -> Maybe [(String, String)] -> c -> StorableCipher -> IO Cipher
|
2022-05-18 19:32:40 +00:00
|
|
|
decryptCipher' _ _ _ (SharedCipher t) = return $ Cipher t
|
|
|
|
decryptCipher' _ _ _ (SharedPubKeyCipher t _) = return $ MacOnlyCipher t
|
|
|
|
decryptCipher' cmd environ c (EncryptedCipher t variant _) =
|
|
|
|
mkCipher <$> Gpg.pipeStrict' cmd params environ t
|
2013-09-05 06:09:39 +00:00
|
|
|
where
|
|
|
|
mkCipher = case variant of
|
2013-09-05 15:12:01 +00:00
|
|
|
Hybrid -> Cipher
|
|
|
|
PubKey -> MacOnlyCipher
|
2016-05-23 21:27:15 +00:00
|
|
|
params = Param "--decrypt" : getGpgDecParams c
|
2011-04-15 22:18:39 +00:00
|
|
|
|
2014-07-27 00:14:09 +00:00
|
|
|
type EncKey = Key -> Key
|
|
|
|
|
2011-04-16 20:26:47 +00:00
|
|
|
{- Generates an encrypted form of a Key. The encryption does not need to be
|
2023-03-14 02:39:16 +00:00
|
|
|
- reversible, nor does it need to be the same type of encryption used
|
2011-04-16 20:26:47 +00:00
|
|
|
- on content. It does need to be repeatable. -}
|
2014-07-27 00:14:09 +00:00
|
|
|
encryptKey :: Mac -> Cipher -> EncKey
|
2019-11-22 20:24:04 +00:00
|
|
|
encryptKey mac c k = mkKey $ \d -> d
|
2023-11-01 18:27:22 +00:00
|
|
|
{ keyName = S.toShort $ encodeBS $ macWithCipher mac c (serializeKey' k)
|
2019-01-11 20:34:04 +00:00
|
|
|
, keyVariety = OtherKey $
|
|
|
|
encryptedBackendNamePrefix <> encodeBS (showMac mac)
|
2011-04-16 20:26:47 +00:00
|
|
|
}
|
2011-04-15 22:18:39 +00:00
|
|
|
|
2019-01-11 20:34:04 +00:00
|
|
|
encryptedBackendNamePrefix :: S.ByteString
|
2014-08-03 20:54:57 +00:00
|
|
|
encryptedBackendNamePrefix = "GPG"
|
|
|
|
|
|
|
|
isEncKey :: Key -> Bool
|
2019-11-22 20:24:04 +00:00
|
|
|
isEncKey k = case fromKey keyVariety k of
|
2019-01-11 20:34:04 +00:00
|
|
|
OtherKey s -> encryptedBackendNamePrefix `S.isPrefixOf` s
|
2017-02-24 19:16:56 +00:00
|
|
|
_ -> False
|
2014-08-03 20:54:57 +00:00
|
|
|
|
2012-11-18 19:27:44 +00:00
|
|
|
type Feeder = Handle -> IO ()
|
2014-07-29 20:22:19 +00:00
|
|
|
type Reader m a = Handle -> m a
|
2012-11-18 19:27:44 +00:00
|
|
|
|
|
|
|
feedFile :: FilePath -> Feeder
|
|
|
|
feedFile f h = L.hPut h =<< L.readFile f
|
|
|
|
|
|
|
|
feedBytes :: L.ByteString -> Feeder
|
|
|
|
feedBytes = flip L.hPut
|
|
|
|
|
2014-07-29 20:22:19 +00:00
|
|
|
readBytes :: (MonadIO m) => (L.ByteString -> m a) -> Reader m a
|
|
|
|
readBytes a h = liftIO (L.hGetContents h) >>= a
|
2012-11-18 19:27:44 +00:00
|
|
|
|
2020-06-16 21:03:19 +00:00
|
|
|
readBytesStrictly :: (MonadIO m) => (S.ByteString -> m a) -> Reader m a
|
|
|
|
readBytesStrictly a h = liftIO (S.hGetContents h) >>= a
|
|
|
|
|
2013-09-01 18:12:00 +00:00
|
|
|
{- Runs a Feeder action, that generates content that is symmetrically
|
|
|
|
- encrypted with the Cipher (unless it is empty, in which case
|
2024-01-12 17:29:34 +00:00
|
|
|
- public-key encryption is used), and then read by the Reader action.
|
2020-06-16 21:03:19 +00:00
|
|
|
-
|
2024-01-12 17:29:34 +00:00
|
|
|
- Note that the Reader must fully consume all input before returning.
|
2020-06-16 21:03:19 +00:00
|
|
|
-}
|
2024-01-12 17:29:34 +00:00
|
|
|
encrypt :: (MonadIO m, MonadMask m, LensEncParams c) => Gpg.GpgCmd -> c -> Cipher -> Feeder -> Reader m a -> m a
|
|
|
|
encrypt gpgcmd c cipher feeder reader = case cipher of
|
|
|
|
Cipher{} ->
|
|
|
|
let passphrase = cipherPassphrase cipher
|
|
|
|
in case statelessOpenPGPCommand c of
|
|
|
|
Just sopcmd -> withTmpDir "sop" $ \d ->
|
|
|
|
SOP.encryptSymmetric sopcmd passphrase
|
|
|
|
(SOP.EmptyDirectory d)
|
|
|
|
(statelessOpenPGPProfile c)
|
|
|
|
(SOP.Armoring False)
|
|
|
|
feeder reader
|
|
|
|
Nothing -> Gpg.feedRead gpgcmd (params ++ Gpg.stdEncryptionParams True) passphrase feeder reader
|
|
|
|
MacOnlyCipher{} -> Gpg.feedRead' gpgcmd (params ++ Gpg.stdEncryptionParams False) feeder reader
|
2016-05-23 21:03:20 +00:00
|
|
|
where
|
|
|
|
params = getGpgEncParams c
|
2012-11-18 19:27:44 +00:00
|
|
|
|
|
|
|
{- Runs a Feeder action, that generates content that is decrypted with the
|
2013-09-01 18:12:00 +00:00
|
|
|
- Cipher (or using a private key if the Cipher is empty), and read by the
|
2020-06-16 21:03:19 +00:00
|
|
|
- Reader action.
|
|
|
|
-
|
2024-01-12 17:29:34 +00:00
|
|
|
- Note that the Reader must fully consume all input before returning.
|
2020-06-16 21:03:19 +00:00
|
|
|
- -}
|
2024-01-12 17:29:34 +00:00
|
|
|
decrypt :: (MonadIO m, MonadMask m, LensEncParams c) => Gpg.GpgCmd -> c -> Cipher -> Feeder -> Reader m a -> m a
|
|
|
|
decrypt cmd c cipher feeder reader = case cipher of
|
|
|
|
Cipher{} ->
|
|
|
|
let passphrase = cipherPassphrase cipher
|
|
|
|
in case statelessOpenPGPCommand c of
|
|
|
|
Just sopcmd -> withTmpDir "sop" $ \d ->
|
|
|
|
SOP.decryptSymmetric sopcmd passphrase
|
|
|
|
(SOP.EmptyDirectory d)
|
|
|
|
feeder reader
|
|
|
|
Nothing -> Gpg.feedRead cmd params passphrase feeder reader
|
|
|
|
MacOnlyCipher{} -> Gpg.feedRead' cmd params feeder reader
|
2016-05-10 17:03:56 +00:00
|
|
|
where
|
2016-05-23 21:51:15 +00:00
|
|
|
params = Param "--decrypt" : getGpgDecParams c
|
2011-04-15 22:18:39 +00:00
|
|
|
|
2023-11-01 18:27:22 +00:00
|
|
|
macWithCipher :: Mac -> Cipher -> S.ByteString -> String
|
2013-03-29 16:06:02 +00:00
|
|
|
macWithCipher mac c = macWithCipher' mac (cipherMac c)
|
2023-11-01 18:27:22 +00:00
|
|
|
macWithCipher' :: Mac -> S.ByteString -> S.ByteString -> String
|
2024-08-10 20:32:54 +00:00
|
|
|
macWithCipher' mac c s = calcMac show mac c s
|
2011-04-21 20:56:24 +00:00
|
|
|
|
2013-03-29 16:06:02 +00:00
|
|
|
{- Ensure that macWithCipher' returns the same thing forevermore. -}
|
|
|
|
prop_HmacSha1WithCipher_sane :: Bool
|
|
|
|
prop_HmacSha1WithCipher_sane = known_good == macWithCipher' HmacSha1 "foo" "bar"
|
2012-10-29 01:27:15 +00:00
|
|
|
where
|
|
|
|
known_good = "46b4ec586117154dacd49d664e5d63fdc88efb51"
|
2013-09-05 03:16:33 +00:00
|
|
|
|
2024-01-12 17:29:34 +00:00
|
|
|
class LensEncParams a where
|
|
|
|
{- Base gpg parameters for encrypting. Does not include specification
|
2016-05-23 21:48:15 +00:00
|
|
|
- of recipient keys. -}
|
|
|
|
getGpgEncParamsBase :: a -> [CommandParam]
|
2024-01-12 17:29:34 +00:00
|
|
|
{- Gpg parameters for encrypting. When the remote is configured to use
|
2016-05-23 21:48:15 +00:00
|
|
|
- public-key encryption, includes specification of recipient keys. -}
|
2016-05-10 17:03:56 +00:00
|
|
|
getGpgEncParams :: a -> [CommandParam]
|
2024-01-12 17:29:34 +00:00
|
|
|
{- Gpg parameters for decrypting. -}
|
2016-05-10 17:03:56 +00:00
|
|
|
getGpgDecParams :: a -> [CommandParam]
|
2024-01-12 17:29:34 +00:00
|
|
|
{- Set when stateless OpenPGP should be used rather than gpg.
|
|
|
|
- It is currently only used for SharedEncryption and not the other
|
|
|
|
- schemes which use public keys. -}
|
|
|
|
statelessOpenPGPCommand :: a -> Maybe SOP.SOPCmd
|
|
|
|
{- When using stateless OpenPGP, this may be set to a profile
|
|
|
|
- which should be used instead of the default. -}
|
|
|
|
statelessOpenPGPProfile :: a -> Maybe SOP.SOPProfile
|
2013-09-05 03:16:33 +00:00
|
|
|
|
|
|
|
{- Extract the GnuPG options from a pair of a Remote Config and a Remote
|
2014-02-06 22:25:31 +00:00
|
|
|
- Git Config. -}
|
2024-01-12 17:29:34 +00:00
|
|
|
instance LensEncParams (ParsedRemoteConfig, RemoteGitConfig) where
|
2016-05-23 21:48:15 +00:00
|
|
|
getGpgEncParamsBase (_c,gc) = map Param (remoteAnnexGnupgOptions gc)
|
|
|
|
getGpgEncParams (c,gc) = getGpgEncParamsBase (c,gc) ++
|
2016-05-23 21:03:20 +00:00
|
|
|
{- When the remote is configured to use public-key encryption,
|
|
|
|
- look up the recipient keys and add them to the option list. -}
|
2020-01-13 16:35:39 +00:00
|
|
|
case getRemoteConfigValue encryptionField c of
|
|
|
|
Just PubKeyEncryption ->
|
|
|
|
Gpg.pkEncTo $ maybe [] (splitc ',') $
|
|
|
|
getRemoteConfigValue cipherkeysField c
|
|
|
|
Just SharedPubKeyEncryption ->
|
|
|
|
Gpg.pkEncTo $ maybe [] (splitc ',') $
|
|
|
|
getRemoteConfigValue pubkeysField c
|
2016-05-23 21:03:20 +00:00
|
|
|
_ -> []
|
|
|
|
getGpgDecParams (_c,gc) = map Param (remoteAnnexGnupgDecryptOptions gc)
|
2024-01-12 17:29:34 +00:00
|
|
|
statelessOpenPGPCommand (c,gc) = case remoteAnnexSharedSOPCommand gc of
|
|
|
|
Nothing -> Nothing
|
|
|
|
Just sopcmd ->
|
|
|
|
{- So far stateless OpenPGP is only supported
|
|
|
|
- for SharedEncryption, not other encryption
|
|
|
|
- methods that involve public keys. -}
|
|
|
|
case getRemoteConfigValue encryptionField c of
|
|
|
|
Just SharedEncryption -> Just sopcmd
|
|
|
|
_ -> Nothing
|
|
|
|
statelessOpenPGPProfile (_c,gc) = remoteAnnexSharedSOPProfile gc
|
2013-09-05 03:16:33 +00:00
|
|
|
|
|
|
|
{- Extract the GnuPG options from a Remote. -}
|
2024-01-12 17:29:34 +00:00
|
|
|
instance LensEncParams (RemoteA a) where
|
2016-05-23 21:48:15 +00:00
|
|
|
getGpgEncParamsBase r = getGpgEncParamsBase (config r, gitconfig r)
|
2013-09-05 03:16:33 +00:00
|
|
|
getGpgEncParams r = getGpgEncParams (config r, gitconfig r)
|
2016-05-10 17:03:56 +00:00
|
|
|
getGpgDecParams r = getGpgDecParams (config r, gitconfig r)
|
2024-01-12 17:29:34 +00:00
|
|
|
statelessOpenPGPCommand r = statelessOpenPGPCommand (config r, gitconfig r)
|
|
|
|
statelessOpenPGPProfile r = statelessOpenPGPProfile (config r, gitconfig r)
|