From 18637eab484c36632b752237b1dd5b1545716254 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Wed, 10 Jul 2019 06:24:47 -0400 Subject: have the write functions call mkpath --- lib/Kiki.hs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/Kiki.hs b/lib/Kiki.hs index e782d8a..cb77e2a 100644 --- a/lib/Kiki.hs +++ b/lib/Kiki.hs @@ -333,14 +333,14 @@ installIpsecPeerCertificate :: FileWriter -> (L.ByteString, SockAddr, KeyData) -> IO Char8.ByteString -installIpsecPeerCertificate fw@(FileWriter mkpath _) (contactname,addr,kd) = +installIpsecPeerCertificate fw (contactname,addr,kd) = Char8.concat <$> do forM (take 1 ipsecs) $ \k -> do flip (either warn') (pemFromPacket k :: Either String String) $ \pem -> do case sshs of (sshkey:_) -> do theirHostname <- sshKeyToHostname sshkey - write fw (mkpath $ ipsecCertPath theirHostname) pem + write fw (ipsecCertPath theirHostname) pem return $ strongswanPeerConfiguration addr contactname theirHostname _ -> error "fuck." where @@ -368,7 +368,7 @@ ipsecCertPath :: Char8.ByteString -> FilePath ipsecCertPath = ipsecPath "certs" write' :: FileWriter -> (FilePath -> t -> IO b) -> FilePath -> t -> IO b -write' fw wr f bs = do +write' fw@(FileWriter mkpath _) wr (mkpath -> f) bs = do createDirectoryIfMissing True $ takeDirectory f wr f bs @@ -421,8 +421,8 @@ getMkPathAndCommit destdir = do -- return (mkpath pth) return $ FileWriter mkpath commit -generateHostsFile :: (FilePath -> FilePath) -> KeyRingRuntime -> IO () -generateHostsFile mkpath rt = do +generateHostsFile :: FileWriter -> KeyRingRuntime -> IO () +generateHostsFile (FileWriter mkpath _) rt = do let hostspath = mkpath "hosts" op = KeyRingOperation { opFiles = Map.fromList $ @@ -453,9 +453,9 @@ getssh (contactname,_addr,kd) = do installIpsecConf :: FileWriter -> SockAddr -> Char8.ByteString -> [(Char8.ByteString, SockAddr, KeyData)] -> IO () -installIpsecConf fw@(FileWriter mkpath _) wkaddr (certBasename) cs = do +installIpsecConf fw wkaddr (certBasename) cs = do snippets <- mapM (installIpsecPeerCertificate fw) cs - writeL fw (mkpath "ipsec.conf") . Char8.unlines + writeL fw "ipsec.conf" . Char8.unlines $ [ "conn %default" , " ikelifetime=60m" , " keylife=20m" @@ -480,8 +480,8 @@ installIpsecConf fw@(FileWriter mkpath _) wkaddr (certBasename) cs = do refreshCache :: KeyRingRuntime -> Maybe FilePath -> IO () refreshCache rt rootdir = do - fw@(FileWriter mkpath commit) <- getMkPathAndCommit (fromMaybe "" rootdir ++ "/var/cache/kiki/config") - generateHostsFile mkpath rt + fw@(FileWriter mkpath _) <- getMkPathAndCommit (fromMaybe "" rootdir ++ "/var/cache/kiki/config") + generateHostsFile fw rt fromMaybe (error "No working key.") $ do Hostnames wkaddr onames _ _ <- names rt Just $ do @@ -525,12 +525,12 @@ rethrowKikiErrors BadPassphrase = rethrowKikiErrors rt = unconditionally $ return rt writePublicKeyFiles :: KeyRingRuntime -> FileWriter -> String -> Char8.ByteString -> SockAddr -> IO () -writePublicKeyFiles rt fw@(FileWriter mkpath commit) grip oname wkaddr = do +writePublicKeyFiles rt fw@(FileWriter _ commit) grip oname wkaddr = do -- Finally, export public keys if they do not exist. - either warn (write fw $ mkpath "root/.ssh/id_rsa.pub") $ show_ssh' "ssh-client" grip (rtKeyDB rt) - either warn (write fw $ mkpath "ssh_host_rsa_key.pub") $ show_ssh' "ssh-server" grip (rtKeyDB rt) - either warn (write fw $ mkpath $ ipsecCertPath oname) $ show_pem' "ipsec" grip (rtKeyDB rt) pemFromPacket + either warn (write fw "root/.ssh/id_rsa.pub") $ show_ssh' "ssh-client" grip (rtKeyDB rt) + either warn (write fw "ssh_host_rsa_key.pub") $ show_ssh' "ssh-server" grip (rtKeyDB rt) + either warn (write fw $ ipsecCertPath oname) $ show_pem' "ipsec" grip (rtKeyDB rt) pemFromPacket let onionkeys = mapMaybe namedContact $ Map.elems $ rtKeyDB rt cs = filter (\(_,_,kd) -> notme kd) onionkeys @@ -545,7 +545,7 @@ writePublicKeyFiles rt fw@(FileWriter mkpath commit) grip oname wkaddr = do known_hosts = L.concat $ map getssh onionkeys - writeL fw (mkpath "ssh_known_hosts") known_hosts + writeL fw "ssh_known_hosts" known_hosts installIpsecConf fw wkaddr (Char8.pack $ takeBaseName $ ipsecCertPath oname) cs commit -- cgit v1.2.3