diff options
-rw-r--r-- | OpenPGP.hs | 44 | ||||
-rw-r--r-- | kiki.hs | 5 |
2 files changed, 2 insertions, 47 deletions
diff --git a/OpenPGP.hs b/OpenPGP.hs deleted file mode 100644 index 75054b3..0000000 --- a/OpenPGP.hs +++ /dev/null | |||
@@ -1,44 +0,0 @@ | |||
1 | module OpenPGP | ||
2 | ( verify | ||
3 | , fingerprint | ||
4 | , pgpSign | ||
5 | , decryptSecretKey | ||
6 | ) where | ||
7 | |||
8 | import Data.OpenPGP as OpenPGP | ||
9 | import Data.OpenPGP.CryptoAPI (verify,fingerprint,sign,decryptSecretKey) | ||
10 | import Data.Time.Clock.POSIX | ||
11 | import Control.Applicative ( (<$>) ) | ||
12 | import Crypto.Random (newGenIO,SystemRandom) | ||
13 | import ControlMaybe | ||
14 | |||
15 | now = floor <$> Data.Time.Clock.POSIX.getPOSIXTime | ||
16 | |||
17 | stampit timestamp sig = sig { hashed_subpackets = hashed' } | ||
18 | where | ||
19 | hashed_stamps = filter isStamp (hashed_subpackets sig) | ||
20 | unhashed_stamps = filter isStamp (unhashed_subpackets sig) | ||
21 | hashed' = case hashed_stamps ++ unhashed_stamps of | ||
22 | [] -> SignatureCreationTimePacket (fromIntegral timestamp) | ||
23 | : hashed_subpackets sig | ||
24 | _ -> hashed_subpackets sig | ||
25 | isStamp (SignatureCreationTimePacket {}) = True | ||
26 | isStamp _ = False | ||
27 | |||
28 | -- | Make a signature | ||
29 | -- | ||
30 | -- In order to set more options on a signature, pass in a signature packet. | ||
31 | pgpSign :: | ||
32 | OpenPGP.Message -- ^ SecretKeys, one of which will be used | ||
33 | -> OpenPGP.SignatureOver -- ^ Data to sign, and optional signature packet | ||
34 | -> OpenPGP.HashAlgorithm -- ^ HashAlgorithm to use in signature | ||
35 | -> String -- ^ KeyID of key to choose | ||
36 | -> IO (Maybe OpenPGP.SignatureOver) | ||
37 | pgpSign seckeys dta hash_algo keyid = | ||
38 | handleIO_ (return Nothing) $ do | ||
39 | timestamp <- now | ||
40 | g <- newGenIO :: IO SystemRandom | ||
41 | let sigs = map (stampit timestamp) $ signatures_over dta | ||
42 | dta' = dta { signatures_over = sigs } | ||
43 | let (r,g') = sign seckeys dta' hash_algo keyid timestamp g | ||
44 | return (Just r) | ||
@@ -23,8 +23,7 @@ import Control.Monad | |||
23 | import qualified Text.Show.Pretty as PP | 23 | import qualified Text.Show.Pretty as PP |
24 | import Text.PrettyPrint as PP hiding ((<>)) | 24 | import Text.PrettyPrint as PP hiding ((<>)) |
25 | import Data.List | 25 | import Data.List |
26 | -- import Data.OpenPGP.CryptoAPI (verify,fingerprint,sign,decryptSecretKey) | 26 | import Data.OpenPGP.Util (verify,fingerprint,decryptSecretKey,pgpSign) |
27 | import OpenPGP | ||
28 | import Data.Ord | 27 | import Data.Ord |
29 | import Data.Maybe | 28 | import Data.Maybe |
30 | import Data.Bits | 29 | import Data.Bits |
@@ -714,7 +713,7 @@ expandPath path [] = [] | |||
714 | 713 | ||
715 | readPacketsFromFile :: FilePath -> IO Message | 714 | readPacketsFromFile :: FilePath -> IO Message |
716 | readPacketsFromFile fname = do | 715 | readPacketsFromFile fname = do |
717 | warn $ fname ++ ": reading..." | 716 | -- warn $ fname ++ ": reading..." |
718 | input <- L.readFile fname | 717 | input <- L.readFile fname |
719 | return $ | 718 | return $ |
720 | case decodeOrFail input of | 719 | case decodeOrFail input of |