diff options
author | Vo Minh Thu <thu@hypered.io> | 2015-12-18 08:31:17 +0100 |
---|---|---|
committer | Vo Minh Thu <thu@hypered.io> | 2015-12-18 08:31:17 +0100 |
commit | 00e3068de0193564afb28759e5d8a5c6bdfc5ee5 (patch) | |
tree | 8122a5423a6a6a7c5edaeb5d2237ab75f4d47ca2 | |
parent | 7eb942214ee70af20b43fde9fea2f97388291d62 (diff) |
Refactor.
-rw-r--r-- | acme.hs | 37 |
1 files changed, 10 insertions, 27 deletions
@@ -45,25 +45,13 @@ main = do | |||
45 | Just (userKey :: RSAPubKey) -> do | 45 | Just (userKey :: RSAPubKey) -> do |
46 | let protected = b64 (header userKey nonce_) | 46 | let protected = b64 (header userKey nonce_) |
47 | 47 | ||
48 | -------------------------------------------------------------------------------- | ||
49 | -- Create user account | 48 | -- Create user account |
49 | signPayload "registration" userKey protected (registration email) | ||
50 | 50 | ||
51 | let payload = registration email | ||
52 | writePayload "registration" protected payload | ||
53 | sig <- sign "registration" | ||
54 | writeBody "registration" userKey protected payload sig | ||
55 | |||
56 | -------------------------------------------------------------------------------- | ||
57 | -- Obtain a challenge | 51 | -- Obtain a challenge |
52 | signPayload "challenge-request" userKey protected (authz domain) | ||
58 | 53 | ||
59 | let payload = authz domain | ||
60 | writePayload "challenge-request" protected payload | ||
61 | sig <- sign "challenge-request" | ||
62 | writeBody "challenge-request" userKey protected payload sig | ||
63 | |||
64 | -------------------------------------------------------------------------------- | ||
65 | -- Answser the challenge | 54 | -- Answser the challenge |
66 | |||
67 | let thumb = thumbprint (JWK (rsaE userKey) "RSA" (rsaN userKey)) | 55 | let thumb = thumbprint (JWK (rsaE userKey) "RSA" (rsaN userKey)) |
68 | -- Extracted from POST response above. | 56 | -- Extracted from POST response above. |
69 | token = "DjyJpI3HVWAmsAwMT5ZFpW8dj19cel6ml6qaBUeGpCg" | 57 | token = "DjyJpI3HVWAmsAwMT5ZFpW8dj19cel6ml6qaBUeGpCg" |
@@ -73,28 +61,23 @@ main = do | |||
73 | BC.unpack token) | 61 | BC.unpack token) |
74 | putStrLn ("With content:\n" ++ BC.unpack thumbtoken) | 62 | putStrLn ("With content:\n" ++ BC.unpack thumbtoken) |
75 | 63 | ||
76 | -------------------------------------------------------------------------------- | ||
77 | -- Notify Let's Encrypt we answsered the challenge | 64 | -- Notify Let's Encrypt we answsered the challenge |
65 | signPayload "challenge-response" userKey protected (challenge thumbtoken) | ||
78 | 66 | ||
79 | let payload = challenge thumbtoken | ||
80 | writePayload "challenge-response" protected payload | ||
81 | sig <- sign "challenge-response" | ||
82 | writeBody "challenge-response" userKey protected payload sig | ||
83 | |||
84 | -------------------------------------------------------------------------------- | ||
85 | -- Wait for challenge validation | 67 | -- Wait for challenge validation |
86 | 68 | ||
87 | -------------------------------------------------------------------------------- | ||
88 | -- Send a CSR and get a certificate | 69 | -- Send a CSR and get a certificate |
89 | |||
90 | csr_ <- B.readFile (domain ++ ".csr.der") | 70 | csr_ <- B.readFile (domain ++ ".csr.der") |
71 | signPayload "csr-request" userKey protected (csr csr_) | ||
91 | 72 | ||
92 | let payload = csr csr_ | ||
93 | writePayload "csr-request" protected payload | ||
94 | sig <- sign "csr-request" | ||
95 | writeBody "csr-request" userKey protected payload sig | ||
96 | 73 | ||
97 | -------------------------------------------------------------------------------- | 74 | -------------------------------------------------------------------------------- |
75 | -- | Sign and write a payload to a file with a nonce-protected header. | ||
76 | signPayload name key protected payload = do | ||
77 | writePayload name protected payload | ||
78 | sig <- sign name | ||
79 | writeBody name key protected payload sig | ||
80 | |||
98 | -- | Write a payload to file with a nonce-protected header. | 81 | -- | Write a payload to file with a nonce-protected header. |
99 | writePayload name protected payload = | 82 | writePayload name protected payload = |
100 | LB.writeFile (name ++ ".txt") (LB.fromChunks [protected, ".", payload]) | 83 | LB.writeFile (name ++ ".txt") (LB.fromChunks [protected, ".", payload]) |