summaryrefslogtreecommitdiff
path: root/kiki.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2014-05-09 23:12:40 -0400
committerjoe <joe@jerkface.net>2014-05-09 23:12:40 -0400
commit073f2a99552a75e27c7fbe3fe8c328d2bf7277c6 (patch)
treea9d3197156cf88228ce2accf3304e89fbb9523f7 /kiki.hs
parentae090c58719726fd0027c4c606bc82faf55b1bc9 (diff)
readKeyFile "PEM" now accepts multiple keys and certs.
Diffstat (limited to 'kiki.hs')
-rw-r--r--kiki.hs58
1 files changed, 0 insertions, 58 deletions
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
325 let nwb = maybe 0x80 CryptoCoins.secretByteFromName $ snd s 325 let nwb = maybe 0x80 CryptoCoins.secretByteFromName $ snd s
326 putStrLn $ walletImportFormat nwb k 326 putStrLn $ walletImportFormat nwb k
327 327
328packetFromPublicRSAKey notBefore n e =
329 PublicKeyPacket { version = 4
330 , timestamp = round $ utcTimeToPOSIXSeconds notBefore
331 , key_algorithm = RSA
332 , key = [('n',n),('e',e)]
333 , is_subkey = True
334 , v3_days_of_validity = Nothing
335 }
336
337data ParsedCert = ParsedCert
338 { pcertKey :: Packet
339 , pcertTimestamp :: UTCTime
340 , pcertBlob :: L.ByteString
341 }
342 deriving (Show,Eq)
343
344parseCertBlob comp bs = do
345 asn1 <- either (const Nothing) Just
346 $ decodeASN1 DER bs
347 let asn1' = drop 2 asn1
348 cert <- either (const Nothing) (Just . fst) (fromASN1 asn1')
349 let _ = cert :: Certificate
350 (notBefore,_) = certValidity cert
351 case certPubKey cert of
352 PubKeyRSA key -> do
353 let withoutkey =
354 let ekey = Char8.toStrict $ encodeASN1 DER (toASN1 key [])
355 (pre,post) = S.breakSubstring ekey $ Char8.toStrict bs
356 post' = S.drop (S.length ekey) post
357 len :: Word16
358 len = if S.null post then maxBound
359 else fromIntegral $ S.length pre
360 in if len < 4096
361 then encode len `L.append` GZip.compress (Char8.fromChunks [pre,post'])
362 else bs
363 return
364 ParsedCert { pcertKey = packetFromPublicRSAKey notBefore
365 (MPI $ public_n key)
366 (MPI $ public_e key)
367 , pcertTimestamp = notBefore
368 , pcertBlob = if comp then withoutkey
369 else bs
370 }
371 _ -> Nothing
372
373decodeBlob cert =
374 if 0 /= (bs `L.index` 0) .&. 0x10
375 then bs
376 else let (keypos0,bs') = L.splitAt 2 bs
377 keypos :: Word16
378 keypos = decode keypos0
379 ds = GZip.decompress bs'
380 (prekey,postkey) = L.splitAt (fromIntegral keypos) ds
381 in prekey <> key <> postkey
382 where
383 bs = pcertBlob cert
384 key = maybe L.empty (encodeASN1 DER . flip toASN1 []) $ rsaKeyFromPacket $ pcertKey cert
385
386show_torhash pubkey _ = do 328show_torhash pubkey _ = do
387 bs <- Char8.readFile pubkey 329 bs <- Char8.readFile pubkey
388 let parsekey f dta = do 330 let parsekey f dta = do