From 073f2a99552a75e27c7fbe3fe8c328d2bf7277c6 Mon Sep 17 00:00:00 2001 From: joe Date: Fri, 9 May 2014 23:12:40 -0400 Subject: readKeyFile "PEM" now accepts multiple keys and certs. --- kiki.hs | 58 ---------------------------------------------------------- 1 file changed, 58 deletions(-) (limited to 'kiki.hs') diff --git a/kiki.hs b/kiki.hs index 8d1d7cb..063c42c 100644 --- a/kiki.hs +++ b/kiki.hs @@ -325,64 +325,6 @@ show_wip keyspec wkgrip db = do let nwb = maybe 0x80 CryptoCoins.secretByteFromName $ snd s putStrLn $ walletImportFormat nwb k -packetFromPublicRSAKey notBefore n e = - PublicKeyPacket { version = 4 - , timestamp = round $ utcTimeToPOSIXSeconds notBefore - , key_algorithm = RSA - , key = [('n',n),('e',e)] - , is_subkey = True - , v3_days_of_validity = Nothing - } - -data ParsedCert = ParsedCert - { pcertKey :: Packet - , pcertTimestamp :: UTCTime - , pcertBlob :: L.ByteString - } - deriving (Show,Eq) - -parseCertBlob comp bs = do - asn1 <- either (const Nothing) Just - $ decodeASN1 DER bs - let asn1' = drop 2 asn1 - cert <- either (const Nothing) (Just . fst) (fromASN1 asn1') - let _ = cert :: Certificate - (notBefore,_) = certValidity cert - case certPubKey cert of - PubKeyRSA key -> do - let withoutkey = - let ekey = Char8.toStrict $ encodeASN1 DER (toASN1 key []) - (pre,post) = S.breakSubstring ekey $ Char8.toStrict bs - post' = S.drop (S.length ekey) post - len :: Word16 - len = if S.null post then maxBound - else fromIntegral $ S.length pre - in if len < 4096 - then encode len `L.append` GZip.compress (Char8.fromChunks [pre,post']) - else bs - return - ParsedCert { pcertKey = packetFromPublicRSAKey notBefore - (MPI $ public_n key) - (MPI $ public_e key) - , pcertTimestamp = notBefore - , pcertBlob = if comp then withoutkey - else bs - } - _ -> Nothing - -decodeBlob cert = - if 0 /= (bs `L.index` 0) .&. 0x10 - then bs - else let (keypos0,bs') = L.splitAt 2 bs - keypos :: Word16 - keypos = decode keypos0 - ds = GZip.decompress bs' - (prekey,postkey) = L.splitAt (fromIntegral keypos) ds - in prekey <> key <> postkey - where - bs = pcertBlob cert - key = maybe L.empty (encodeASN1 DER . flip toASN1 []) $ rsaKeyFromPacket $ pcertKey cert - show_torhash pubkey _ = do bs <- Char8.readFile pubkey let parsekey f dta = do -- cgit v1.2.3