diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 11 | ||||
-rw-r--r-- | examples/keygen.hs | 43 |
3 files changed, 51 insertions, 4 deletions
@@ -3,5 +3,6 @@ | |||
3 | *.swp* | 3 | *.swp* |
4 | verify | 4 | verify |
5 | sign | 5 | sign |
6 | keygen | ||
6 | dist/* | 7 | dist/* |
7 | report.html | 8 | report.html |
@@ -3,18 +3,21 @@ HLINTFLAGS=-XHaskell98 -XNoCPP -i 'Use camelCase' -i 'Use String' -i 'Use head' | |||
3 | 3 | ||
4 | .PHONY: all clean doc install | 4 | .PHONY: all clean doc install |
5 | 5 | ||
6 | all: sign verify report.html doc dist/build/libHSopenpgp-0.2.a dist/openpgp-0.2.tar.gz | 6 | all: sign verify keygen report.html doc dist/build/libHSopenpgp-0.2.a dist/openpgp-0.2.tar.gz |
7 | 7 | ||
8 | install: dist/build/libHSopenpgp-0.2.a | 8 | install: dist/build/libHSopenpgp-0.2.a |
9 | cabal install | 9 | cabal install |
10 | 10 | ||
11 | sign: examples/sign.hs | 11 | sign: examples/sign.hs Data/*.hs Data/OpenPGP/*.hs |
12 | ghc --make $(GHCFLAGS) -o $@ $^ | 12 | ghc --make $(GHCFLAGS) -o $@ $^ |
13 | 13 | ||
14 | verify: examples/verify.hs | 14 | verify: examples/verify.hs Data/*.hs Data/OpenPGP/*.hs |
15 | ghc --make $(GHCFLAGS) -o $@ $^ | 15 | ghc --make $(GHCFLAGS) -o $@ $^ |
16 | 16 | ||
17 | report.html: examples/* Data/* Data/OpenPGP/* | 17 | keygen: examples/keygen.hs Data/*.hs Data/OpenPGP/*.hs |
18 | ghc --make $(GHCFLAGS) -o $@ $^ | ||
19 | |||
20 | report.html: examples/*.hs Data/*.hs Data/OpenPGP/*.hs | ||
18 | hlint $(HLINTFLAGS) --report Data examples || true | 21 | hlint $(HLINTFLAGS) --report Data examples || true |
19 | 22 | ||
20 | doc: dist/doc/html/openpgp/index.html README | 23 | doc: dist/doc/html/openpgp/index.html README |
diff --git a/examples/keygen.hs b/examples/keygen.hs new file mode 100644 index 0000000..65c3e33 --- /dev/null +++ b/examples/keygen.hs | |||
@@ -0,0 +1,43 @@ | |||
1 | import System.Time (getClockTime, ClockTime(..)) | ||
2 | import qualified Data.Map as Map | ||
3 | import qualified Data.ByteString.Lazy as LZ | ||
4 | |||
5 | import Data.Binary | ||
6 | import OpenSSL.RSA | ||
7 | import Control.Arrow (second) | ||
8 | import Codec.Encryption.RSA.NumberTheory (extEuclGcd) | ||
9 | |||
10 | import qualified Data.OpenPGP as OpenPGP | ||
11 | import qualified Data.OpenPGP.Crypto as OpenPGP | ||
12 | |||
13 | main :: IO () | ||
14 | main = do | ||
15 | time <- getClockTime | ||
16 | let TOD t _ = time | ||
17 | |||
18 | nkey <- generateRSAKey' 1042 65537 | ||
19 | |||
20 | let secretKey = OpenPGP.SecretKeyPacket { | ||
21 | OpenPGP.version = 4, | ||
22 | OpenPGP.timestamp = fromIntegral t, | ||
23 | OpenPGP.key_algorithm = OpenPGP.RSA, | ||
24 | OpenPGP.key = Map.fromList $ map (second OpenPGP.MPI) | ||
25 | [('n', rsaN nkey), ('e', rsaE nkey), | ||
26 | ('d', rsaD nkey), ('p', rsaP nkey), ('q', rsaQ nkey), | ||
27 | ('u', fst $ extEuclGcd (rsaP nkey) (rsaQ nkey))], | ||
28 | OpenPGP.s2k_useage = 0, | ||
29 | OpenPGP.symmetric_type = undefined, | ||
30 | OpenPGP.s2k_type = undefined, | ||
31 | OpenPGP.s2k_hash_algorithm = undefined, | ||
32 | OpenPGP.s2k_salt = undefined, | ||
33 | OpenPGP.s2k_count = undefined, | ||
34 | OpenPGP.encrypted_data = undefined, | ||
35 | OpenPGP.private_hash = undefined } | ||
36 | |||
37 | let userID = OpenPGP.UserIDPacket "Test <test@example.com>" | ||
38 | let message = OpenPGP.Message[ secretKey, userID ] | ||
39 | |||
40 | let message' = OpenPGP.Message [ secretKey, userID, | ||
41 | OpenPGP.sign message message OpenPGP.SHA256 [] (fromIntegral t)] | ||
42 | |||
43 | LZ.putStr $ encode message' | ||