diff options
Diffstat (limited to 'lib/Kiki.hs')
-rw-r--r-- | lib/Kiki.hs | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/lib/Kiki.hs b/lib/Kiki.hs index 324efc4..1cc387b 100644 --- a/lib/Kiki.hs +++ b/lib/Kiki.hs | |||
@@ -13,6 +13,7 @@ import Codec.Encryption.OpenPGP.ASCIIArmor.Types | |||
13 | import Control.Applicative | 13 | import Control.Applicative |
14 | import Control.Exception | 14 | import Control.Exception |
15 | import Control.Monad | 15 | import Control.Monad |
16 | import qualified Crypto.Hash as C | ||
16 | import Data.ASN1.BinaryEncoding | 17 | import Data.ASN1.BinaryEncoding |
17 | import Data.ASN1.Encoding | 18 | import Data.ASN1.Encoding |
18 | import Data.ASN1.Types | 19 | import Data.ASN1.Types |
@@ -37,6 +38,7 @@ import System.Posix.Types (FileMode) | |||
37 | import System.Posix.IO as Posix (createPipe) | 38 | import System.Posix.IO as Posix (createPipe) |
38 | import System.Posix.User | 39 | import System.Posix.User |
39 | #if defined(VERSION_memory) | 40 | #if defined(VERSION_memory) |
41 | import Data.ByteArray (convert) | ||
40 | import Data.ByteArray.Encoding | 42 | import Data.ByteArray.Encoding |
41 | import qualified Data.ByteString.Char8 as S8 | 43 | import qualified Data.ByteString.Char8 as S8 |
42 | #elif defined(VERSION_dataenc) | 44 | #elif defined(VERSION_dataenc) |
@@ -582,14 +584,15 @@ writePublicKeyFiles rt fw grip myId = do | |||
582 | installIpsecConf fw myId cs | 584 | installIpsecConf fw myId cs |
583 | fileWriterCommit fw | 585 | fileWriterCommit fw |
584 | 586 | ||
585 | sshKeyToHostname :: Packet -> IO Char8.ByteString | 587 | |
588 | sshKeyToHostname :: Applicative m => Packet -> m Char8.ByteString | ||
586 | sshKeyToHostname sshkey = do | 589 | sshKeyToHostname sshkey = do |
587 | (_, (sout, _serr)) <- runExternal shellScript (Just $ sshblobFromPacket sshkey) | 590 | case rsaKeyFromPacket sshkey of |
588 | return $ Char8.fromChunks [sout] | 591 | Just (RSAKey (MPI n) (MPI e)) -> do |
589 | where | 592 | let blob = SSH.sshrsa e n |
590 | shellScript = | 593 | sha1 = C.hashlazy blob :: C.Digest C.SHA1 |
591 | "f=$(mktemp) && cat > \"$f\" && ssh-keygen -r _ -f \"$f\" |" ++ | 594 | pure $ Char8.fromStrict (convertToBase Base16 sha1) <> ".ssh.cryptonomic.net" |
592 | " (read _ _ _ _ _ hash _ && echo -n $hash.ssh.cryptonomic.net); r=$?; rm -f \"$f\"; exit $r" | 595 | Nothing -> pure "" |
593 | 596 | ||
594 | peerConnectionName :: Peer -> Char8.ByteString | 597 | peerConnectionName :: Peer -> Char8.ByteString |
595 | peerConnectionName = coerce . peerAddress | 598 | peerConnectionName = coerce . peerAddress |
@@ -653,6 +656,13 @@ show_pem' keyspec wkgrip db keyfmt = do | |||
653 | warn :: String -> IO () | 656 | warn :: String -> IO () |
654 | warn str = hPutStrLn stderr str | 657 | warn str = hPutStrLn stderr str |
655 | 658 | ||
659 | show_sshfp :: String -> String -> KeyDB -> IO () | ||
660 | show_sshfp keyspec wkgrip db = do | ||
661 | let s = parseSpec wkgrip keyspec | ||
662 | case selectPublicKey s db of | ||
663 | Nothing -> hPutStrLn stderr $ keyspec ++ ": not found" | ||
664 | Just k -> Char8.putStrLn =<< sshKeyToHostname k | ||
665 | |||
656 | show_ssh :: String -> String -> KeyDB -> IO () | 666 | show_ssh :: String -> String -> KeyDB -> IO () |
657 | show_ssh keyspec wkgrip db = either warn putStrLn $ show_ssh' keyspec wkgrip db | 667 | show_ssh keyspec wkgrip db = either warn putStrLn $ show_ssh' keyspec wkgrip db |
658 | 668 | ||