initremote: Prevent enabling encryption with exporttree=yes/importtree=yes
authorJoey Hess <joeyh@joeyh.name>
Tue, 15 Dec 2020 16:08:08 +0000 (12:08 -0400)
committerJoey Hess <joeyh@joeyh.name>
Tue, 15 Dec 2020 16:08:08 +0000 (12:08 -0400)
I do think this was a reversion, but I have not tracked back to what
version. While involving the remote config, it's not the same class of
problems that I kept having to chase down for a while after the remote
config parser reworking.

CHANGELOG
Remote/Helper/Encryptable.hs
Remote/Helper/ExportImport.hs
doc/bugs/initremote_with_export_and_import_allowed_with_encryption.mdwn

index c8aa120ea70e9148867824a57243a21a0378f270..b91d58eaba98bf288d8dba8aed32ab1e894e259a 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -22,6 +22,7 @@ git-annex (8.20201128) UNRELEASED; urgency=medium
     current directory, rather than the path from the top of the repository.
   * importfeed: Avoid using youtube-dl when a feed does not contain an
     enclosure, but only a link to an url which youtube-dl does not support.
+  * initremote: Prevent enabling encryption with exporttree=yes/importtree=yes.
 
  -- Joey Hess <id@joeyh.name>  Mon, 30 Nov 2020 12:55:49 -0400
 
index 25980a937df571b99b569424235047bf01c5be0c..296f3836c757a5e26332f4da5464686fe099742d 100644 (file)
@@ -20,6 +20,7 @@ module Remote.Helper.Encryptable (
        cipherKey,
        extractCipher,
        isEncrypted,
+       encryptionIsEnabled,
        describeEncryption,
        encryptionField,
        highRandomQualityField
@@ -282,6 +283,14 @@ extractCipher c = case (getRemoteConfigValue cipherField c,
 isEncrypted :: ParsedRemoteConfig -> Bool
 isEncrypted = isJust . extractCipher
 
+-- Check if encryption is enabled. This can be done before encryption
+-- is fully set up yet, so the cipher might not be present yet.
+encryptionIsEnabled :: ParsedRemoteConfig -> Bool
+encryptionIsEnabled c = case getRemoteConfigValue encryptionField c of
+       Nothing -> False
+       Just NoneEncryption -> False
+       Just _ -> True
+
 describeEncryption :: ParsedRemoteConfig -> String
 describeEncryption c = case extractCipher c of
        Nothing -> "none"
index 245b7a940f54b55b1b3ded1538649a698e8c46f4..27b63bab4d3fd0fd06c5f2aa7d10d7afd6966e4f 100644 (file)
@@ -14,7 +14,7 @@ import Types.Remote
 import Types.Key
 import Types.ProposedAccepted
 import Backend
-import Remote.Helper.Encryptable (isEncrypted)
+import Remote.Helper.Encryptable (encryptionIsEnabled)
 import qualified Database.Export as Export
 import qualified Database.ContentIdentifier as ContentIdentifier
 import Annex.Export
@@ -83,7 +83,7 @@ adjustExportImportRemoteType rt = rt { setup = setup' }
                        ifM (supported rt pc gc)
                                ( case st of
                                        Init
-                                               | configured pc && isEncrypted pc ->
+                                               | configured pc && encryptionIsEnabled pc ->
                                                        giveup $ "cannot enable both encryption and " ++ fromProposedAccepted configfield
                                                | otherwise -> cont
                                        Enable oldc -> do
index ef3ac00a2f92baab4c3804a87a4a7d676d0308fc..8f1a6b0cd0ab9e6cb69f5e040429d965e6265019 100644 (file)
@@ -4,3 +4,5 @@ This should be rejected, but currently succeeds:
 
 There is code in adjustExportImportRemoteType, and I remember it used to
 work. --[[Joey]]
+
+> [[fixed|done]] --[[Joey]]