{-# LANGUAGE OverloadedStrings #-}
module Network.Wai.Handler.WarpTLS.Internal (
CertSettings (..),
TLSSettings (..),
defaultTlsSettings,
OnInsecure (..),
getCertSettings,
) where
import qualified Data.ByteString as S
import qualified Data.ByteString.Lazy as L
import Data.Default.Class (def)
import qualified Data.IORef as I
import qualified Network.TLS as TLS
import qualified Network.TLS.Extra as TLSExtra
import qualified Network.TLS.SessionManager as SM
data CertSettings
= CertFromFile !FilePath ![FilePath] !FilePath
| CertFromMemory !S.ByteString ![S.ByteString] !S.ByteString
| CertFromRef
!(I.IORef S.ByteString)
![I.IORef S.ByteString]
!(I.IORef S.ByteString)
instance Show CertSettings where
show :: CertSettings -> String
show (CertFromFile String
a [String]
b String
c) = String
"CertFromFile " String -> ShowS
forall a. [a] -> [a] -> [a]
++ ShowS
forall a. Show a => a -> String
show String
a String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
forall a. Show a => a -> String
show [String]
b String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ ShowS
forall a. Show a => a -> String
show String
c
show (CertFromMemory ByteString
a [ByteString]
b ByteString
c) = String
"CertFromMemory " String -> ShowS
forall a. [a] -> [a] -> [a]
++ ByteString -> String
forall a. Show a => a -> String
show ByteString
a String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ [ByteString] -> String
forall a. Show a => a -> String
show [ByteString]
b String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ ByteString -> String
forall a. Show a => a -> String
show ByteString
c
show (CertFromRef IORef ByteString
_ [IORef ByteString]
_ IORef ByteString
_) = String
"CertFromRef"
data OnInsecure
= DenyInsecure L.ByteString
| AllowInsecure
deriving (Int -> OnInsecure -> ShowS
[OnInsecure] -> ShowS
OnInsecure -> String
(Int -> OnInsecure -> ShowS)
-> (OnInsecure -> String)
-> ([OnInsecure] -> ShowS)
-> Show OnInsecure
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> OnInsecure -> ShowS
showsPrec :: Int -> OnInsecure -> ShowS
$cshow :: OnInsecure -> String
show :: OnInsecure -> String
$cshowList :: [OnInsecure] -> ShowS
showList :: [OnInsecure] -> ShowS
Show)
data TLSSettings = TLSSettings
{ TLSSettings -> CertSettings
certSettings :: CertSettings
, TLSSettings -> OnInsecure
onInsecure :: OnInsecure
, TLSSettings -> Logging
tlsLogging :: TLS.Logging
, TLSSettings -> [Version]
tlsAllowedVersions :: [TLS.Version]
, TLSSettings -> [Cipher]
tlsCiphers
:: [TLS.Cipher]
, TLSSettings -> Bool
tlsWantClientCert :: Bool
, TLSSettings -> ServerHooks
tlsServerHooks :: TLS.ServerHooks
, TLSSettings -> Maybe DHParams
tlsServerDHEParams :: Maybe TLS.DHParams
, TLSSettings -> Maybe Config
tlsSessionManagerConfig :: Maybe SM.Config
, TLSSettings -> Maybe Credentials
tlsCredentials :: Maybe TLS.Credentials
, TLSSettings -> Maybe SessionManager
tlsSessionManager :: Maybe TLS.SessionManager
, TLSSettings -> [HashAndSignatureAlgorithm]
tlsSupportedHashSignatures :: [TLS.HashAndSignatureAlgorithm]
}
getCertSettings :: TLSSettings -> CertSettings
getCertSettings :: TLSSettings -> CertSettings
getCertSettings = TLSSettings -> CertSettings
certSettings
defaultCertSettings :: CertSettings
defaultCertSettings :: CertSettings
defaultCertSettings = String -> [String] -> String -> CertSettings
CertFromFile String
"certificate.pem" [] String
"key.pem"
defaultTlsSettings :: TLSSettings
defaultTlsSettings :: TLSSettings
defaultTlsSettings =
TLSSettings
{ certSettings :: CertSettings
certSettings = CertSettings
defaultCertSettings
, onInsecure :: OnInsecure
onInsecure = ByteString -> OnInsecure
DenyInsecure ByteString
"This server only accepts secure HTTPS connections."
, tlsLogging :: Logging
tlsLogging = Logging
forall a. Default a => a
def
, tlsAllowedVersions :: [Version]
tlsAllowedVersions = Supported -> [Version]
TLS.supportedVersions Supported
forall a. Default a => a
def
, tlsCiphers :: [Cipher]
tlsCiphers = [Cipher]
ciphers
, tlsWantClientCert :: Bool
tlsWantClientCert = Bool
False
, tlsServerHooks :: ServerHooks
tlsServerHooks = ServerHooks
forall a. Default a => a
def
, tlsServerDHEParams :: Maybe DHParams
tlsServerDHEParams = Maybe DHParams
forall a. Maybe a
Nothing
, tlsSessionManagerConfig :: Maybe Config
tlsSessionManagerConfig = Maybe Config
forall a. Maybe a
Nothing
, tlsCredentials :: Maybe Credentials
tlsCredentials = Maybe Credentials
forall a. Maybe a
Nothing
, tlsSessionManager :: Maybe SessionManager
tlsSessionManager = Maybe SessionManager
forall a. Maybe a
Nothing
, tlsSupportedHashSignatures :: [HashAndSignatureAlgorithm]
tlsSupportedHashSignatures = Supported -> [HashAndSignatureAlgorithm]
TLS.supportedHashSignatures Supported
forall a. Default a => a
def
}
ciphers :: [TLS.Cipher]
ciphers :: [Cipher]
ciphers = [Cipher]
TLSExtra.ciphersuite_strong