summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2016-01-20 07:01:29 -0500
committerAndrew Cady <d@jerkface.net>2016-01-20 07:01:29 -0500
commitec64081c83707657ee1aa641d193d346f292e744 (patch)
treecaea5f40685ca7935d6084ec84838885ea4ca327
parentdf5eb4c682ddda18282d6d2230b1451c4dcd644f (diff)
add Wreq and Lens libraries
-rw-r--r--acme-encrypt.cabal4
-rw-r--r--acme.hs34
2 files changed, 20 insertions, 18 deletions
diff --git a/acme-encrypt.cabal b/acme-encrypt.cabal
index 0faf99b..824b09d 100644
--- a/acme-encrypt.cabal
+++ b/acme-encrypt.cabal
@@ -21,7 +21,9 @@ executable acme-encrypt-exe
21 -- hs-source-dirs: app 21 -- hs-source-dirs: app
22 main-is: acme.hs 22 main-is: acme.hs
23 ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall 23 ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall
24 build-depends: base, cryptonite, aeson, bytestring, base64-bytestring, SHA, text, HsOpenSSL, process 24 build-depends: base,
25 cryptonite, aeson, bytestring, base64-bytestring, SHA,
26 text, HsOpenSSL, process, wreq, lens
25 -- , acme-encrypt 27 -- , acme-encrypt
26 default-language: Haskell2010 28 default-language: Haskell2010
27 29
diff --git a/acme.hs b/acme.hs
index 737968f..2f8138c 100644
--- a/acme.hs
+++ b/acme.hs
@@ -21,22 +21,10 @@ import OpenSSL.EVP.PKey
21import OpenSSL.PEM (readPublicKey) 21import OpenSSL.PEM (readPublicKey)
22import OpenSSL.RSA 22import OpenSSL.RSA
23import System.Process (readProcess) 23import System.Process (readProcess)
24import Network.Wreq hiding (header)
25import Control.Lens hiding ((.=))
24 26
25 27
26--------------------------------------------------------------------------------
27email :: String
28email = "noteed@gmail.com"
29
30domain :: String
31domain = "aaa.reesd.com"
32
33nonce_ :: String
34nonce_ = "ckYlMQ7BflfUb7HmxipdSpnkFle83-8lUkn50U-X97Q"
35
36terms :: String
37terms = "https://letsencrypt.org/documents/LE-SA-v1.0.1-July-27-2015.pdf"
38
39--------------------------------------------------------------------------------
40main :: IO () 28main :: IO ()
41main = do 29main = do
42 userKey_ <- readFile "user.pub" >>= readPublicKey 30 userKey_ <- readFile "user.pub" >>= readPublicKey
@@ -46,7 +34,7 @@ main = do
46 let protected = b64 (header userKey nonce_) 34 let protected = b64 (header userKey nonce_)
47 35
48 -- Create user account 36 -- Create user account
49 signPayload "registration" userKey protected (registration email) 37 signPayload "registration" userKey protected (registration email terms)
50 38
51 -- Obtain a challenge 39 -- Obtain a challenge
52 signPayload "challenge-request" userKey protected (authz domain) 40 signPayload "challenge-request" userKey protected (authz domain)
@@ -70,6 +58,18 @@ main = do
70 csr_ <- B.readFile (domain ++ ".csr.der") 58 csr_ <- B.readFile (domain ++ ".csr.der")
71 signPayload "csr-request" userKey protected (csr csr_) 59 signPayload "csr-request" userKey protected (csr csr_)
72 60
61 where
62 email :: String
63 email = "noteed@gmail.com"
64
65 domain :: String
66 domain = "aaa.reesd.com"
67
68 nonce_ :: String
69 nonce_ = "ckYlMQ7BflfUb7HmxipdSpnkFle83-8lUkn50U-X97Q"
70
71 terms :: String
72 terms = "https://letsencrypt.org/documents/LE-SA-v1.0.1-July-27-2015.pdf"
73 73
74-------------------------------------------------------------------------------- 74--------------------------------------------------------------------------------
75-- | Sign and write a payload to a file with a nonce-protected header. 75-- | Sign and write a payload to a file with a nonce-protected header.
@@ -127,8 +127,8 @@ header key nonce = (toStrict . encode)
127 (Header "RS256" (JWK (rsaE key) "RSA" (rsaN key)) (Just nonce)) 127 (Header "RS256" (JWK (rsaE key) "RSA" (rsaN key)) (Just nonce))
128 128
129-- | Registration payload to sign with user key. 129-- | Registration payload to sign with user key.
130registration :: String -> ByteString 130registration :: String -> String -> ByteString
131registration emailAddr = (b64 . toStrict . encode) (Reg emailAddr terms) 131registration emailAddr terms = (b64 . toStrict . encode) (Reg emailAddr terms)
132 132
133-- | Challenge request payload to sign with user key. 133-- | Challenge request payload to sign with user key.
134authz :: String -> ByteString 134authz :: String -> ByteString