From 9fa0ed75d7607bf534d25f2deea8c78835fabe02 Mon Sep 17 00:00:00 2001 From: joe Date: Thu, 31 Jul 2014 22:56:17 -0400 Subject: interpolation code --- kiki.hs | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'kiki.hs') diff --git a/kiki.hs b/kiki.hs index 4266ac5..fe8593e 100644 --- a/kiki.hs +++ b/kiki.hs @@ -1160,11 +1160,16 @@ kiki "init-key" args = do writeInputFileL (InputFileContext secring pubring) HomePub ( encode $ Message [] ) + + -- TODO: These should be read from a configuration file + let torpath = fromMaybe "" rootdir ++ "/var/lib/tor/samizdat/private_key" + sshcpath0 = fromMaybe "" rootdir ++ "/root/.ssh/id_rsa" + sshspath0 = fromMaybe "" rootdir ++ "/etc/ssh/ssh_host_rsa_key" + ipsecpath0 = fromMaybe "" rootdir ++ "/etc/ipsec.d/private/%(onion).pem" -- First, we ensure that the tor key exists and is imported -- so that we know where to put the strongswan key. - let torpath = fromMaybe "" rootdir ++ "/var/lib/tor/samizdat/private_key" - passfd = fmap (FileDesc . read) $ lookup "passphrase-fd" args + let passfd = fmap (FileDesc . read) $ lookup "passphrase-fd" args buildStreamInfo rtyp ftyp = StreamInfo { typ = ftyp , fill = rtyp , spill = KF_All @@ -1199,10 +1204,10 @@ kiki "init-key" args = do let oname = do wk <- rtWorkingKey rt onionNameForContact (keykey wk) (rtKeyDB rt) flip (maybe $ error "Missing tor key") oname $ \oname -> do - let sshcpath = fromMaybe "" rootdir ++ "/root/.ssh/id_rsa" - sshspath = fromMaybe "" rootdir ++ "/etc/ssh/ssh_host_rsa_key" - ipsecpath = fromMaybe "" rootdir ++ "/etc/ipsec.d/private/"++oname++".pem" - op2 = op + let [ sshcpath , sshspath , ipsecpath ] + = map (interp (Map.fromList [("onion",oname)])) + [ sshcpath0, sshspath0, ipsecpath0 ] + let op2 = op { opFiles = Map.fromList $ [ ( HomeSec, buildStreamInfo KF_All KeyRingFile ) , ( HomePub, (buildStreamInfo KF_All KeyRingFile) { access = Pub } ) @@ -1253,6 +1258,17 @@ commands = , ( "init-key", "initialize the samizdat key ring") ] +interp vars raw = es >>= interp1 + where + gs = groupBy (\_ c -> c/='%') raw + es = dropWhile null $ gobbleEscapes ("":gs) + where gobbleEscapes (a:"%":b:bs) = (a++b) : gobbleEscapes bs + gobbleEscapes (g:gs) = g : gobbleEscapes gs + gobbleEscapes [] = [] + interp1 ('%':'(':str) = fromMaybe "" (Map.lookup key vars) ++ drop 1 rest + where (key,rest) = break (==')') str + interp1 plain = plain + main = do dotlock_init args_raw <- getArgs -- cgit v1.2.3