summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2013-12-13 04:27:54 -0500
committerjoe <joe@jerkface.net>2013-12-13 04:27:54 -0500
commitde42e2f46ec64f84317ef3696bd304a3836a38f9 (patch)
tree71190f85d0b5354fde46f22f5150ab86ac34343d
parent89c2b6b175ecf805fdd9e823726b8eec4774c78b (diff)
Changed pgpSign to return a Maybe in case a signature cannot be made.
-rw-r--r--OpenPGP.hs8
-rw-r--r--kiki.hs10
2 files changed, 11 insertions, 7 deletions
diff --git a/OpenPGP.hs b/OpenPGP.hs
index 7fef0b5..75054b3 100644
--- a/OpenPGP.hs
+++ b/OpenPGP.hs
@@ -10,6 +10,7 @@ import Data.OpenPGP.CryptoAPI (verify,fingerprint,sign,decryptSecretKey)
10import Data.Time.Clock.POSIX 10import Data.Time.Clock.POSIX
11import Control.Applicative ( (<$>) ) 11import Control.Applicative ( (<$>) )
12import Crypto.Random (newGenIO,SystemRandom) 12import Crypto.Random (newGenIO,SystemRandom)
13import ControlMaybe
13 14
14now = floor <$> Data.Time.Clock.POSIX.getPOSIXTime 15now = floor <$> Data.Time.Clock.POSIX.getPOSIXTime
15 16
@@ -32,11 +33,12 @@ pgpSign ::
32 -> OpenPGP.SignatureOver -- ^ Data to sign, and optional signature packet 33 -> OpenPGP.SignatureOver -- ^ Data to sign, and optional signature packet
33 -> OpenPGP.HashAlgorithm -- ^ HashAlgorithm to use in signature 34 -> OpenPGP.HashAlgorithm -- ^ HashAlgorithm to use in signature
34 -> String -- ^ KeyID of key to choose 35 -> String -- ^ KeyID of key to choose
35 -> IO OpenPGP.SignatureOver 36 -> IO (Maybe OpenPGP.SignatureOver)
36pgpSign seckeys dta hash_algo keyid = do 37pgpSign seckeys dta hash_algo keyid =
38 handleIO_ (return Nothing) $ do
37 timestamp <- now 39 timestamp <- now
38 g <- newGenIO :: IO SystemRandom 40 g <- newGenIO :: IO SystemRandom
39 let sigs = map (stampit timestamp) $ signatures_over dta 41 let sigs = map (stampit timestamp) $ signatures_over dta
40 dta' = dta { signatures_over = sigs } 42 dta' = dta { signatures_over = sigs }
41 let (r,g') = sign seckeys dta' hash_algo keyid timestamp g 43 let (r,g') = sign seckeys dta' hash_algo keyid timestamp g
42 return r 44 return (Just r)
diff --git a/kiki.hs b/kiki.hs
index bc8b61b..7c77f64 100644
--- a/kiki.hs
+++ b/kiki.hs
@@ -1417,7 +1417,7 @@ doImport doDecrypt db (fname,subspec,ms,_) = do
1417 SHA1 1417 SHA1
1418 (fingerprint wkun) 1418 (fingerprint wkun)
1419 flip (maybe $ warn "Failed to make signature" >> return uids) 1419 flip (maybe $ warn "Failed to make signature" >> return uids)
1420 (listToMaybe $ signatures_over sig_ov) 1420 (sig_ov >>= listToMaybe . signatures_over)
1421 $ \sig -> do 1421 $ \sig -> do
1422 let om = Map.singleton fname (origin sig (-1)) 1422 let om = Map.singleton fname (origin sig (-1))
1423 trust = Map.empty 1423 trust = Map.empty
@@ -1449,7 +1449,7 @@ makeSig doDecrypt top fname subkey_p tag mbsig = do
1449 let grip = fingerprint wk 1449 let grip = fingerprint wk
1450 addOrigin new_sig = do 1450 addOrigin new_sig = do
1451 flip (maybe $ error "Failed to make signature.") 1451 flip (maybe $ error "Failed to make signature.")
1452 (listToMaybe $ signatures_over new_sig) 1452 (new_sig >>= listToMaybe . signatures_over)
1453 $ \new_sig -> do 1453 $ \new_sig -> do
1454 let mp' = MappedPacket new_sig (Map.singleton fname (origin new_sig (-1))) 1454 let mp' = MappedPacket new_sig (Map.singleton fname (origin new_sig (-1)))
1455 return (mp', Map.empty) 1455 return (mp', Map.empty)
@@ -1481,8 +1481,9 @@ makeSig doDecrypt top fname subkey_p tag mbsig = do
1481 [IssuerPacket subgrip])) 1481 [IssuerPacket subgrip]))
1482 SHA1 1482 SHA1
1483 subgrip 1483 subgrip
1484 let unhashed0 = ( IssuerPacket (fingerprint wk) 1484 let iss = IssuerPacket (fingerprint wk)
1485 : map EmbeddedSignaturePacket (signatures_over back_sig)) 1485 cons_iss back_sig = iss : map EmbeddedSignaturePacket (signatures_over back_sig)
1486 unhashed0 = maybe [iss] cons_iss back_sig
1486 1487
1487 new_sig <- pgpSign (Message [wkun]) 1488 new_sig <- pgpSign (Message [wkun])
1488 (SubkeySignature wk 1489 (SubkeySignature wk
@@ -1927,6 +1928,7 @@ main = do
1927 . keykey)) 1928 . keykey))
1928 vs 1929 vs
1929 additional new_sig = do 1930 additional new_sig = do
1931 new_sig <- maybeToList new_sig
1930 guard $ {- trace (unlines $ [ "selfsigs = "++show (map ((\(_,_,k)->fingerprint k)) selfsigs) 1932 guard $ {- trace (unlines $ [ "selfsigs = "++show (map ((\(_,_,k)->fingerprint k)) selfsigs)
1931 , " for mainkey = "++fingerprint mainpubkey] ) 1933 , " for mainkey = "++fingerprint mainpubkey] )
1932 -} 1934 -}