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
12 import Data.Time.Clock
13 import Network.HTTP.Lucu
15 import OpenSSL.EVP.PKey
17 import qualified OpenSSL.Session as SSL
24 key ← generateRSAKey 1024 3 Nothing
26 SSL.contextSetPrivateKey ctx key
27 SSL.contextSetCertificate ctx cert
28 SSL.contextSetDefaultCiphers ctx
30 let config = defaultConfig {
31 cnfServerPort = "9000"
32 , cnfSSLConfig = Just SSLConfig {
33 sslServerPort = "9001"
38 tree = C.fromList [ ([], nonGreedy helloWorld) ]
39 putStrLn "Access https://localhost:9001/ with your browser."
40 runHttpd config $ resourceMap tree
46 , do setContentType [mimeType| text/plain |]
47 putChunk "getRemoteCertificate = "
48 cert ← do cert ← getRemoteCertificate
50 Just c → liftIO $ Lazy.pack <$> printX509 c
51 Nothing → return "Nothing"
56 genCert ∷ KeyPair k ⇒ k → IO X509
60 setSerialNumber cert 1
61 setIssuerName cert [("CN", "localhost")]
62 setSubjectName cert [("CN", "localhost")]
63 setNotBefore cert =≪ addUTCTime (-1) <$> getCurrentTime
64 setNotAfter cert =≪ addUTCTime (365 * 24 * 60 * 60) <$> getCurrentTime
65 setPublicKey cert pkey
66 signX509 cert pkey Nothing