summaryrefslogtreecommitdiff
path: root/kiki.hs
diff options
context:
space:
mode:
Diffstat (limited to 'kiki.hs')
-rw-r--r--kiki.hs37
1 files changed, 6 insertions, 31 deletions
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
36import qualified Data.ByteString.Lazy.Char8 as Char8 36import qualified Data.ByteString.Lazy.Char8 as Char8
37import qualified Data.Map as Map 37import qualified Data.Map as Map
38import Control.Arrow (first,second) 38import Control.Arrow (first,second)
39import Data.Binary.Get (runGet)
40import Data.Binary.Put (putWord32be,runPut,putByteString)
41import Data.Time.Clock.POSIX ( posixSecondsToUTCTime ) 39import Data.Time.Clock.POSIX ( posixSecondsToUTCTime )
42import Data.Monoid ( (<>) ) 40import Data.Monoid ( (<>) )
43 41
@@ -45,12 +43,12 @@ import Data.OpenPGP.Util (verify,fingerprint)
45import ScanningParser 43import ScanningParser
46import PEM 44import PEM
47import DotLock 45import DotLock
48import LengthPrefixedBE
49import KeyRing 46import KeyRing
50import Base58 47import Base58
51import qualified CryptoCoins 48import qualified CryptoCoins
52-- import Chroot 49-- import Chroot
53import ProcessUtils 50import ProcessUtils
51import qualified SSHKey as SSH
54 52
55-- {-# ANN module ("HLint: ignore Eta reduce"::String) #-} 53-- {-# ANN module ("HLint: ignore Eta reduce"::String) #-}
56-- {-# ANN module ("HLint: ignore Use camelCase"::String) #-} 54-- {-# ANN module ("HLint: ignore Use camelCase"::String) #-}
@@ -114,22 +112,6 @@ import ProcessUtils
114 112
115warn str = hPutStrLn stderr str 113warn str = hPutStrLn stderr str
116 114
117sshrsa :: Integer -> Integer -> Char8.ByteString
118sshrsa e n = runPut $ do
119 putWord32be 7
120 putByteString "ssh-rsa"
121 put (LengthPrefixedBE e)
122 put (LengthPrefixedBE n)
123
124decode_sshrsa :: Char8.ByteString -> Maybe RSAPublicKey
125decode_sshrsa bs = do
126 let (pre,bs1) = Char8.splitAt 11 bs
127 guard $ pre == runPut (putWord32be 7 >> putByteString "ssh-rsa")
128 let rsakey = flip runGet bs1 $ do
129 LengthPrefixedBE e <- get
130 LengthPrefixedBE n <- get
131 return $ RSAKey (MPI n) (MPI e)
132 return rsakey
133 115
134isCertificationSig (CertificationSignature {}) = True 116isCertificationSig (CertificationSignature {}) = True
135isCertificationSig _ = True 117isCertificationSig _ = True
@@ -240,16 +222,9 @@ modifyUID other = other
240-} 222-}
241 223
242readPublicKey :: Char8.ByteString -> RSAPublicKey 224readPublicKey :: Char8.ByteString -> RSAPublicKey
243readPublicKey bs = fromMaybe er $ do 225readPublicKey bs = RSAKey (MPI n) (MPI e)
244 let (pre,bs1) = Char8.splitAt 7 bs
245 guard $ pre == "ssh-rsa"
246 let (sp,bs2) = Char8.span isSpace bs1
247 guard $ not (Char8.null sp)
248 bs3 <- listToMaybe $ Char8.words bs2
249 qq <- L.pack `fmap` Base64.decode (Char8.unpack bs3)
250 decode_sshrsa qq
251 where 226 where
252 er = error "Unsupported key format" 227 (n,e) = SSH.blobkey bs
253 228
254-- | Returns the given list with its last element modified. 229-- | Returns the given list with its last element modified.
255toLast :: (x -> x) -> [x] -> [x] 230toLast :: (x -> x) -> [x] -> [x]
@@ -312,9 +287,9 @@ show_ssh' keyspec wkgrip db = do
312 (selectPublicKey s db) 287 (selectPublicKey s db)
313 $ \k -> do 288 $ \k -> do
314 let Just (RSAKey (MPI n) (MPI e)) = rsaKeyFromPacket k 289 let Just (RSAKey (MPI n) (MPI e)) = rsaKeyFromPacket k
315 bs = sshrsa e n 290 bs = SSH.keyblob (n,e)
316 blob = Base64.encode (L.unpack bs) 291 blob = Char8.unpack bs
317 return $ "ssh-rsa " ++ blob 292 return blob
318 293
319show_id keyspec wkgrip db = do 294show_id keyspec wkgrip db = do
320 let s = parseSpec "" keyspec 295 let s = parseSpec "" keyspec