1 {-# LANGUAGE PackageImports #-}
3 import "mtl" Control.Monad.Trans
5 import Network.HTTP.Lucu
7 import OpenSSL.EVP.PKey
9 import qualified OpenSSL.Session as SSL
16 key <- generateRSAKey 1024 3 Nothing
18 SSL.contextSetPrivateKey ctx key
19 SSL.contextSetCertificate ctx cert
20 SSL.contextSetDefaultCiphers ctx
22 let config = defaultConfig {
23 cnfServerPort = "9000"
24 , cnfSSLConfig = Just SSLConfig {
25 sslServerPort = "9001"
29 resources = mkResTree [ ( []
32 putStrLn "Access https://localhost:9001/ with your browser."
33 runHttpd config resources []
36 helloWorld :: ResourceDef
39 resUsesNativeThread = False
42 = Just $ do setContentType $ read "text/plain"
43 outputChunk "getRemoteCertificate = "
44 cert <- do c <- getRemoteCertificate
46 Just c -> liftIO $ printX509 c
47 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 =<< liftM (addUTCTime (-1)) getCurrentTime
64 setNotAfter cert =<< liftM (addUTCTime (365 * 24 * 60 * 60)) getCurrentTime
65 setPublicKey cert pkey
66 signX509 cert pkey Nothing