summaryrefslogtreecommitdiff
path: root/kiki.hs
diff options
context:
space:
mode:
Diffstat (limited to 'kiki.hs')
-rw-r--r--kiki.hs28
1 files changed, 22 insertions, 6 deletions
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
1160 writeInputFileL (InputFileContext secring pubring) 1160 writeInputFileL (InputFileContext secring pubring)
1161 HomePub 1161 HomePub
1162 ( encode $ Message [] ) 1162 ( encode $ Message [] )
1163
1164 -- TODO: These should be read from a configuration file
1165 let torpath = fromMaybe "" rootdir ++ "/var/lib/tor/samizdat/private_key"
1166 sshcpath0 = fromMaybe "" rootdir ++ "/root/.ssh/id_rsa"
1167 sshspath0 = fromMaybe "" rootdir ++ "/etc/ssh/ssh_host_rsa_key"
1168 ipsecpath0 = fromMaybe "" rootdir ++ "/etc/ipsec.d/private/%(onion).pem"
1163 1169
1164 -- First, we ensure that the tor key exists and is imported 1170 -- First, we ensure that the tor key exists and is imported
1165 -- so that we know where to put the strongswan key. 1171 -- so that we know where to put the strongswan key.
1166 let torpath = fromMaybe "" rootdir ++ "/var/lib/tor/samizdat/private_key" 1172 let passfd = fmap (FileDesc . read) $ lookup "passphrase-fd" args
1167 passfd = fmap (FileDesc . read) $ lookup "passphrase-fd" args
1168 buildStreamInfo rtyp ftyp = StreamInfo { typ = ftyp 1173 buildStreamInfo rtyp ftyp = StreamInfo { typ = ftyp
1169 , fill = rtyp 1174 , fill = rtyp
1170 , spill = KF_All 1175 , spill = KF_All
@@ -1199,10 +1204,10 @@ kiki "init-key" args = do
1199 let oname = do wk <- rtWorkingKey rt 1204 let oname = do wk <- rtWorkingKey rt
1200 onionNameForContact (keykey wk) (rtKeyDB rt) 1205 onionNameForContact (keykey wk) (rtKeyDB rt)
1201 flip (maybe $ error "Missing tor key") oname $ \oname -> do 1206 flip (maybe $ error "Missing tor key") oname $ \oname -> do
1202 let sshcpath = fromMaybe "" rootdir ++ "/root/.ssh/id_rsa" 1207 let [ sshcpath , sshspath , ipsecpath ]
1203 sshspath = fromMaybe "" rootdir ++ "/etc/ssh/ssh_host_rsa_key" 1208 = map (interp (Map.fromList [("onion",oname)]))
1204 ipsecpath = fromMaybe "" rootdir ++ "/etc/ipsec.d/private/"++oname++".pem" 1209 [ sshcpath0, sshspath0, ipsecpath0 ]
1205 op2 = op 1210 let op2 = op
1206 { opFiles = Map.fromList $ 1211 { opFiles = Map.fromList $
1207 [ ( HomeSec, buildStreamInfo KF_All KeyRingFile ) 1212 [ ( HomeSec, buildStreamInfo KF_All KeyRingFile )
1208 , ( HomePub, (buildStreamInfo KF_All KeyRingFile) { access = Pub } ) 1213 , ( HomePub, (buildStreamInfo KF_All KeyRingFile) { access = Pub } )
@@ -1253,6 +1258,17 @@ commands =
1253 , ( "init-key", "initialize the samizdat key ring") 1258 , ( "init-key", "initialize the samizdat key ring")
1254 ] 1259 ]
1255 1260
1261interp vars raw = es >>= interp1
1262 where
1263 gs = groupBy (\_ c -> c/='%') raw
1264 es = dropWhile null $ gobbleEscapes ("":gs)
1265 where gobbleEscapes (a:"%":b:bs) = (a++b) : gobbleEscapes bs
1266 gobbleEscapes (g:gs) = g : gobbleEscapes gs
1267 gobbleEscapes [] = []
1268 interp1 ('%':'(':str) = fromMaybe "" (Map.lookup key vars) ++ drop 1 rest
1269 where (key,rest) = break (==')') str
1270 interp1 plain = plain
1271
1256main = do 1272main = do
1257 dotlock_init 1273 dotlock_init
1258 args_raw <- getArgs 1274 args_raw <- getArgs