diff options
author | Andrew Cady <d@jerkface.net> | 2016-01-24 01:53:55 -0500 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2016-01-24 01:53:55 -0500 |
commit | fdf06576f7d21392f512492b164df899136f30d3 (patch) | |
tree | bd490b0e629d851660441eb96c34ffb8148a5436 /src | |
parent | 05817369d9388d2175e942af79888ec01aa4b74a (diff) |
Validate email address
Diffstat (limited to 'src')
-rw-r--r-- | src/Network/ACME.hs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/Network/ACME.hs b/src/Network/ACME.hs index ccd0a8c..d6a0f47 100644 --- a/src/Network/ACME.hs +++ b/src/Network/ACME.hs | |||
@@ -1,6 +1,6 @@ | |||
1 | {-# LANGUAGE OverloadedStrings #-} | 1 | {-# LANGUAGE OverloadedStrings #-} |
2 | {-# LANGUAGE RecordWildCards #-} | 2 | {-# LANGUAGE RecordWildCards #-} |
3 | {-# LANGUAGE ScopedTypeVariables #-} | 3 | {-# LANGUAGE ScopedTypeVariables #-} |
4 | 4 | ||
5 | module Network.ACME ( | 5 | module Network.ACME ( |
6 | Keys(..), | 6 | Keys(..), |
@@ -32,6 +32,8 @@ import OpenSSL.EVP.PKey | |||
32 | import OpenSSL.EVP.Sign | 32 | import OpenSSL.EVP.Sign |
33 | import OpenSSL.PEM | 33 | import OpenSSL.PEM |
34 | import OpenSSL.RSA | 34 | import OpenSSL.RSA |
35 | import Text.Email.Validate | ||
36 | import qualified Data.Text as T | ||
35 | 37 | ||
36 | data Keys = Keys RSAKeyPair RSAPubKey | 38 | data Keys = Keys RSAKeyPair RSAPubKey |
37 | readKeys :: String -> IO (Maybe Keys) | 39 | readKeys :: String -> IO (Maybe Keys) |
@@ -69,7 +71,7 @@ header key nonce = (toStrict . encode) | |||
69 | (Header "RS256" (JWK (rsaE key) "RSA" (rsaN key)) (Just nonce)) | 71 | (Header "RS256" (JWK (rsaE key) "RSA" (rsaN key)) (Just nonce)) |
70 | 72 | ||
71 | -- | Registration payload to sign with user key. | 73 | -- | Registration payload to sign with user key. |
72 | registration :: String -> String -> ByteString | 74 | registration :: EmailAddress -> String -> ByteString |
73 | registration emailAddr terms = (b64 . toStrict . encode) (Reg emailAddr terms) | 75 | registration emailAddr terms = (b64 . toStrict . encode) (Reg emailAddr terms) |
74 | 76 | ||
75 | -- | Challenge request payload to sign with user key. | 77 | -- | Challenge request payload to sign with user key. |
@@ -125,7 +127,7 @@ instance ToJSON JWK where | |||
125 | ] | 127 | ] |
126 | 128 | ||
127 | data Reg = Reg | 129 | data Reg = Reg |
128 | { rMail :: String | 130 | { rMail :: EmailAddress |
129 | , rAgreement :: String | 131 | , rAgreement :: String |
130 | } | 132 | } |
131 | deriving Show | 133 | deriving Show |
@@ -133,7 +135,7 @@ data Reg = Reg | |||
133 | instance ToJSON Reg where | 135 | instance ToJSON Reg where |
134 | toJSON Reg{..} = object | 136 | toJSON Reg{..} = object |
135 | [ "resource" .= ("new-reg" :: String) | 137 | [ "resource" .= ("new-reg" :: String) |
136 | , "contact" .= ["mailto:" ++ rMail] | 138 | , "contact" .= ["mailto:" ++ (T.unpack . decodeUtf8 . toByteString $ rMail)] |
137 | , "agreement" .= rAgreement | 139 | , "agreement" .= rAgreement |
138 | ] | 140 | ] |
139 | 141 | ||