From f75dc8570a347896093a88e482780d6969488cbf Mon Sep 17 00:00:00 2001 From: joe Date: Mon, 4 Aug 2014 19:25:43 -0400 Subject: Refactored ssh key blob serialization into independent module. --- kiki.hs | 37 ++++++------------------------------- 1 file changed, 6 insertions(+), 31 deletions(-) (limited to 'kiki.hs') diff --git a/kiki.hs b/kiki.hs index 9619971..98ac4c7 100644 --- a/kiki.hs +++ b/kiki.hs @@ -36,8 +36,6 @@ import qualified Data.ByteString.Lazy as L import qualified Data.ByteString.Lazy.Char8 as Char8 import qualified Data.Map as Map import Control.Arrow (first,second) -import Data.Binary.Get (runGet) -import Data.Binary.Put (putWord32be,runPut,putByteString) import Data.Time.Clock.POSIX ( posixSecondsToUTCTime ) import Data.Monoid ( (<>) ) @@ -45,12 +43,12 @@ import Data.OpenPGP.Util (verify,fingerprint) import ScanningParser import PEM import DotLock -import LengthPrefixedBE import KeyRing import Base58 import qualified CryptoCoins -- import Chroot import ProcessUtils +import qualified SSHKey as SSH -- {-# ANN module ("HLint: ignore Eta reduce"::String) #-} -- {-# ANN module ("HLint: ignore Use camelCase"::String) #-} @@ -114,22 +112,6 @@ import ProcessUtils warn str = hPutStrLn stderr str -sshrsa :: Integer -> Integer -> Char8.ByteString -sshrsa e n = runPut $ do - putWord32be 7 - putByteString "ssh-rsa" - put (LengthPrefixedBE e) - put (LengthPrefixedBE n) - -decode_sshrsa :: Char8.ByteString -> Maybe RSAPublicKey -decode_sshrsa bs = do - let (pre,bs1) = Char8.splitAt 11 bs - guard $ pre == runPut (putWord32be 7 >> putByteString "ssh-rsa") - let rsakey = flip runGet bs1 $ do - LengthPrefixedBE e <- get - LengthPrefixedBE n <- get - return $ RSAKey (MPI n) (MPI e) - return rsakey isCertificationSig (CertificationSignature {}) = True isCertificationSig _ = True @@ -240,16 +222,9 @@ modifyUID other = other -} readPublicKey :: Char8.ByteString -> RSAPublicKey -readPublicKey bs = fromMaybe er $ do - let (pre,bs1) = Char8.splitAt 7 bs - guard $ pre == "ssh-rsa" - let (sp,bs2) = Char8.span isSpace bs1 - guard $ not (Char8.null sp) - bs3 <- listToMaybe $ Char8.words bs2 - qq <- L.pack `fmap` Base64.decode (Char8.unpack bs3) - decode_sshrsa qq +readPublicKey bs = RSAKey (MPI n) (MPI e) where - er = error "Unsupported key format" + (n,e) = SSH.blobkey bs -- | Returns the given list with its last element modified. toLast :: (x -> x) -> [x] -> [x] @@ -312,9 +287,9 @@ show_ssh' keyspec wkgrip db = do (selectPublicKey s db) $ \k -> do let Just (RSAKey (MPI n) (MPI e)) = rsaKeyFromPacket k - bs = sshrsa e n - blob = Base64.encode (L.unpack bs) - return $ "ssh-rsa " ++ blob + bs = SSH.keyblob (n,e) + blob = Char8.unpack bs + return blob show_id keyspec wkgrip db = do let s = parseSpec "" keyspec -- cgit v1.2.3