1 {-# LANGUAGE PackageImports #-}
3 import "mtl" Control.Monad.Trans
6 import Network.HTTP.Lucu
8 import OpenSSL.EVP.PKey
10 import qualified OpenSSL.Session as SSL
17 key <- generateRSAKey 1024 3 Nothing
19 SSL.contextSetPrivateKey ctx key
20 SSL.contextSetCertificate ctx cert
21 SSL.contextSetDefaultCiphers ctx
23 let config = defaultConfig {
24 cnfServerPort = PortNumber 9000
25 , cnfSSLConfig = Just SSLConfig {
26 sslServerPort = PortNumber 9001
30 resources = mkResTree [ ( []
33 putStrLn "Access https://localhost:9001/ with your browser."
34 runHttpd config resources []
37 helloWorld :: ResourceDef
40 resUsesNativeThread = False
43 = Just $ do setContentType $ read "text/plain"
44 outputChunk "getRemoteCertificate = "
45 cert <- do c <- getRemoteCertificate
47 Just c -> liftIO $ printX509 c
48 Nothing -> return "Nothing"
57 genCert :: KeyPair k => k -> IO X509
61 setSerialNumber cert 1
62 setIssuerName cert [("CN", "localhost")]
63 setSubjectName cert [("CN", "localhost")]
64 setNotBefore cert =<< liftM (addUTCTime (-1)) getCurrentTime
65 setNotAfter cert =<< liftM (addUTCTime (365 * 24 * 60 * 60)) getCurrentTime
66 setPublicKey cert pkey
67 signX509 cert pkey Nothing