summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2020-05-19 17:40:39 -0400
committerJoe Crayne <joe@jerkface.net>2020-05-24 14:11:07 -0400
commit9cc0b24375b6b40eb7c3412983e75b6e3fe3a3f6 (patch)
tree88e7add38a551703db90abd6287bc5878c184863 /lib
parenta3a517892426b0fb2cffbfcca5f749f06d710842 (diff)
Commandline option to use v5 key packets.
Diffstat (limited to 'lib')
-rw-r--r--lib/KeyRing.hs3
-rw-r--r--lib/KeyRing/BuildKeyDB.hs3
-rw-r--r--lib/KeyRing/Types.hs9
-rw-r--r--lib/Kiki.hs15
4 files changed, 19 insertions, 11 deletions
diff --git a/lib/KeyRing.hs b/lib/KeyRing.hs
index 5b51a93..9669430 100644
--- a/lib/KeyRing.hs
+++ b/lib/KeyRing.hs
@@ -87,8 +87,7 @@ import KeyRing.BuildKeyDB (allNames', Hostnames,
87 readSecretPEMFile, 87 readSecretPEMFile,
88 secp256k1_id, 88 secp256k1_id,
89 selectPublicKey, 89 selectPublicKey,
90 usageFromFilter, 90 usageFromFilter)
91 preferredPGPVersion)
92 91
93import KeyRing.Types 92import KeyRing.Types
94import KeyDB 93import KeyDB
diff --git a/lib/KeyRing/BuildKeyDB.hs b/lib/KeyRing/BuildKeyDB.hs
index c2b2703..3993c66 100644
--- a/lib/KeyRing/BuildKeyDB.hs
+++ b/lib/KeyRing/BuildKeyDB.hs
@@ -79,9 +79,6 @@ import GnuPGAgent
79import ByteStringUtil 79import ByteStringUtil
80import Text.XXD 80import Text.XXD
81 81
82preferredPGPVersion :: KeyRingOperation -> Word8
83preferredPGPVersion _ = 4 -- TODO: v5
84
85newtype IPsToWriteToHostsFile = IPsToWriteToHostsFile [SockAddr] 82newtype IPsToWriteToHostsFile = IPsToWriteToHostsFile [SockAddr]
86-- | buildKeyDB 83-- | buildKeyDB
87-- 84--
diff --git a/lib/KeyRing/Types.hs b/lib/KeyRing/Types.hs
index dbcc22c..c272efc 100644
--- a/lib/KeyRing/Types.hs
+++ b/lib/KeyRing/Types.hs
@@ -32,13 +32,16 @@ data KeyRingOperation = KeyRingOperation
32 -- ^ If provided, this is the directory where the 'HomeSec' and 'HomePub' 32 -- ^ If provided, this is the directory where the 'HomeSec' and 'HomePub'
33 -- files reside. Otherwise, the evironment variable $GNUPGHOME is consulted 33 -- files reside. Otherwise, the evironment variable $GNUPGHOME is consulted
34 -- and if that is not set, it falls back to $HOME/.gnupg. 34 -- and if that is not set, it falls back to $HOME/.gnupg.
35 , preferredPGPVersion :: Word8
36 -- ^ Newly created PGP key packets will use this version. It should be set
37 -- to either 4 or 5.
35 } 38 }
36 deriving (Eq,Show) 39 deriving (Eq,Show)
37instance Semigroup KeyRingOperation where 40instance Semigroup KeyRingOperation where
38 KeyRingOperation f p t h <> KeyRingOperation f' p' t' h' = 41 KeyRingOperation f p t h v <> KeyRingOperation f' p' t' h' v' =
39 KeyRingOperation (f <> f') (p <> p') (t <> t') (h <> h') 42 KeyRingOperation (f <> f') (p <> p') (t <> t') (h <> h') (max v v')
40instance Monoid KeyRingOperation where 43instance Monoid KeyRingOperation where
41 mempty = KeyRingOperation Map.empty [] [] Nothing 44 mempty = KeyRingOperation Map.empty [] [] Nothing 4
42 45
43data InputFile = HomeSec 46data InputFile = HomeSec
44 -- ^ A file named secring.gpg located in the home directory. 47 -- ^ A file named secring.gpg located in the home directory.
diff --git a/lib/Kiki.hs b/lib/Kiki.hs
index 222c1bb..a0e2d07 100644
--- a/lib/Kiki.hs
+++ b/lib/Kiki.hs
@@ -152,6 +152,7 @@ minimalOp isHomeless cap = op
152 return $ PassphraseSpec Nothing Nothing pfile 152 return $ PassphraseSpec Nothing Nothing pfile
153 , opTransforms = [] 153 , opTransforms = []
154 , opHome = cap_homespec cap 154 , opHome = cap_homespec cap
155 , preferredPGPVersion = 4
155 } 156 }
156 157
157run :: [String] -> Args (IO ()) -> IO () 158run :: [String] -> Args (IO ()) -> IO ()
@@ -203,8 +204,8 @@ peminfo bits usage = StreamInfo
203 , transforms = [] 204 , transforms = []
204 } 205 }
205 206
206importAndRefresh :: (FilePath -> FilePath) -> CommonArgsParsed -> SymmetricAlgorithm -> IO () 207importAndRefresh :: Word8 -> (FilePath -> FilePath) -> CommonArgsParsed -> SymmetricAlgorithm -> IO ()
207importAndRefresh root cmn cipher = do 208importAndRefresh pgpver root cmn cipher = do
208 let rootdir = do guard (root "x" /= "x") 209 let rootdir = do guard (root "x" /= "x")
209 Just $ root "" 210 Just $ root ""
210 me <- getEffectiveUserID 211 me <- getEffectiveUserID
@@ -214,7 +215,6 @@ importAndRefresh root cmn cipher = do
214 let homespec = mplus (slash <$> rootdir <*> cap_homespec cmn) 215 let homespec = mplus (slash <$> rootdir <*> cap_homespec cmn)
215 (fmap (++"/root/.gnupg") rootdir) 216 (fmap (++"/root/.gnupg") rootdir)
216 passfd = cap_passfd cmn 217 passfd = cap_passfd cmn
217 pgpver = preferredPGPVersion $ minimalOp False cmn
218 (home,secring,pubring,mbwk) <- unconditionally $ getHomeDir homespec 218 (home,secring,pubring,mbwk) <- unconditionally $ getHomeDir homespec
219 osHomeDir <- if bUnprivileged then getHomeDirectory else return "/root" 219 osHomeDir <- if bUnprivileged then getHomeDirectory else return "/root"
220 220
@@ -326,6 +326,7 @@ importAndRefresh root cmn cipher = do
326 return $ PassphraseSpec Nothing Nothing pfd 326 return $ PassphraseSpec Nothing Nothing pfd
327 , opHome = homespec 327 , opHome = homespec
328 , opTransforms = [] 328 , opTransforms = []
329 , preferredPGPVersion = pgpver
329 } 330 }
330 nop = 331 nop =
331 KeyRingOperation 332 KeyRingOperation
@@ -340,6 +341,7 @@ importAndRefresh root cmn cipher = do
340 return $ PassphraseSpec Nothing Nothing pfd 341 return $ PassphraseSpec Nothing Nothing pfd
341 , opHome=homespec 342 , opHome=homespec
342 , opTransforms = [] 343 , opTransforms = []
344 , preferredPGPVersion = pgpver
343 } 345 }
344 when bUnprivileged $ do 346 when bUnprivileged $ do
345 hPutStrLn stderr "Insufficient privilege generating system service keys." 347 hPutStrLn stderr "Insufficient privilege generating system service keys."
@@ -473,6 +475,7 @@ generateHostsFile fw rt = do
473 , opPassphrases = [] 475 , opPassphrases = []
474 , opHome = Just $ takeDirectory (rtPubring rt) 476 , opHome = Just $ takeDirectory (rtPubring rt)
475 , opTransforms = [] 477 , opTransforms = []
478 , preferredPGPVersion = 4 -- Does not matter (no fill of pgp files).
476 } 479 }
477 KikiResult _ report <- runKeyRing op 480 KikiResult _ report <- runKeyRing op
478 outputReport report 481 outputReport report
@@ -723,6 +726,12 @@ slash "" ('/':xs) = '/':xs
723slash "" xs = '/':xs 726slash "" xs = '/':xs
724slash (y:ys) xs = y:slash ys xs 727slash (y:ys) xs = y:slash ys xs
725 728
729dashdashPGPVersion :: Args Word8
730dashdashPGPVersion = liftA2 (\is4 is5 -> if is5 then 5 else if is4 then 4 else defaultV) (flag "-4") (flag "-5")
731 where
732 defaultV = 4 -- Use v4 packets by default for now.
733
734
726dashdashChroot :: Args (FilePath -> FilePath) 735dashdashChroot :: Args (FilePath -> FilePath)
727dashdashChroot = pure (\r a -> slash r a) <*> arg "--chroot" <|> pure id 736dashdashChroot = pure (\r a -> slash r a) <*> arg "--chroot" <|> pure id
728 737