diff options
author | Andrew Cady <d@jerkface.net> | 2016-01-20 07:01:29 -0500 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2016-01-20 07:01:29 -0500 |
commit | ec64081c83707657ee1aa641d193d346f292e744 (patch) | |
tree | caea5f40685ca7935d6084ec84838885ea4ca327 | |
parent | df5eb4c682ddda18282d6d2230b1451c4dcd644f (diff) |
add Wreq and Lens libraries
-rw-r--r-- | acme-encrypt.cabal | 4 | ||||
-rw-r--r-- | acme.hs | 34 |
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 | ||
@@ -21,22 +21,10 @@ import OpenSSL.EVP.PKey | |||
21 | import OpenSSL.PEM (readPublicKey) | 21 | import OpenSSL.PEM (readPublicKey) |
22 | import OpenSSL.RSA | 22 | import OpenSSL.RSA |
23 | import System.Process (readProcess) | 23 | import System.Process (readProcess) |
24 | import Network.Wreq hiding (header) | ||
25 | import Control.Lens hiding ((.=)) | ||
24 | 26 | ||
25 | 27 | ||
26 | -------------------------------------------------------------------------------- | ||
27 | email :: String | ||
28 | email = "noteed@gmail.com" | ||
29 | |||
30 | domain :: String | ||
31 | domain = "aaa.reesd.com" | ||
32 | |||
33 | nonce_ :: String | ||
34 | nonce_ = "ckYlMQ7BflfUb7HmxipdSpnkFle83-8lUkn50U-X97Q" | ||
35 | |||
36 | terms :: String | ||
37 | terms = "https://letsencrypt.org/documents/LE-SA-v1.0.1-July-27-2015.pdf" | ||
38 | |||
39 | -------------------------------------------------------------------------------- | ||
40 | main :: IO () | 28 | main :: IO () |
41 | main = do | 29 | main = 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. |
130 | registration :: String -> ByteString | 130 | registration :: String -> String -> ByteString |
131 | registration emailAddr = (b64 . toStrict . encode) (Reg emailAddr terms) | 131 | registration 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. |
134 | authz :: String -> ByteString | 134 | authz :: String -> ByteString |