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
14 import Network.HTTP.Lucu
16 import OpenSSL.EVP.PKey
18 import qualified OpenSSL.Session as SSL
25 key ← generateRSAKey 1024 3 Nothing
27 SSL.contextSetPrivateKey ctx key
28 SSL.contextSetCertificate ctx cert
29 SSL.contextSetDefaultCiphers ctx
31 let config = defaultConfig {
32 cnfServerPort = "9000"
33 , cnfSSLConfig = Just SSLConfig {
34 sslServerPort = "9001"
39 tree = C.fromList [ ([], nonGreedy helloWorld) ]
40 putStrLn "Access https://localhost:9001/ with your browser."
41 withSocketsDo $ runHttpd config $ resourceMap tree
47 , do setContentType [mimeType| text/plain |]
48 putChunk "getRemoteCertificate = "
49 cert ← do cert ← getRemoteCertificate
51 Just c → liftIO $ Lazy.pack <$> printX509 c
52 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