summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2019-06-22 19:04:04 -0400
committerJoe Crayne <joe@jerkface.net>2019-07-01 06:03:24 -0400
commit01c15153208afc08092fd7c708ab2da85588e0de (patch)
treea07a534381eac2fa9f484033696b49ce94ca2252 /lib
parentb0d560708f5fd7b244ce4b98973a1378f15963d0 (diff)
alter strongswan configured hostname
Diffstat (limited to 'lib')
-rw-r--r--lib/Kiki.hs22
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/Kiki.hs b/lib/Kiki.hs
index c1dd587..2198fb7 100644
--- a/lib/Kiki.hs
+++ b/lib/Kiki.hs
@@ -510,14 +510,9 @@ refreshCache rt rootdir = do
510 let warn' x = warn x >> return Char8.empty 510 let warn' x = warn x >> return Char8.empty
511 flip (either warn') (pemFromPacket k :: Either String String) $ \pem -> do 511 flip (either warn') (pemFromPacket k :: Either String String) $ \pem -> do
512 write (mkpath cpath) pem 512 write (mkpath cpath) pem
513 case take 1 sshs of 513 case sshs of
514 [sshkey] -> do 514 (sshkey:_) -> strongswanForContact addr contactname <$> sshKeyToHostname sshkey
515 (_,(sout,serr)) <- runExternal "(f=$(mktemp); cat > \"$f\"; ssh-keygen -l -f \"$f\" | (read _ hash _; echo -n $hash.ssh.cryptonomic.net) | tr -d ':')" 515 _ -> error "fuck."
516 (Just $ sshblobFromPacket sshkey)
517 -- ssh-keygen -l -f /dev/stdin
518 -- putStrLn $ "wtf="++show(sout,serr, sshblobFromPacket sshkey)
519 return $ strongswanForContact addr contactname (Char8.fromChunks [sout])
520 [] -> error "fuck."
521 return $ Char8.concat bss 516 return $ Char8.concat bss
522 517
523 known_hosts = L.concat $ map getssh onionkeys 518 known_hosts = L.concat $ map getssh onionkeys
@@ -558,9 +553,18 @@ refreshCache rt rootdir = do
558 ] ++ filter (not . Char8.null) cons 553 ] ++ filter (not . Char8.null) cons
559 commit 554 commit
560 555
556sshKeyToHostname :: Packet -> IO Char8.ByteString
557sshKeyToHostname sshkey = do
558 (_, (sout, _serr)) <- runExternal shellScript (Just $ sshblobFromPacket sshkey)
559 return $ Char8.fromChunks [sout]
560 where
561 shellScript =
562 "f=$(mktemp) && cat > \"$f\" && ssh-keygen -r _ -f \"$f\" | (read _ _ _ _ _ hash _ && echo -n $hash.ssh.cryptonomic.net)"
563
564strongswanForContact :: SockAddr -> Char8.ByteString -> Char8.ByteString -> Char8.ByteString
561strongswanForContact addr oname rightip = Char8.unlines 565strongswanForContact addr oname rightip = Char8.unlines
562 [ "conn " <> oname 566 [ "conn " <> oname
563 , " right=lan." <> rightip 567 , " right=" <> rightip
564 , " rightsubnet=" <> p (showA addr) <> "/128" 568 , " rightsubnet=" <> p (showA addr) <> "/128"
565 , " rightauth=pubkey" 569 , " rightauth=pubkey"
566 , " rightid=" <> p (showA addr) 570 , " rightid=" <> p (showA addr)