summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2014-05-09 23:25:50 -0400
committerjoe <joe@jerkface.net>2014-05-09 23:25:50 -0400
commitf4d32f7692b2699e7136e5dd267382193b005bb4 (patch)
tree8c985c4a49b0dc4b885442f663d0d2968758a6fe
parent073f2a99552a75e27c7fbe3fe8c328d2bf7277c6 (diff)
doImport now capable of handling multiple keys from a single pem.
-rw-r--r--KeyRing.hs25
1 files changed, 14 insertions, 11 deletions
diff --git a/KeyRing.hs b/KeyRing.hs
index ad3e2ae..f7a1a12 100644
--- a/KeyRing.hs
+++ b/KeyRing.hs
@@ -1454,8 +1454,8 @@ decodeBlob cert =
1454 key = maybe "" (encodeASN1 DER . flip toASN1 []) $ rsaKeyFromPacket $ pcertKey cert 1454 key = maybe "" (encodeASN1 DER . flip toASN1 []) $ rsaKeyFromPacket $ pcertKey cert
1455 1455
1456 1456
1457readKeyFromFile :: Bool -> String -> InputFile -> IO [SecretPEMData] 1457readSecretPEMFile :: InputFile -> IO [SecretPEMData]
1458readKeyFromFile False "PEM" fname = do 1458readSecretPEMFile fname = do
1459 -- warn $ fname ++ ": reading ..." 1459 -- warn $ fname ++ ": reading ..."
1460 let ctx = InputFileContext "" "" 1460 let ctx = InputFileContext "" ""
1461 -- Note: The key's timestamp is included in it's fingerprint. 1461 -- Note: The key's timestamp is included in it's fingerprint.
@@ -1493,7 +1493,6 @@ readKeyFromFile False "PEM" fname = do
1493 , is_subkey = True 1493 , is_subkey = True
1494 } 1494 }
1495 return dta 1495 return dta
1496readKeyFromFile is_public fmt filename = error ("unimplemented key type: "++fmt)
1497 1496
1498doImport 1497doImport
1499 :: Ord k => 1498 :: Ord k =>
@@ -1502,17 +1501,21 @@ doImport
1502 -> (FilePath, Maybe [Char], [k], t) 1501 -> (FilePath, Maybe [Char], [k], t)
1503 -> IO (KikiCondition (Map.Map k KeyData, [(FilePath,KikiReportAction)])) 1502 -> IO (KikiCondition (Map.Map k KeyData, [(FilePath,KikiReportAction)]))
1504doImport doDecrypt db (fname,subspec,ms,_) = do 1503doImport doDecrypt db (fname,subspec,ms,_) = do
1505 let fetchkey = readKeyFromFile False "PEM" (ArgFile fname)
1506 flip (maybe $ return CannotImportMasterKey) 1504 flip (maybe $ return CannotImportMasterKey)
1507 subspec $ \tag -> do 1505 subspec $ \tag -> do
1508 ps <- fetchkey 1506 ps <- readSecretPEMFile (ArgFile fname)
1509 let parsedkey = mapMaybe spemPacket ps 1507 let parsedkey = mapMaybe spemPacket ps
1510 flip (maybe $ return $ KikiSuccess (db,[])) 1508 foldM (importPemThing tag) (KikiSuccess (db,[])) parsedkey
1511 (listToMaybe parsedkey) $ \key -> do 1509 where
1512 let (m0,tailms) = splitAt 1 ms 1510 importPemThing tag prior key = do
1513 if (not (null tailms) || null m0) 1511 try prior $ \(db,report) -> do
1514 then return $ AmbiguousKeySpec fname 1512 let (m0,tailms) = splitAt 1 ms
1515 else doImportG doDecrypt db m0 tag fname key 1513 if (not (null tailms) || null m0)
1514 then return $ AmbiguousKeySpec fname
1515 else do
1516 r <- doImportG doDecrypt db m0 tag fname key
1517 try r $ \(db',report') -> do
1518 return $ KikiSuccess (db',report++report')
1516 1519
1517doImportG 1520doImportG
1518 :: Ord k => 1521 :: Ord k =>