From 8c7186a839964c10f94f6d21e1aa00c1cf652429 Mon Sep 17 00:00:00 2001 From: joe Date: Tue, 30 Aug 2016 00:03:12 -0400 Subject: Avoid unneccessary decryption. --- lib/KeyRing.hs | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) (limited to 'lib') diff --git a/lib/KeyRing.hs b/lib/KeyRing.hs index c7fcebc..5cd5c71 100644 --- a/lib/KeyRing.hs +++ b/lib/KeyRing.hs @@ -1829,27 +1829,31 @@ insertSubkey transcode kk (KeyData top topsigs uids subs) tags inputfile key0 = tops2k = s2k $ packet top doDecrypt = transcode (Unencrypted,S2K 100 "") fname = resolveForReport Nothing inputfile - wkun <- doDecrypt top - try wkun $ \wkun -> do - key' <- transcode (topcipher,tops2k) $ mappedPacket "" key0 - try key' $ \key -> do - let subkk = keykey key - (is_new, subkey) = maybe (True, SubKey (mappedPacket fname key) - []) - ( (False,) . addOrigin ) - (Map.lookup subkk subs) - where - addOrigin (SubKey mp sigs) = + subkk = keykey key0 + istor = do + guard ("tor" `elem` mapMaybe usage tags) + return $ torUIDFromKey key0 + addOrigin (SubKey mp sigs) = let mp' = mp { locations = Map.insert fname (origin (packet mp) (-1)) (locations mp) } in SubKey mp' sigs - subs' = Map.insert subkk subkey subs - istor = do - guard ("tor" `elem` mapMaybe usage tags) - return $ torUIDFromKey key + subkey_result <- do + case Map.lookup subkk subs of + Just sub -> return $ KikiSuccess (False,addOrigin sub,Nothing) + Nothing -> do + wkun' <- doDecrypt top + try wkun' $ \wkun -> do + key' <- transcode (topcipher,tops2k) $ mappedPacket "" key0 + try key' $ \key -> do + return $ KikiSuccess (True, SubKey (mappedPacket fname key) [], Just (wkun,key)) + + + try subkey_result $ \(is_new,subkey,decrypted) -> do + + let subs' = Map.insert subkk subkey subs uids' <- flip (maybe $ return $ KikiSuccess (uids,[])) istor $ \idstr -> do let has_torid = do @@ -1860,10 +1864,12 @@ insertSubkey transcode kk (KeyData top topsigs uids subs) tags inputfile key0 = signatures_over $ verify (Message [packet top]) s flip (flip maybe $ const $ return $ KikiSuccess (uids,[])) has_torid $ do - let keyflags = keyFlags wkun (map packet $ flattenAllUids fname True uids) + let keyflags = keyFlags (error "dummy argument (insertSubkey)") (map packet $ flattenAllUids fname True uids) uid = UserIDPacket idstr -- sig_ov = fst $ torsig g (packet top) wkun uid timestamp keyflags - tor_ov = makeInducerSig (packet top) wkun uid keyflags + tor_ov = makeInducerSig (packet top) (packet top) uid keyflags + wkun' <- maybe (doDecrypt top) (return . KikiSuccess . fst) decrypted + try wkun' $ \wkun -> do sig_ov <- pgpSign (Message [wkun]) tor_ov SHA1 @@ -1882,7 +1888,7 @@ insertSubkey transcode kk (KeyData top topsigs uids subs) tags inputfile key0 = let SubKey subkey_p subsigs = subkey wk = packet top - (xs',minsig,ys') = findTag tags wk key subsigs + (xs',minsig,ys') = findTag tags wk key0 subsigs doInsert mbsig = do -- NEW SUBKEY BINDING SIGNATURE -- XXX: Here I assume that key0 is the unencrypted version @@ -1898,7 +1904,7 @@ insertSubkey transcode kk (KeyData top topsigs uids subs) tags inputfile key0 = report <- let f = if is_new then (++[(fname,YieldSecretKeyPacket s)]) else id - s = show (fmap fst minsig,fingerprint key) + s = show (fmap fst minsig,fingerprint key0) in return (f report) case minsig of -- cgit v1.2.3