summaryrefslogtreecommitdiff
path: root/KeyRing.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2014-04-20 13:23:10 -0400
committerjoe <joe@jerkface.net>2014-04-20 13:23:10 -0400
commit6a30393193e3df562b605a7fcd01d56582a8f2ff (patch)
tree4c18b60bfa492bd503195d70f2041ecb7eaaeee1 /KeyRing.hs
parent05f590cd812a97c8014cfd321ba87be392addf36 (diff)
abstract the performManipulations step
Diffstat (limited to 'KeyRing.hs')
-rw-r--r--KeyRing.hs111
1 files changed, 56 insertions, 55 deletions
diff --git a/KeyRing.hs b/KeyRing.hs
index 4973aa4..36477c0 100644
--- a/KeyRing.hs
+++ b/KeyRing.hs
@@ -1205,6 +1205,55 @@ doDecrypt unkeysRef pws mp = do
1205 (return . KikiSuccess) 1205 (return . KikiSuccess)
1206 $ Map.lookup kk unkeys 1206 $ Map.lookup kk unkeys
1207 1207
1208performManipulations ::
1209 (MappedPacket -> IO (KikiCondition Packet))
1210 -> KeyRingOperation
1211 -> KeyRingRuntime
1212 -> Maybe MappedPacket
1213 -> IO (KikiCondition (KeyDB,[(FilePath,KikiReportAction)]))
1214performManipulations doDecrypt operation rt wk = do
1215 let db = rtKeyDB rt
1216 db <- let perform kd (InducerSignature uid subpaks) = do
1217 case wk of
1218 Nothing -> error "TODO no working key" -- todo
1219 Just wk' -> do
1220 wkun' <- doDecrypt wk'
1221 case functorToEither wkun' of
1222 Left e -> error "Bad passphrase, todo"
1223 Right wkun -> do
1224 let sigOver = makeInducerSig (keyPacket kd) wkun (UserIDPacket uid) subpaks
1225 sigr <- pgpSign (Message [wkun]) sigOver SHA1 (fingerprint wkun)
1226 let f ::([SigAndTrust],OriginMap) -> ([SigAndTrust],OriginMap)
1227 f x = ( map ( (,Map.empty) . toMappedPacket om) (additional sigr) ++ fst x
1228 , om `Map.union` snd x )
1229 om = Map.singleton "--autosign" (origin p (-1)) where p = UserIDPacket uid
1230 toMappedPacket om p = (mappedPacket "" p) {locations=om}
1231 selfsigs = filter (\(sig,v,whosign) -> isJust (v >> Just wkun >>= guard
1232 . (== keykey whosign)
1233 . keykey)) vs
1234 keys = map keyPacket $ Map.elems (rtKeyDB rt)
1235 overs sig = signatures $ Message (keys++[keyPacket kd,UserIDPacket uid,sig])
1236 vs :: [ ( Packet -- signature
1237 , Maybe SignatureOver -- Nothing means non-verified
1238 , Packet ) -- key who signed
1239 ]
1240 vs = do
1241 x <- maybeToList $ Map.lookup uid (rentryUids kd)
1242 sig <- map (packet . fst) (fst x)
1243 o <- overs sig
1244 k <- keys
1245 let ov = verify (Message [k]) $ o
1246 signatures_over ov
1247 return (sig,Just ov,k)
1248 additional new_sig = do
1249 new_sig <- maybeToList new_sig
1250 guard (null $ selfsigs)
1251 signatures_over new_sig
1252 return kd { rentryUids = Map.adjust f uid (rentryUids kd) }
1253 in Traversable.mapM (\kd -> foldM perform kd (kManip operation rt kd)) db
1254 return $ KikiSuccess (db,[])
1255
1256
1208{- 1257{-
1209interpretManip :: KeyData -> KeyRingAddress PacketUpdate -> IO KeyData 1258interpretManip :: KeyData -> KeyRingAddress PacketUpdate -> IO KeyData
1210interpretManip kd (KeyRingAddress kk sk (InducerSignature ps)) = error "todo" 1259interpretManip kd (KeyRingAddress kk sk (InducerSignature ps)) = error "todo"
@@ -1321,62 +1370,13 @@ runKeyRing operation = do
1321 1370
1322 try' externals_ret $ \(db,report_externals) -> do 1371 try' externals_ret $ \(db,report_externals) -> do
1323 1372
1324 db <- let perform kd (InducerSignature uid subpaks) = do
1325 case wk of
1326 Nothing -> error "TODO no working key" -- todo
1327 Just wk' -> do
1328 wkun' <- doDecrypt unkeysRef pws wk'
1329 case functorToEither wkun' of
1330 Left e -> error "Bad passphrase, todo"
1331 Right wkun -> do
1332 let sigOver = makeInducerSig (keyPacket kd) wkun (UserIDPacket uid) subpaks
1333 sigr <- pgpSign (Message [wkun]) sigOver SHA1 (fingerprint wkun)
1334 let f ::([SigAndTrust],OriginMap) -> ([SigAndTrust],OriginMap)
1335 f x = ( map ( (,Map.empty) . toMappedPacket om) (additional sigr) ++ fst x
1336 , om `Map.union` snd x )
1337 om = Map.singleton "--autosign" (origin p (-1)) where p = UserIDPacket uid
1338 toMappedPacket om p = (mappedPacket "" p) {locations=om}
1339 selfsigs = filter (\(sig,v,whosign) -> isJust (v >> Just wkun >>= guard
1340 . (== keykey whosign)
1341 . keykey)) vs
1342 keys = map keyPacket $ Map.elems (rtKeyDB rt)
1343 overs sig = signatures $ Message (keys++[keyPacket kd,UserIDPacket uid,sig])
1344 vs :: [ ( Packet -- signature
1345 , Maybe SignatureOver -- Nothing means non-verified
1346 , Packet ) -- key who signed
1347 ]
1348 vs = do
1349 x <- maybeToList $ Map.lookup uid (rentryUids kd)
1350 sig <- map (packet . fst) (fst x)
1351 o <- overs sig
1352 k <- keys
1353 let ov = verify (Message [k]) $ o
1354 signatures_over ov
1355 return (sig,Just ov,k)
1356 additional new_sig = do
1357 new_sig <- maybeToList new_sig
1358 guard (null $ selfsigs)
1359 signatures_over new_sig
1360 return kd { rentryUids = Map.adjust f uid (rentryUids kd) }
1361 in Traversable.mapM (\kd -> foldM perform kd (kManip operation rt kd)) db
1362 1373
1363{- 1374 r <- performManipulations (doDecrypt unkeysRef pws)
1364 let manips0 = kManip operation rt 1375 operation
1365 manips :: Map.Map KeyKey [KeyRingAddress PacketUpdate] 1376 rt
1366 manips = Map.fromList $ do 1377 wk
1367 ms <- groupBy ((==EQ) .: comparing topkeyAddress) 1378 try' r $ \(db,report_manips) -> do
1368 $ sortBy (comparing topkeyAddress) 1379 rt <- return $ rt { rtKeyDB = db }
1369 manips0
1370 k <- fmap topkeyAddress $ take 1 ms
1371 return (k,ms)
1372 where (.:) = (.).(.)
1373 doManips kd = do
1374 let kk = keykey $ keyPacket kd
1375 ms = maybe [] id $ Map.lookup kk manips
1376 foldM interpretManip kd ms
1377
1378 db' <- Traversable.mapM doManips db
1379-}
1380 1380
1381 r <- writeWalletKeys operation db (fmap packet wk) 1381 r <- writeWalletKeys operation db (fmap packet wk)
1382 try' r $ \report_wallets -> do 1382 try' r $ \report_wallets -> do
@@ -1390,6 +1390,7 @@ runKeyRing operation = do
1390 return $ KikiResult (KikiSuccess rt) 1390 return $ KikiResult (KikiSuccess rt)
1391 $ concat [ report_imports 1391 $ concat [ report_imports
1392 , report_externals 1392 , report_externals
1393 , report_manips
1393 , report_wallets 1394 , report_wallets
1394 , report_rings 1395 , report_rings
1395 , report_pems ] 1396 , report_pems ]