7 import Control.Applicative
8 import Control.Monad.IO.Class
9 import Control.Monad.Unicode
10 import qualified Data.ByteString.Lazy.Char8 as Lazy
11 import qualified Data.Collections as C
13 import Data.Time.Clock
15 import Network.HTTP.Lucu
17 import OpenSSL.EVP.PKey
19 import qualified OpenSSL.Session as SSL
21 import Prelude.Unicode
27 key ← generateRSAKey 1024 3 Nothing
29 SSL.contextSetPrivateKey ctx key
30 SSL.contextSetCertificate ctx cert
31 SSL.contextSetDefaultCiphers ctx
34 cnfServerPort = "9000"
35 , cnfSSLConfig = Just SSLConfig {
36 sslServerPort = "9001"
41 tree = C.fromList [ ([], nonGreedy helloWorld) ]
42 putStrLn "Access https://localhost:9001/ with your browser."
43 withSocketsDo ∘ runHttpd config $ resourceMap tree
49 , do setContentType [mimeType| text/plain |]
50 putChunk "getRemoteCertificate = "
51 cert ← do cert ← getRemoteCertificate
53 Just c → liftIO $ Lazy.pack <$> printX509 c
54 Nothing → return "Nothing"
58 genCert ∷ KeyPair k ⇒ k → IO X509
62 setSerialNumber cert 1
63 setIssuerName cert [("CN", "localhost")]
64 setSubjectName cert [("CN", "localhost")]
65 setNotBefore cert =≪ addUTCTime (-1) <$> getCurrentTime
66 setNotAfter cert =≪ addUTCTime (365 * 24 * 60 * 60) <$> getCurrentTime
67 setPublicKey cert pkey
68 signX509 cert pkey Nothing