From f5b586b541d6b8703a6fef3e09aabf563683c4e8 Mon Sep 17 00:00:00 2001 From: joe Date: Fri, 1 Aug 2014 00:04:33 -0400 Subject: export public ssh keys --- kiki.hs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/kiki.hs b/kiki.hs index fe8593e..607a935 100644 --- a/kiki.hs +++ b/kiki.hs @@ -299,15 +299,17 @@ show_pem keyspec wkgrip db = do putStrLn $ writePEM "PUBLIC KEY" qq -- ("TODO "++show keyspec) -show_ssh keyspec wkgrip db = do +show_ssh keyspec wkgrip db = either warn putStrLn $ show_ssh' keyspec wkgrip db + +show_ssh' keyspec wkgrip db = do let s = parseSpec wkgrip keyspec - flip (maybe . void $ warn (keyspec ++ ": not found")) + flip (maybe . Left $ keyspec ++ ": not found") (selectPublicKey s db) $ \k -> do let Just (RSAKey (MPI n) (MPI e)) = rsaKeyFromPacket k bs = sshrsa e n blob = Base64.encode (L.unpack bs) - putStrLn $ "ssh-rsa " ++ blob + return $ "ssh-rsa " ++ blob show_id keyspec wkgrip db = do let s = parseSpec "" keyspec @@ -1222,9 +1224,15 @@ kiki "init-key" args = do rt <- unconditionally $ return rt -- Finally, export public keys if they do not exist. - -- TODO - -- makepub ssh-client "$ROOT/root/.ssh/id_rsa.pub" - -- makepub ssh-host "$ROOT/etc/ssh/ssh_host_rsa_key.pub" + flip (maybe $ warn "missing working key?") (rtGrip rt) $ \grip -> do + gotc <- doesFileExist (sshcpath++".pub") + when (not gotc) $ do + either warn (writeFile $ sshcpath++".pub") + $ show_ssh' "ssh-client" grip (rtKeyDB rt) + goth <- doesFileExist (sshspath++".pub") + when (not goth) $ do + either warn (writeFile $ sshspath++".pub") + $ show_ssh' "ssh-host" grip (rtKeyDB rt) return () -- cgit v1.2.3