| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Network.TLS
Description
Native Haskell TLS protocol implementation for servers and clients.
This provides a high-level implementation of a sensitive security protocol, eliminating a common set of security issues through the use of the advanced type system, high level constructions and common Haskell features.
Currently implement the TLS1.2 and TLS 1.3 protocol, and support RSA and Ephemeral (Elliptic curve and regular) Diffie Hellman key exchanges, and many extensions.
The typical usage is:
socket <- ... ctx <- contextNew socket <params> handshake ctx ... (using recvData and sendData) bye
Synopsis
- data Context
- contextNew :: (MonadIO m, HasBackend backend, TLSParams params) => backend -> params -> m Context
- handshake :: MonadIO m => Context -> m ()
- sendData :: MonadIO m => Context -> ByteString -> m ()
- recvData :: MonadIO m => Context -> m ByteString
- closeNotifyReceived :: MonadIO m => Context -> m Bool
- bye :: MonadIO m => Context -> m ()
- class HasBackend a where
- initializeBackend :: a -> IO ()
- getBackend :: a -> Backend
- data Backend = Backend {
- backendFlush :: IO ()
- backendClose :: IO ()
- backendSend :: ByteString -> IO ()
- backendRecv :: Int -> IO ByteString
- class TLSParams a
- data ClientParams
- defaultParamsClient :: HostName -> ByteString -> ClientParams
- clientServerIdentification :: ClientParams -> (HostName, ByteString)
- clientUseServerNameIndication :: ClientParams -> Bool
- clientWantSessionResume :: ClientParams -> Maybe (SessionID, SessionData)
- clientWantSessionResumeList :: ClientParams -> [(SessionID, SessionData)]
- clientWantTicket :: ClientParams -> Bool
- clientShared :: ClientParams -> Shared
- clientHooks :: ClientParams -> ClientHooks
- clientSupported :: ClientParams -> Supported
- clientDebug :: ClientParams -> DebugParams
- clientUseEarlyData :: ClientParams -> Bool
- clientUseECH :: ClientParams -> Bool
- data ServerParams
- defaultParamsServer :: ServerParams
- serverWantClientCert :: ServerParams -> Bool
- serverCACertificates :: ServerParams -> [SignedCertificate]
- serverDHEParams :: ServerParams -> Maybe DHParams
- serverHooks :: ServerParams -> ServerHooks
- serverShared :: ServerParams -> Shared
- serverSupported :: ServerParams -> Supported
- serverDebug :: ServerParams -> DebugParams
- serverEarlyDataSize :: ServerParams -> Int
- serverTicketLifetime :: ServerParams -> Int
- serverECHKey :: ServerParams -> [(ConfigId, ByteString)]
- data Shared
- defaultShared :: Shared
- sharedCredentials :: Shared -> Credentials
- sharedSessionManager :: Shared -> SessionManager
- sharedCAStore :: Shared -> CertificateStore
- sharedValidationCache :: Shared -> ValidationCache
- sharedHelloExtensions :: Shared -> [ExtensionRaw]
- sharedECHConfigList :: Shared -> ECHConfigList
- sharedLimit :: Shared -> Limit
- data ClientHooks
- defaultClientHooks :: ClientHooks
- type OnCertificateRequest = ([CertificateType], Maybe [SignatureScheme], [DistinguishedName]) -> IO (Maybe (CertificateChain, PrivKey))
- onCertificateRequest :: ClientHooks -> OnCertificateRequest
- type OnServerCertificate = CertificateStore -> ValidationCache -> ServiceID -> CertificateChain -> IO [FailedReason]
- onServerCertificate :: ClientHooks -> OnServerCertificate
- onSuggestALPN :: ClientHooks -> IO (Maybe [ByteString])
- onCustomFFDHEGroup :: ClientHooks -> DHParams -> DHPublic -> IO GroupUsage
- onServerFinished :: ClientHooks -> Information -> IO ()
- onSelectKeyShareGroups :: ClientHooks -> [Group] -> [Group]
- data ServerHooks
- defaultServerHooks :: ServerHooks
- onClientCertificate :: ServerHooks -> CertificateChain -> IO CertificateUsage
- validateClientCertificate :: CertificateStore -> ValidationCache -> CertificateChain -> IO CertificateUsage
- onUnverifiedClientCert :: ServerHooks -> IO Bool
- onCipherChoosing :: ServerHooks -> Version -> [Cipher] -> Cipher
- onServerNameIndication :: ServerHooks -> Maybe HostName -> IO Credentials
- onNewHandshake :: ServerHooks -> Measurement -> IO Bool
- onALPNClientSuggest :: ServerHooks -> Maybe ([ByteString] -> IO ByteString)
- onEncryptedExtensionsCreating :: ServerHooks -> [ExtensionRaw] -> IO [ExtensionRaw]
- onSelectKeyShare :: ServerHooks -> [[Group]] -> [Group] -> [Group] -> IO (Maybe Group, Bool)
- onAccept0RTT :: ServerHooks -> SessionData -> IO Bool
- data Measurement
- nbHandshakes :: Measurement -> Word32
- bytesReceived :: Measurement -> Word32
- bytesSent :: Measurement -> Word32
- data Supported
- defaultSupported :: Supported
- supportedVersions :: Supported -> [Version]
- supportedCiphers :: Supported -> [Cipher]
- supportedMinRSAKeySize :: Supported -> Int
- supportedMaxRSAKeySize :: Supported -> Int
- supportedClientCertificatePurposes :: Supported -> [ExtKeyUsagePurpose]
- supportedMinDHKeySize :: Supported -> Int
- supportedMaxDHKeySize :: Supported -> Int
- supportedClientCipherOrder :: Supported -> Bool
- supportedCompressions :: Supported -> [Compression]
- supportedHashSignatures :: Supported -> [SignatureScheme]
- supportedSecureRenegotiation :: Supported -> Bool
- supportedClientInitiatedRenegotiation :: Supported -> Bool
- supportedExtendedMainSecret :: Supported -> EMSMode
- supportedSession :: Supported -> Bool
- supportedFallbackScsv :: Supported -> Bool
- supportedEmptyPacket :: Supported -> Bool
- supportedGroups :: Supported -> [Group]
- supportedGroupsTLS13 :: Supported -> [[Group]]
- data DebugParams
- defaultDebugParams :: DebugParams
- debugSeed :: DebugParams -> Maybe Seed
- debugPrintSeed :: DebugParams -> Seed -> IO ()
- debugVersionForced :: DebugParams -> Maybe Version
- debugKeyLogger :: DebugParams -> String -> IO ()
- defaultKeyLogger :: String -> IO ()
- debugError :: DebugParams -> String -> IO ()
- debugTraceKey :: DebugParams -> String -> IO ()
- data Limit
- defaultLimit :: Limit
- limitHandshakeFragment :: Limit -> Int
- limitKeyUpdate :: Limit -> Maybe Int
- limitRecordSize :: Limit -> Maybe Int
- limitRecordsPerKey :: Limit -> Maybe Word64
- newtype Credentials = Credentials [Credential]
- type Credential = (CertificateChain, PrivKey)
- credentialLoadX509 :: FilePath -> FilePath -> IO (Either String Credential)
- credentialLoadX509FromMemory :: ByteString -> ByteString -> Either String Credential
- credentialLoadX509Chain :: FilePath -> [FilePath] -> FilePath -> IO (Either String Credential)
- credentialLoadX509ChainFromMemory :: ByteString -> [ByteString] -> ByteString -> Either String Credential
- data SessionManager
- noSessionManager :: SessionManager
- sessionResume :: SessionManager -> SessionIDorTicket -> IO (Maybe SessionData)
- sessionResumeOnlyOnce :: SessionManager -> SessionIDorTicket -> IO (Maybe SessionData)
- sessionEstablish :: SessionManager -> SessionIDorTicket -> SessionData -> IO (Maybe Ticket)
- sessionInvalidate :: SessionManager -> SessionIDorTicket -> IO ()
- sessionUseTicket :: SessionManager -> Bool
- type SessionID = ByteString
- type SessionIDorTicket = ByteString
- type Ticket = ByteString
- data SessionData
- defaultSessionData :: SessionData
- sessionVersion :: SessionData -> Version
- sessionCipher :: SessionData -> CipherID
- sessionCompression :: SessionData -> CompressionID
- sessionClientSNI :: SessionData -> Maybe HostName
- sessionSecret :: SessionData -> ByteString
- sessionGroup :: SessionData -> Maybe Group
- sessionTicketInfo :: SessionData -> Maybe TLS13TicketInfo
- sessionALPN :: SessionData -> Maybe ByteString
- sessionMaxEarlyDataSize :: SessionData -> Int
- sessionFlags :: SessionData -> [SessionFlag]
- sessionClientCertificate :: SessionData -> Maybe ByteString
- sessionAppData :: SessionData -> Maybe ByteString
- data SessionFlag = SessionEMS
- data TLS13TicketInfo
- is0RTTPossible :: SessionData -> Bool
- data ValidationCache = ValidationCache {}
- defaultValidationCache :: ValidationCache
- type ValidationCacheQueryCallback = ServiceID -> Fingerprint -> Certificate -> IO ValidationCacheResult
- type ValidationCacheAddCallback = ServiceID -> Fingerprint -> Certificate -> IO ()
- data ValidationCacheResult
- exceptionValidationCache :: [(ServiceID, Fingerprint)] -> ValidationCache
- newtype Version where
- data Compression = CompressionC a => Compression a
- nullCompression :: Compression
- newtype SignatureScheme where
- SignatureScheme {
- fromSignatureScheme :: Word16
- pattern DSA_MD5 :: SignatureScheme
- pattern DSA_SHA1 :: SignatureScheme
- pattern DSA_SHA224 :: SignatureScheme
- pattern DSA_SHA256 :: SignatureScheme
- pattern DSA_SHA384 :: SignatureScheme
- pattern DSA_SHA512 :: SignatureScheme
- pattern ECDSA_BRAINPOOLP256R1TLS13_SHA256 :: SignatureScheme
- pattern ECDSA_BRAINPOOLP384R1TLS13_SHA384 :: SignatureScheme
- pattern ECDSA_BRAINPOOLP512R1TLS13_SHA512 :: SignatureScheme
- pattern ECDSA_MD5 :: SignatureScheme
- pattern ECDSA_SECP256R1_SHA256 :: SignatureScheme
- pattern ECDSA_SECP384R1_SHA384 :: SignatureScheme
- pattern ECDSA_SECP521R1_SHA512 :: SignatureScheme
- pattern ECDSA_SHA1 :: SignatureScheme
- pattern ECDSA_SHA224 :: SignatureScheme
- pattern ED25519 :: SignatureScheme
- pattern ED448 :: SignatureScheme
- pattern MLDSA44 :: SignatureScheme
- pattern MLDSA65 :: SignatureScheme
- pattern MLDSA87 :: SignatureScheme
- pattern RSA_PKCS1_MD5 :: SignatureScheme
- pattern RSA_PKCS1_SHA1 :: SignatureScheme
- pattern RSA_PKCS1_SHA224 :: SignatureScheme
- pattern RSA_PKCS1_SHA256 :: SignatureScheme
- pattern RSA_PKCS1_SHA384 :: SignatureScheme
- pattern RSA_PKCS1_SHA512 :: SignatureScheme
- pattern RSA_PSS_PSS_SHA256 :: SignatureScheme
- pattern RSA_PSS_PSS_SHA384 :: SignatureScheme
- pattern RSA_PSS_PSS_SHA512 :: SignatureScheme
- pattern RSA_PSS_RSAE_SHA256 :: SignatureScheme
- pattern RSA_PSS_RSAE_SHA384 :: SignatureScheme
- pattern RSA_PSS_RSAE_SHA512 :: SignatureScheme
- SignatureScheme {
- type HashAndSignatureAlgorithm = SignatureScheme
- supportedSignatureSchemes :: [SignatureScheme]
- signatureSchemesForTLS13 :: [SignatureScheme]
- newtype Group where
- Group Word16
- pattern FFDHE2048 :: Group
- pattern FFDHE3072 :: Group
- pattern FFDHE4096 :: Group
- pattern FFDHE6144 :: Group
- pattern FFDHE8192 :: Group
- pattern MLKEM1024 :: Group
- pattern MLKEM512 :: Group
- pattern MLKEM768 :: Group
- pattern P256 :: Group
- pattern P256MLKEM768 :: Group
- pattern P384 :: Group
- pattern P384MLKEM1024 :: Group
- pattern P521 :: Group
- pattern X25519 :: Group
- pattern X25519MLKEM768 :: Group
- pattern X448 :: Group
- supportedNamedGroups :: [Group]
- data EMSMode
- = NoEMS
- | AllowEMS
- | RequireEMS
- type DHParams = Params
- type DHPublic = PublicNumber
- data GroupUsage
- data CertificateUsage
- data CertificateRejectReason
- newtype CertificateType where
- CertificateType {
- fromCertificateType :: Word8
- pattern CertificateType_DSA_Sign :: CertificateType
- pattern CertificateType_ECDSA_Sign :: CertificateType
- pattern CertificateType_Ed25519_Sign :: CertificateType
- pattern CertificateType_Ed448_Sign :: CertificateType
- pattern CertificateType_RSA_Sign :: CertificateType
- CertificateType {
- newtype CertificateChain = CertificateChain [SignedExact Certificate]
- type HostName = String
- data MaxFragmentEnum
- ctxBackend :: Context -> Backend
- contextFlush :: Context -> IO ()
- contextClose :: Context -> IO ()
- data Information
- contextGetInformation :: Context -> IO (Maybe Information)
- infoVersion :: Information -> Version
- infoCipher :: Information -> Cipher
- infoCompression :: Information -> Compression
- infoMainSecret :: Information -> Maybe ByteString
- infoExtendedMainSecret :: Information -> Bool
- infoClientRandom :: Information -> Maybe ClientRandom
- infoServerRandom :: Information -> Maybe ServerRandom
- infoSupportedGroup :: Information -> Maybe Group
- infoTLS12Resumption :: Information -> Bool
- infoTLS13HandshakeMode :: Information -> Maybe HandshakeMode13
- infoIsEarlyDataAccepted :: Information -> Bool
- infoIsECHAccepted :: Information -> Bool
- infoServerSignatureScheme :: Information -> Maybe SignatureScheme
- infoClientSignatureScheme :: Information -> Maybe SignatureScheme
- data ClientRandom
- data ServerRandom
- unClientRandom :: ClientRandom -> ByteString
- unServerRandom :: ServerRandom -> ByteString
- data HandshakeMode13
- getClientCertificateChain :: Context -> IO (Maybe CertificateChain)
- getServerCertificateChain :: Context -> IO (Maybe CertificateChain)
- getNegotiatedProtocol :: MonadIO m => Context -> m (Maybe ByteString)
- getClientSNI :: MonadIO m => Context -> m (Maybe HostName)
- updateKey :: MonadIO m => Context -> KeyUpdateRequest -> m Bool
- data KeyUpdateRequest
- requestCertificate :: Context -> IO Bool
- requestCertificateAsync :: Context -> IO (Bool -> IO PHAResult)
- data PHAResult
- getTLSUnique :: Context -> IO (Maybe ByteString)
- getTLSExporter :: Context -> IO (Maybe ByteString)
- getTLSServerEndPoint :: Context -> IO (Maybe ByteString)
- getFinished :: Context -> IO (Maybe VerifyData)
- getPeerFinished :: Context -> IO (Maybe VerifyData)
- data Hooks
- defaultHooks :: Hooks
- hookRecvHandshake :: Hooks -> Handshake -> IO Handshake
- hookRecvHandshake13 :: Hooks -> Handshake13 -> IO Handshake13
- hookRecvCertificates :: Hooks -> CertificateChain -> IO ()
- hookLogging :: Hooks -> Logging
- contextModifyHooks :: Context -> (Hooks -> Hooks) -> IO ()
- data Handshake
- contextHookSetHandshakeRecv :: Context -> (Handshake -> IO Handshake) -> IO ()
- data Handshake13
- contextHookSetHandshake13Recv :: Context -> (Handshake13 -> IO Handshake13) -> IO ()
- contextHookSetCertificateRecv :: Context -> (CertificateChain -> IO ()) -> IO ()
- data Logging
- defaultLogging :: Logging
- loggingPacketSent :: Logging -> String -> IO ()
- loggingPacketRecv :: Logging -> String -> IO ()
- loggingIOSent :: Logging -> ByteString -> IO ()
- loggingIORecv :: Logging -> Header -> ByteString -> IO ()
- data Header = Header ProtocolType Version Word16
- newtype ProtocolType where
- ProtocolType {
- fromProtocolType :: Word8
- pattern ProtocolType_Alert :: ProtocolType
- pattern ProtocolType_AppData :: ProtocolType
- pattern ProtocolType_ChangeCipherSpec :: ProtocolType
- pattern ProtocolType_Handshake :: ProtocolType
- ProtocolType {
- contextHookSetLogging :: Context -> Logging -> IO ()
- data TLSError
- = Error_Misc String
- | Error_Protocol String AlertDescription
- | Error_Protocol_Warning String AlertDescription
- | Error_Certificate String
- | Error_HandshakePolicy String
- | Error_EOF
- | Error_Packet String
- | Error_Packet_unexpected String String
- | Error_Packet_Parsing String
- | Error_TCP_Terminate
- data KxError
- = RSAError Error
- | KxUnsupported
- newtype AlertDescription where
- AlertDescription {
- fromAlertDescription :: Word8
- pattern AccessDenied :: AlertDescription
- pattern BadCertificate :: AlertDescription
- pattern BadCertificateHashValue :: AlertDescription
- pattern BadCertificateStatusResponse :: AlertDescription
- pattern BadRecordMac :: AlertDescription
- pattern CertificateExpired :: AlertDescription
- pattern CertificateRequired :: AlertDescription
- pattern CertificateRevoked :: AlertDescription
- pattern CertificateUnknown :: AlertDescription
- pattern CertificateUnobtainable :: AlertDescription
- pattern CloseNotify :: AlertDescription
- pattern DecodeError :: AlertDescription
- pattern DecompressionFailure :: AlertDescription
- pattern DecryptError :: AlertDescription
- pattern DecryptionFailed :: AlertDescription
- pattern ExportRestriction :: AlertDescription
- pattern HandshakeFailure :: AlertDescription
- pattern IllegalParameter :: AlertDescription
- pattern InappropriateFallback :: AlertDescription
- pattern InsufficientSecurity :: AlertDescription
- pattern InternalError :: AlertDescription
- pattern MissingExtension :: AlertDescription
- pattern NoApplicationProtocol :: AlertDescription
- pattern NoRenegotiation :: AlertDescription
- pattern ProtocolVersion :: AlertDescription
- pattern RecordOverflow :: AlertDescription
- pattern UnexpectedMessage :: AlertDescription
- pattern UnknownCa :: AlertDescription
- pattern UnknownPskIdentity :: AlertDescription
- pattern UnrecognizedName :: AlertDescription
- pattern UnsupportedCertificate :: AlertDescription
- pattern UnsupportedExtension :: AlertDescription
- pattern UserCanceled :: AlertDescription
- AlertDescription {
- data TLSException
- class CompressionC a where
- compressionCID :: a -> CompressionID
- compressionCDeflate :: a -> ByteString -> (a, ByteString)
- compressionCInflate :: a -> ByteString -> (a, ByteString)
- type CompressionID = Word8
- data PubKey
- = PubKeyRSA PublicKey
- | PubKeyDSA PublicKey
- | PubKeyDH (Integer, Integer, Integer, Maybe Integer, ([Word8], Integer))
- | PubKeyEC PubKeyEC
- | PubKeyX25519 PublicKey
- | PubKeyX448 PublicKey
- | PubKeyEd25519 PublicKey
- | PubKeyEd448 PublicKey
- | PubKeyMLDSA44 (VerificationKey MLDSA44)
- | PubKeyMLDSA65 (VerificationKey MLDSA65)
- | PubKeyMLDSA87 (VerificationKey MLDSA87)
- | PubKeyUnknown OID ByteString
- data PrivKey
- = PrivKeyRSA PrivateKey
- | PrivKeyDSA PrivateKey
- | PrivKeyEC PrivKeyEC
- | PrivKeyX25519 SecretKey
- | PrivKeyX448 SecretKey
- | PrivKeyEd25519 SecretKey
- | PrivKeyEd448 SecretKey
- | PrivKeyMLDSA44 (PrivKeyMLDSA MLDSA44)
- | PrivKeyMLDSA65 (PrivKeyMLDSA MLDSA65)
- | PrivKeyMLDSA87 (PrivKeyMLDSA MLDSA87)
- data ExtKeyUsagePurpose
- bulkInit :: Bulk -> BulkDirection -> BulkKey -> BulkState
- cipherAllowedForVersion :: Version -> Cipher -> Bool
- cipherKeyBlockSize :: Cipher -> Int
- elemCipher :: [CipherId] -> Cipher -> Bool
- findCipher :: CipherID -> [Cipher] -> Maybe Cipher
- hasMAC :: BulkFunctions -> Bool
- hasRecordIV :: BulkFunctions -> Bool
- intersectCiphers :: [CipherId] -> [Cipher] -> [Cipher]
- data BulkState
- data Hash
- data Bulk = Bulk {
- bulkName :: String
- bulkKeySize :: Int
- bulkIVSize :: Int
- bulkExplicitIV :: Int
- bulkAuthTagLen :: Int
- bulkBlockSize :: Int
- bulkF :: BulkFunctions
- type BulkAEAD = BulkNonce -> ByteString -> BulkAdditionalData -> (ByteString, AuthTag)
- type BulkAdditionalData = ByteString
- type BulkBlock = BulkIV -> ByteString -> (ByteString, BulkIV)
- data BulkDirection
- data BulkFunctions
- = BulkBlockF (BulkDirection -> BulkKey -> BulkBlock)
- | BulkStreamF (BulkDirection -> BulkKey -> BulkStream)
- | BulkAeadF (BulkDirection -> BulkKey -> BulkAEAD)
- type BulkIV = Nonce
- type BulkKey = Secret
- type BulkNonce = Nonce
- newtype BulkStream = BulkStream (ByteString -> (ByteString, BulkStream))
- data Cipher = Cipher {
- cipherID :: CipherID
- cipherName :: String
- cipherHash :: Hash
- cipherBulk :: Bulk
- cipherKeyExchange :: CipherKeyExchangeType
- cipherMinVer :: Maybe Version
- cipherPRFHash :: Maybe Hash
- type CipherID = Word16
- data CipherKeyExchangeType
- recvData' :: MonadIO m => Context -> m ByteString
- type Bytes = ByteString
- data ValidationChecks = ValidationChecks {
- checkTimeValidity :: Bool
- checkAtTime :: Maybe DateTime
- checkStrictOrdering :: Bool
- checkCAConstraints :: Bool
- checkExhaustive :: Bool
- checkLeafV3 :: Bool
- checkLeafKeyUsage :: [ExtKeyUsageFlag]
- checkLeafKeyPurpose :: [ExtKeyUsagePurpose]
- checkFQHN :: Bool
- data ValidationHooks = ValidationHooks {
- hookMatchSubjectIssuer :: DistinguishedName -> Certificate -> Bool
- hookValidateTime :: DateTime -> Certificate -> [FailedReason]
- hookValidateName :: HostName -> Certificate -> [FailedReason]
- hookFilterReason :: [FailedReason] -> [FailedReason]
- clientUseMaxFragmentLength :: ClientParams -> Maybe MaxFragmentEnum
Basic APIs
Arguments
| :: (MonadIO m, HasBackend backend, TLSParams params) | |
| => backend | Backend abstraction with specific method to interact with the connection type. |
| -> params | Parameters of the context. |
| -> m Context |
create a new context using the backend and parameters specified.
handshake :: MonadIO m => Context -> m () Source #
Handshake for a new TLS connection
This is to be called at the beginning of a connection, and during renegotiation.
Don't use this function as the acquire resource of bracket.
sendData :: MonadIO m => Context -> ByteString -> m () Source #
sendData sends a bunch of data. It will automatically chunk data to acceptable packet size
recvData :: MonadIO m => Context -> m ByteString Source #
Get data out of Data packet, and automatically renegotiate if a Handshake
ClientHello is received. An empty result means EOF. Use
closeNotifyReceived to tell an orderly closure from a truncation.
closeNotifyReceived :: MonadIO m => Context -> m Bool Source #
Whether the peer has sent close_notify. If recvData returns an
empty result and this is False, the transport was closed without
close_notify, so the data received may be truncated.
Since: 2.5.0
bye :: MonadIO m => Context -> m () Source #
Notify the context that this side wants to close connection. This is important that it is called before closing the handle, otherwise the session might not be resumable (for version < TLS1.2). This doesn't actually close the handle.
Proper usage is as follows:
ctx <- contextNew <backend> <params> handshake ctx ... bye
The following code ensures nothing but is no harm.
bracket (contextNew <backend> <params>) bye $ \ctx -> do handshake ctx ...
Exceptions
Since 1.8.0, this library only throws exceptions of type TLSException.
In the common case where the chosen backend is socket, IOException
may be thrown as well. This happens because the backend for sockets,
opaque to most modules in the tls library, throws those exceptions.
Backend abstraction
class HasBackend a where Source #
Instances
| HasBackend Handle Source # | |
Defined in Network.TLS.Backend | |
| HasBackend Socket Source # | |
Defined in Network.TLS.Backend | |
| HasBackend Backend Source # | |
Defined in Network.TLS.Backend | |
Connection IO backend
Constructors
| Backend | |
Fields
| |
Instances
| HasBackend Backend Source # | |
Defined in Network.TLS.Backend | |
Parameters
Minimal complete definition
getTLSCommonParams, getTLSRole, doHandshake, doHandshakeWith, doRequestCertificate, doRequestCertificateAsync, doPostHandshakeAuthWith
Instances
| TLSParams ClientParams Source # | |
Defined in Network.TLS.Context Methods getTLSCommonParams :: ClientParams -> CommonParams getTLSRole :: ClientParams -> Role doHandshake :: ClientParams -> Context -> IO () doHandshakeWith :: ClientParams -> Context -> HandshakeR -> IO () doRequestCertificate :: ClientParams -> Context -> IO Bool doRequestCertificateAsync :: ClientParams -> Context -> IO (Bool -> IO PHAResult) doPostHandshakeAuthWith :: ClientParams -> Context -> Handshake13R -> IO () | |
| TLSParams ServerParams Source # | |
Defined in Network.TLS.Context Methods getTLSCommonParams :: ServerParams -> CommonParams getTLSRole :: ServerParams -> Role doHandshake :: ServerParams -> Context -> IO () doHandshakeWith :: ServerParams -> Context -> HandshakeR -> IO () doRequestCertificate :: ServerParams -> Context -> IO Bool doRequestCertificateAsync :: ServerParams -> Context -> IO (Bool -> IO PHAResult) doPostHandshakeAuthWith :: ServerParams -> Context -> Handshake13R -> IO () | |
Client parameters
data ClientParams Source #
Instances
| Show ClientParams Source # | |
Defined in Network.TLS.Parameters Methods showsPrec :: Int -> ClientParams -> ShowS show :: ClientParams -> String showList :: [ClientParams] -> ShowS | |
| TLSParams ClientParams Source # | |
Defined in Network.TLS.Context Methods getTLSCommonParams :: ClientParams -> CommonParams getTLSRole :: ClientParams -> Role doHandshake :: ClientParams -> Context -> IO () doHandshakeWith :: ClientParams -> Context -> HandshakeR -> IO () doRequestCertificate :: ClientParams -> Context -> IO Bool doRequestCertificateAsync :: ClientParams -> Context -> IO (Bool -> IO PHAResult) doPostHandshakeAuthWith :: ClientParams -> Context -> Handshake13R -> IO () | |
defaultParamsClient :: HostName -> ByteString -> ClientParams Source #
Default value for ClientParams
clientServerIdentification :: ClientParams -> (HostName, ByteString) Source #
Define the name of the server, along with an extra service identification blob. this is important that the hostname part is properly filled for security reason, as it allow to properly associate the remote side with the given certificate during a handshake.
The extra blob is useful to differentiate services running on the same host, but that might have different certificates given. It's only used as part of the X509 validation infrastructure.
This value is typically set by defaultParamsClient.
clientUseServerNameIndication :: ClientParams -> Bool Source #
Allow the use of the Server Name Indication TLS extension during handshake, which allow the client to specify which host name, it's trying to access. This is useful to distinguish CNAME aliasing (e.g. web virtual host).
Default: True
clientWantSessionResume :: ClientParams -> Maybe (SessionID, SessionData) Source #
try to establish a connection using this session for TLS
1.2/TLS 1.3. This can be used for TLS 1.3 but for backward
compatibility purpose only. Use clientWantSessionResume13
instead for TLS 1.3.
Default: Nothing
clientWantSessionResumeList :: ClientParams -> [(SessionID, SessionData)] Source #
try to establish a connection using one of this sessions
especially for TLS 1.3. This take precedence over
clientWantSessionResume. For convenience, this can be
specified for TLS 1.2 but only the first entry is used.
Default: '[]'
clientWantTicket :: ClientParams -> Bool Source #
Whether to solicit TLS 1.2 session tickets (or TLS 1.3
resumption PSKs) from servers. With a False setting,
stateless clients that never do resumption can avoid
wasting server and client resources used to generate,
transmit and process tickets that will never be used.
Default: True
Since: 2.4.1
clientShared :: ClientParams -> Shared Source #
See the default value of Shared.
clientHooks :: ClientParams -> ClientHooks Source #
See the default value of ClientHooks.
clientSupported :: ClientParams -> Supported Source #
In this element, you'll need to override the default empty
value of of supportedCiphers with a suitable cipherlist.
See the default value of Supported.
clientDebug :: ClientParams -> DebugParams Source #
See the default value of DebugParams.
clientUseEarlyData :: ClientParams -> Bool Source #
Client tries to send early data in TLS 1.3 via sendData if
possible. If not accepted by the server, the early data is
automatically re-sent.
Default: False
clientUseECH :: ClientParams -> Bool Source #
Enabling Encrypted Client Hello.
If sharedECHConfigList is null, a greasing ECH extension is sent.
Otherwise, a valid ECH is sent.
If the server rejects ECH in Server Hello,
the client sends an alert after negotiation.
Default: False
Since: 2.1.9
Server parameters
data ServerParams Source #
Instances
| Default ServerParams Source # | |
Defined in Network.TLS.Parameters Methods def :: ServerParams | |
| Show ServerParams Source # | |
Defined in Network.TLS.Parameters Methods showsPrec :: Int -> ServerParams -> ShowS show :: ServerParams -> String showList :: [ServerParams] -> ShowS | |
| TLSParams ServerParams Source # | |
Defined in Network.TLS.Context Methods getTLSCommonParams :: ServerParams -> CommonParams getTLSRole :: ServerParams -> Role doHandshake :: ServerParams -> Context -> IO () doHandshakeWith :: ServerParams -> Context -> HandshakeR -> IO () doRequestCertificate :: ServerParams -> Context -> IO Bool doRequestCertificateAsync :: ServerParams -> Context -> IO (Bool -> IO PHAResult) doPostHandshakeAuthWith :: ServerParams -> Context -> Handshake13R -> IO () | |
serverWantClientCert :: ServerParams -> Bool Source #
Request a certificate from client.
Default: False
serverCACertificates :: ServerParams -> [SignedCertificate] Source #
This is a list of certificates from which the disinguished names are sent in certificate request messages. For TLS1.0, it should not be empty.
Default: '[]'
serverDHEParams :: ServerParams -> Maybe DHParams Source #
Server Optional Diffie Hellman parameters. Setting parameters is necessary for FFDHE key exchange when clients are not compatible with RFC 7919.
Value can be one of the standardized groups from module
Network.TLS.Extra.FFDHE or custom parameters generated with
generateParams.
Default: Nothing
serverHooks :: ServerParams -> ServerHooks Source #
See the default value of ServerHooks.
serverShared :: ServerParams -> Shared Source #
See the default value of Shared.
serverSupported :: ServerParams -> Supported Source #
See the default value of Supported.
serverDebug :: ServerParams -> DebugParams Source #
See the default value of DebugParams.
serverEarlyDataSize :: ServerParams -> Int Source #
Server accepts this size of early data in TLS 1.3. 0 (or lower) means that the server does not accept early data.
Early data can be replayed. The server is to accept 0-RTT for the
same handshake at most once (RFC 9846 Section 8), which is left to
sessionResumeOnlyOnce of the session manager: the in-memory one of
tls-session-manager does so, its session ticket one does not.
Default: 0
serverTicketLifetime :: ServerParams -> Int Source #
Lifetime in seconds for session tickets generated by the server. Acceptable value range is 0 to 604800 (7 days).
Default: 7200 (2 hours)
serverECHKey :: ServerParams -> [(ConfigId, ByteString)] Source #
ECH secret keys.
Default: '[]'
Since: 2.1.9
Shared
sharedCredentials :: Shared -> Credentials Source #
The list of certificates and private keys that a server will
use as part of authentication to clients. Actual credentials
that are used are selected dynamically from this list based on
client capabilities. Additional credentials returned by
onServerNameIndication are also considered.
When credential list is left empty (the default value), no key exchange can take place.
Default: mempty
sharedSessionManager :: Shared -> SessionManager Source #
Callbacks used by clients and servers in order to resume TLS sessions. The default implementation never resumes sessions. Package <https://hackage.haskell.org/package/tls-session-manager tls-session-manager> provides an in-memory implementation.
Default: noSessionManager
sharedCAStore :: Shared -> CertificateStore Source #
A collection of trust anchors to be used by a client as part
of validation of server certificates. This is set as first
argument to function onServerCertificate. Package
<https://hackage.haskell.org/package/crypton-x509-system
crypton-x509-system> gives access to a default certificate
store configured in the system.
Default: mempty
sharedValidationCache :: Shared -> ValidationCache Source #
Callbacks that may be used by a client to cache certificate validation results (positive or negative) and avoid expensive signature check. The default implementation does not have any caching.
See the default value of ValidationCache.
sharedHelloExtensions :: Shared -> [ExtensionRaw] Source #
Additional extensions to be sent during the Hello sequence.
For a client this is always included in message ClientHello. For a server, this is sent in messages ServerHello or EncryptedExtensions based on the TLS version.
Default: []
sharedECHConfigList :: Shared -> ECHConfigList Source #
ECH configuration.
Since: 2.1.9
sharedLimit :: Shared -> Limit Source #
Limitation parameters.
Since: 2.1.8
Client hooks
data ClientHooks Source #
A set of callbacks run by the clients for various corners of TLS establishment
Instances
| Default ClientHooks Source # | |
Defined in Network.TLS.Parameters Methods def :: ClientHooks | |
| Show ClientHooks Source # | |
Defined in Network.TLS.Parameters Methods showsPrec :: Int -> ClientHooks -> ShowS show :: ClientHooks -> String showList :: [ClientHooks] -> ShowS | |
type OnCertificateRequest = ([CertificateType], Maybe [SignatureScheme], [DistinguishedName]) -> IO (Maybe (CertificateChain, PrivKey)) Source #
Type for onCertificateRequest. This type synonym is to make
document readable.
onCertificateRequest :: ClientHooks -> OnCertificateRequest Source #
This action is called when the a certificate request is
received from the server. The callback argument is the
information from the request. The server, at its discretion,
may be willing to continue the handshake without a client
certificate. Therefore, the callback is free to return
Nothing to indicate that no client certificate should be
sent, despite the server's request. In some cases it may be
appropriate to get user consent before sending the certificate;
the content of the user's certificate may be sensitive and
intended only for specific servers.
The action should select a certificate chain of one of the
given certificate types and one of the certificates in the
chain should (if possible) be signed by one of the given
distinguished names. Some servers, that don't have a narrow
set of preferred issuer CAs, will send an empty
DistinguishedName list, rather than send all the names from
their trusted CA bundle. If the client does not have a
certificate chaining to a matching CA, it may choose a default
certificate instead.
Each certificate except the last should be signed by the following one. The returned private key must be for the first certificates in the chain. This key will be used to signing the certificate verify message.
The public key in the first certificate, and the matching
returned private key must be compatible with one of the list of
SignatureScheme value when provided. TLS 1.3
changes the meaning of the list elements, adding explicit code
points for each supported pair of hash and signature (public
key) algorithms, rather than combining separate codes for the
hash and key. For details see
RFC 8446
section 4.2.3. When no compatible certificate chain is
available, return Nothing if it is OK to continue without a
client certificate. Returning a non-matching certificate
should result in a handshake failure.
While the TLS version is not provided to the callback, the
content of the signature_algorithms list provides a strong
hint, since TLS 1.3 servers will generally list the RSASSA-PSS
schemes, whose first octet is 0x08.
Note that is is the responsibility of this action to select a certificate matching one of the requested certificate types (public key algorithms). Returning a non-matching one will lead to handshake failure later.
sharedCredentials is for servers: a client sends the certificate
this action returns, for example one loaded from files. The CA of
the server belongs in sharedCAStore.
cred <- either error id <$> credentialLoadX509 "client.crt" "client.key"
let hooks = defaultClientHooks{onCertificateRequest = \_ -> return (Just cred)}Default: returns Nothing anyway.
type OnServerCertificate = CertificateStore -> ValidationCache -> ServiceID -> CertificateChain -> IO [FailedReason] Source #
Type for onServerCertificate. This type synonym is to make
document readable.
onServerCertificate :: ClientHooks -> OnServerCertificate Source #
Used by the client to validate the server certificate. The
default implementation calls validateDefault which validates
according to the default hooks and checks provided by
Data.X509.Validation. This can be replaced with a custom
validation function using different settings.
The function is not expected to verify the key-usage or extended-key-usage extensions of the end-entity certificate. Key usage depends on the dynamically-selected cipher and this part should not be cached. Both checks are performed by the library internally after this function accepts the chain.
Default: validateDefault
onSuggestALPN :: ClientHooks -> IO (Maybe [ByteString]) Source #
This action is called when the client sends ClientHello to determine ALPN values such as '["h2", "http/1.1"]'.
Default: returns Nothing
onCustomFFDHEGroup :: ClientHooks -> DHParams -> DHPublic -> IO GroupUsage Source #
This action is called to validate DHE parameters when the
server selected a finite-field group not part of the
"Supported Groups Registry" or not part of supportedGroups
list.
With TLS 1.3 custom groups have been removed from the protocol, so this callback is only used when the version negotiated is 1.2 or below.
The default behavior with (dh_p, dh_g, dh_size) and pub as follows:
- rejecting if dh_p is even
- rejecting unless 1 < dh_g && dh_g < dh_p - 1
- rejecting unless 1 < dh_p && pub < dh_p - 1
- rejecting if dh_size < 1024 (to prevent Logjam attack)
See RFC 7919 section 3.1 for recommendations.
onServerFinished :: ClientHooks -> Information -> IO () Source #
When a handshake is done, this hook can check Information.
onSelectKeyShareGroups :: ClientHooks -> [Group] -> [Group] Source #
A function to select groups in "key_share" by TLS 1.3 client.
Client's supportedGroups is passed as the 1st argument.
The result is put in the order of supportedGroups, and
groups not in it are dropped (RFC 9846 Section 4.3.8).
The default function specifies a pair of hybrid (classical +
post quantum) group and classical group to transit from
classical key exchange to hybrid key exchange. With the
default value of supportedGroups, X25519MLKEM and X25519
are chosen.
Middleboxes may drop a ClientHello that contains large
X2219MLKEM. In such environment, take 1, which selects
X22519 only with the default value, is maybe a good
candidate.
In the case where X22519 is only contained in "key_share", a wise-server without nasty middleboxes may ask the client to send X2219MLKEM via HelloRetryRequest as X2219MLKEM is specified in "supported_groups".
Since: 2.2.3
Server hooks
data ServerHooks Source #
A set of callbacks run by the server for various corners of the TLS establishment
Instances
| Default ServerHooks Source # | |
Defined in Network.TLS.Parameters Methods def :: ServerHooks | |
| Show ServerHooks Source # | |
Defined in Network.TLS.Parameters Methods showsPrec :: Int -> ServerHooks -> ShowS show :: ServerHooks -> String showList :: [ServerHooks] -> ShowS | |
defaultServerHooks :: ServerHooks Source #
Default value for ServerHooks
onClientCertificate :: ServerHooks -> CertificateChain -> IO CertificateUsage Source #
This action is called when a client certificate chain is received from the client. When it returns a CertificateUsageReject value, the handshake is aborted.
The function is not expected to verify the key-usage extension of the certificate. This verification is performed by the library internally.
Default: returns the following:
CertificateUsageReject (CertificateRejectOther "no client certificates expected")
validateClientCertificate :: CertificateStore -> ValidationCache -> CertificateChain -> IO CertificateUsage Source #
A utility function for client authentication which can be used
onClientCertificate.
Since: 2.1.7
onUnverifiedClientCert :: ServerHooks -> IO Bool Source #
This action is called when the client certificate cannot be
verified. Return True to accept the certificate anyway, or
False to fail verification.
Default: returns False
onCipherChoosing :: ServerHooks -> Version -> [Cipher] -> Cipher Source #
Allow the server to choose the cipher relative to the the client version and the client list of ciphers.
This could be useful with old clients and as a workaround to the BEAST (where RC4 is sometimes preferred with TLS < 1.1)
The client cipher list cannot be empty.
Default: taking the head of ciphers.
onServerNameIndication :: ServerHooks -> Maybe HostName -> IO Credentials Source #
Allow the server to indicate additional credentials to be used depending on the host name indicated by the client.
This is most useful for transparent proxies where credentials must be generated on the fly according to the host the client is trying to connect to.
Returned credentials may be ignored if a client does not support the signature algorithms used in the certificate chain.
Default: returns mempty
onNewHandshake :: ServerHooks -> Measurement -> IO Bool Source #
At each new handshake, we call this hook to see if we allow handshake to happens.
Default: returns True
onALPNClientSuggest :: ServerHooks -> Maybe ([ByteString] -> IO ByteString) Source #
Allow the server to choose an application layer protocol
suggested from the client through the ALPN (Application Layer
Protocol Negotiation) extensions. If the server supports no
protocols that the client advertises an empty ByteString
should be returned.
Default: Nothing
onEncryptedExtensionsCreating :: ServerHooks -> [ExtensionRaw] -> IO [ExtensionRaw] Source #
Allow to modify extensions to be sent in EncryptedExtensions of TLS 1.3.
Default: return
onSelectKeyShare :: ServerHooks -> [[Group]] -> [Group] -> [Group] -> IO (Maybe Group, Bool) Source #
A function to select one key share by TLS 1.3 server.
The 1st argument is server's supportedGroupsTLS13.
The 2nd arguments is client's groups in "supported_groups"
The 3rd arguments is client's groups in "key_share".
True in the result indicates sending a hello retry request
with this group.
The default function targets [Group] in the first argument in
order. If there is a common group among the "key_share"
groups, it will use that group for key exchange.
Alternatively, if there is a common group among the
"supported_groups" groups, it will instruct to send the
HelloRetryRequest using that group. Otherwise, it will check
the next [Group].
Since: 2.2.3
onAccept0RTT :: ServerHooks -> SessionData -> IO Bool Source #
Whether to accept 0-RTT with the session being resumed, once
everything else allows it. False refuses the early data but not
the resumption. QUIC refuses 0-RTT when the transport parameters
it remembered do not hold any more (RFC 9000 Sec 7.4.1), and can
keep them in sessionAppData.
Default: _ -> return True
Since: 2.5.1
data Measurement Source #
record some data about this connection.
Instances
| Eq Measurement Source # | |
Defined in Network.TLS.Measurement | |
| Show Measurement Source # | |
Defined in Network.TLS.Measurement Methods showsPrec :: Int -> Measurement -> ShowS show :: Measurement -> String showList :: [Measurement] -> ShowS | |
nbHandshakes :: Measurement -> Word32 Source #
number of handshakes on this context
bytesReceived :: Measurement -> Word32 Source #
bytes received since last handshake
bytesSent :: Measurement -> Word32 Source #
bytes sent since last handshake
Supported
List all the supported algorithms, versions, ciphers, etc supported.
supportedVersions :: Supported -> [Version] Source #
Supported versions by this context. On the client side, the highest version will be used to establish the connection. On the server side, the highest version that is less or equal than the client version will be chosen.
Versions should be listed in preferred order, i.e. higher versions first.
Default: [TLS13,TLS12]
supportedCiphers :: Supported -> [Cipher] Source #
Supported cipher methods. The default is empty, specify a
suitable cipher list.
ciphersuite_default is often a good
choice.
Default: []
supportedMinRSAKeySize :: Supported -> Int Source #
The least size in bits of the RSA key in the peer's leaf certificate. A shorter one is refused with bad_certificate; 0 lets any size through.
Default: 2048
supportedMaxRSAKeySize :: Supported -> Int Source #
The largest size in bits of the RSA key in the peer's leaf certificate. Verifying with a larger key costs more CPU, which the peer chooses. A longer one is refused with bad_certificate; 0 lets any size through.
Default: 8192
supportedClientCertificatePurposes :: Supported -> [ExtKeyUsagePurpose] Source #
Server only. A client's leaf certificate with Extended Key Usage
is refused with bad_certificate unless it allows one of these.
Adding KeyUsagePurpose_ServerAuth accepts a server certificate.
Default: [KeyUsagePurpose_ClientAuth]
Since: 2.5.0
supportedMinDHKeySize :: Supported -> Int Source #
The least size in bits of the prime of the DH parameters a TLS 1.2
server sends. A smaller one is refused with insufficient_security
before onCustomFFDHEGroup is called; 0 lets any size through.
Default: 2048, the size of the smallest group of RFC 7919
supportedMaxDHKeySize :: Supported -> Int Source #
The largest size in bits of the prime of the DH parameters a TLS
1.2 server sends. Computing with a larger prime costs more CPU,
which the server chooses. A larger one is refused with
handshake_failure before onCustomFFDHEGroup is called; 0 lets any
size through.
Default: 8192, the size of the largest group of RFC 7919
supportedClientCipherOrder :: Supported -> Bool Source #
Whether a server chooses among the ciphers in common in the
client's order of preference, rather than in the order of
supportedCiphers. A client without AES acceleration can then get
ChaCha20-Poly1305 from a server that has it.
Default: False
supportedCompressions :: Supported -> [Compression] Source #
Supported compressions methods. By default only the "null" compression is supported, which means no compression will be performed. Allowing other compression method is not advised as it causes a connection failure when TLS 1.3 is negotiated.
Default: [nullCompression]
supportedHashSignatures :: Supported -> [SignatureScheme] Source #
All supported hash/signature algorithms pair for client certificate verification and server signature in (EC)DHE, ordered by decreasing priority.
This list is sent to the peer as part of the
"signature_algorithms" extension. It is used to restrict
accepted signatures received from the peer at TLS level (not in
X.509 certificates), but only when the TLS version is 1.2 or
above. In order to disable SHA-1 one must then also disable
earlier protocol versions in supportedVersions.
The list also impacts the selection of possible algorithms when generating signatures.
Note: with TLS 1.3 some algorithms have been deprecated and will not be used even when listed in the parameter: MD5, SHA-1, SHA-224, RSA PKCS#1, DSA.
Default: supportedSignatureSchemes
supportedSecureRenegotiation :: Supported -> Bool Source #
Secure renegotiation defined in RFC5746. If True, clients
send the renegotiation_info extension. If True, servers
handle the extension or the renegotiation SCSV then send the
renegotiation_info extension.
Default: True
supportedClientInitiatedRenegotiation :: Supported -> Bool Source #
If True, renegotiation is allowed from the client side.
This is vulnerable to DOS attacks. If False, renegotiation
is allowed only from the server side via HelloRequest.
Default: False
supportedExtendedMainSecret :: Supported -> EMSMode Source #
The mode regarding extended main secret. Enabling this extension provides better security for TLS versions 1.2. TLS 1.3 provides the security properties natively and does not need the extension.
By default the extension is RequireEMS. So, the handshake
will fail when the peer does not support the extension.
Default: RequireEMS
supportedSession :: Supported -> Bool Source #
Set if we support session.
Default: True
supportedFallbackScsv :: Supported -> Bool Source #
Support for fallback SCSV defined in RFC7507. If True,
servers reject handshakes which suggest a lower protocol than
the highest protocol supported.
Default: True
supportedEmptyPacket :: Supported -> Bool Source #
In ver <= TLS1.0, block ciphers using CBC are using CBC
residue as IV, which can be guessed by an attacker. Hence, an
empty packet is normally sent before a normal data packet, to
prevent guessability. Some Microsoft TLS-based protocol
implementations, however, consider these empty packets as a
protocol violation and disconnect. If this parameter is
False, empty packets will never be added, which is less
secure, but might help in rare cases.
Default: True
supportedGroups :: Supported -> [Group] Source #
A list of supported elliptic curves and finite-field groups in preferred order.
- TLS 1.3 client: this list is used as the 1st argument to
onSelectKeyShareGroupsto select groups in "key_share". This list is also used as values of "supported_groups". - TLS 1.3 server: this list is not used.
- TLS 1.2 client: this list is also used as values of "supported_groups".
- TLS 1.2 server: this list is used to select a key exchange mechanism.
The list is sent to the server as part of the "supported_groups" extension. It is used in both clients and servers to restrict accepted groups in DH key exchange. Up until TLS v1.2, it is also used by a client to restrict accepted elliptic curves in ECDSA signatures.
The default value includes all groups with security strength of 128 bits or more.
Default: [X25519MLKEM768,P256MLKEM768,P384MLKEM1024,X25519,P256,P384,X448,P521,FFDHE3072,FFDHE4096,FFDHE6144,FFDHE8192,MLKEM768,MLKEM1024]
supportedGroupsTLS13 :: Supported -> [[Group]] Source #
The inside [Group] is the list of Group at the same level
in preferred order. The inside [Group]s are also listed in
preferred order.
TLS 1.3 server: this is used as the 1st argument to
onSelectKeyShare.
Default: [[X25519MLKEM768,P256MLKEM768,P384MLKEM1024],[X25519,P256],[P384,X448,P521],[FFDHE2048,FFDHE3072,FFDHE4096,FFDHE6144,FFDHE8192],[MLKEM768,MLKEM1024]]
Since: 2.2.3
Debug parameters
data DebugParams Source #
All settings should not be used in production
Instances
| Default DebugParams Source # | |
Defined in Network.TLS.Parameters Methods def :: DebugParams | |
| Show DebugParams Source # | |
Defined in Network.TLS.Parameters Methods showsPrec :: Int -> DebugParams -> ShowS show :: DebugParams -> String showList :: [DebugParams] -> ShowS | |
defaultDebugParams :: DebugParams Source #
Default value for DebugParams
debugSeed :: DebugParams -> Maybe Seed Source #
Disable the true randomness in favor of deterministic seed that will produce a deterministic random from. This is useful for tests and debugging purpose. Do not use in production
Default: Nothing
debugPrintSeed :: DebugParams -> Seed -> IO () Source #
Add a way to print the seed that was randomly generated. reusing the same seed
will reproduce the same randomness with debugSeed
Default: no printing
debugVersionForced :: DebugParams -> Maybe Version Source #
Force to choose this version in the server side.
Default: Nothing
debugKeyLogger :: DebugParams -> String -> IO () Source #
Printing main keys.
Default: no printing
defaultKeyLogger :: String -> IO () Source #
Key logger with the SSLKEYLOGFILE environment variable.
debugError :: DebugParams -> String -> IO () Source #
debugTraceKey :: DebugParams -> String -> IO () Source #
Limit parameters
Limitations for security.
Since: 2.1.7
defaultLimit :: Limit Source #
Default value for Limit.
limitHandshakeFragment :: Limit -> Int Source #
The number of records that may carry a handshake message before the one that completes it. A peer may split a message into records as small as one byte, and each is held until the message is complete.
Default: 2048
limitKeyUpdate :: Limit -> Maybe Int Source #
Maximum number of consecutive TLS 1.3 KeyUpdate messages accepted
without intervening non-empty application data. This bounds the CPU
work and response amplification a peer can trigger while application
code is blocked inside recvData. Nothing and non-positive values
disable the limit; they do not disable KeyUpdate processing.
Default: Just 32
limitRecordSize :: Limit -> Maybe Int Source #
Record size limit defined in RFC 8449.
If Nothing, the "record_size_limit" extension is not used.
In the case of Just: A client sends the "record_size_limit"
extension with this value to the server. A server sends back
this extension with its own value if a client sends the
extension. When negotiated, both my limit and peer's limit are
enabled for protected communication.
Default: Nothing
limitRecordsPerKey :: Limit -> Maybe Word64 Source #
The number of TLS 1.3 records sent under a set of keys, after which
they are updated with KeyUpdate (RFC 9846 Section 5.5). Early data,
which cannot update its keys, is refused there. Nothing means the
limit for the cipher: 2^24 for AES and 2^62 for ChaCha20-Poly1305.
Default: Nothing
Since: 2.5.0
Shared parameters
Credentials
newtype Credentials Source #
Constructors
| Credentials [Credential] |
Instances
| Monoid Credentials Source # | |
Defined in Network.TLS.Credentials | |
| Semigroup Credentials Source # | |
Defined in Network.TLS.Credentials Methods (<>) :: Credentials -> Credentials -> Credentials sconcat :: NonEmpty Credentials -> Credentials stimes :: Integral b => b -> Credentials -> Credentials | |
| Show Credentials Source # | |
Defined in Network.TLS.Credentials Methods showsPrec :: Int -> Credentials -> ShowS show :: Credentials -> String showList :: [Credentials] -> ShowS | |
type Credential = (CertificateChain, PrivKey) Source #
Arguments
| :: FilePath | public certificate (X.509 format) |
| -> FilePath | private key associated |
| -> IO (Either String Credential) |
try to create a new credential object from a public certificate and the associated private key that are stored on the filesystem in PEM format.
credentialLoadX509FromMemory :: ByteString -> ByteString -> Either String Credential Source #
similar to credentialLoadX509 but take the certificate
and private key from memory instead of from the filesystem.
credentialLoadX509Chain Source #
Arguments
| :: FilePath | public certificate (X.509 format) |
| -> [FilePath] | chain certificates (X.509 format) |
| -> FilePath | private key associated |
| -> IO (Either String Credential) |
similar to credentialLoadX509 but also allow specifying chain
certificates.
credentialLoadX509ChainFromMemory :: ByteString -> [ByteString] -> ByteString -> Either String Credential Source #
similar to credentialLoadX509FromMemory but also allow
specifying chain certificates.
Session manager
data SessionManager Source #
A session manager.
In the server side, all fields are used.
In the client side, only sessionEstablish is used.
noSessionManager :: SessionManager Source #
The session manager to do nothing.
sessionResume :: SessionManager -> SessionIDorTicket -> IO (Maybe SessionData) Source #
Used on TLS 1.2/1.3 servers to lookup SessionData with SessionID or to decrypt Ticket to get SessionData.
sessionResumeOnlyOnce :: SessionManager -> SessionIDorTicket -> IO (Maybe SessionData) Source #
Used for 0RTT on TLS 1.3 servers to lookup SessionData with SessionID or to decrypt Ticket to get SessionData.
It is to return the SessionData at most once for an identity, or early data can be replayed (RFC 9846 Section 8); a manager that keeps no state, as with tickets, cannot.
sessionEstablish :: SessionManager -> SessionIDorTicket -> SessionData -> IO (Maybe Ticket) Source #
Used on TLS 1.2/1.3 servers to store SessionData with SessionID or to encrypt SessionData to get Ticket ignoring SessionID. Used on TLS 1.2/1.3 clients to store SessionData with SessionIDorTicket and then return Nothing. For clients, only this field should be set with noSessionManager.
sessionInvalidate :: SessionManager -> SessionIDorTicket -> IO () Source #
Used TLS 1.2 servers to delete SessionData with SessionID on errors.
sessionUseTicket :: SessionManager -> Bool Source #
type SessionIDorTicket = ByteString Source #
Identity
type Ticket = ByteString Source #
Encrypted session ticket (encrypt(encode SessionData)).
Session data
data SessionData Source #
Session data to resume
Instances
| DebugShow SessionData Source # | |||||
Defined in Network.TLS.Types.Session Methods debugShow :: SessionData -> String | |||||
| Eq SessionData Source # | |||||
Defined in Network.TLS.Types.Session | |||||
| Generic SessionData Source # | |||||
Defined in Network.TLS.Types.Session Associated Types
| |||||
| Show SessionData Source # | Everything but | ||||
Defined in Network.TLS.Types.Session Methods showsPrec :: Int -> SessionData -> ShowS show :: SessionData -> String showList :: [SessionData] -> ShowS | |||||
| Serialise SessionData Source # | |||||
Defined in Network.TLS.Types.Session Methods encode :: SessionData -> Encoding decode :: Decoder s SessionData encodeList :: [SessionData] -> Encoding decodeList :: Decoder s [SessionData] | |||||
| type Rep SessionData Source # | |||||
Defined in Network.TLS.Types.Session type Rep SessionData = D1 ('MetaData "SessionData" "Network.TLS.Types.Session" "tls-2.5.3-6PbT8OLNCQHJtBhAX9JoBW" 'False) (C1 ('MetaCons "SessionData" 'PrefixI 'True) (((S1 ('MetaSel ('Just "sessionVersion") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Version) :*: (S1 ('MetaSel ('Just "sessionCipher") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 CipherID) :*: S1 ('MetaSel ('Just "sessionCompression") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 CompressionID))) :*: (S1 ('MetaSel ('Just "sessionClientSNI") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Maybe HostName)) :*: (S1 ('MetaSel ('Just "sessionSecret") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 ByteString) :*: S1 ('MetaSel ('Just "sessionGroup") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Maybe Group))))) :*: ((S1 ('MetaSel ('Just "sessionTicketInfo") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Maybe TLS13TicketInfo)) :*: (S1 ('MetaSel ('Just "sessionALPN") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Maybe ByteString)) :*: S1 ('MetaSel ('Just "sessionMaxEarlyDataSize") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int))) :*: (S1 ('MetaSel ('Just "sessionFlags") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 [SessionFlag]) :*: (S1 ('MetaSel ('Just "sessionClientCertificate") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Maybe ByteString)) :*: S1 ('MetaSel ('Just "sessionAppData") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Maybe ByteString))))))) | |||||
defaultSessionData :: SessionData Source #
A SessionData to build one from with record update syntax, so that a
field added later does not break the code that builds it.
sessionVersion :: SessionData -> Version Source #
sessionCipher :: SessionData -> CipherID Source #
sessionClientSNI :: SessionData -> Maybe HostName Source #
sessionSecret :: SessionData -> ByteString Source #
sessionGroup :: SessionData -> Maybe Group Source #
sessionTicketInfo :: SessionData -> Maybe TLS13TicketInfo Source #
sessionALPN :: SessionData -> Maybe ByteString Source #
sessionMaxEarlyDataSize :: SessionData -> Int Source #
sessionFlags :: SessionData -> [SessionFlag] Source #
sessionClientCertificate :: SessionData -> Maybe ByteString Source #
On a server, the DER of the leaf certificate the client was authenticated with, so that a resumed connection can tell the client.
sessionAppData :: SessionData -> Maybe ByteString Source #
Data of the application's own, kept with the session and given
back on resumption; never set by this library. A server can put
what 0-RTT depends on here and check it in onAccept0RTT.
Since: 2.5.1
data SessionFlag Source #
Some session flags
Constructors
| SessionEMS | Session created with Extended Main Secret |
Instances
| Eq SessionFlag Source # | |||||
Defined in Network.TLS.Types.Session | |||||
| Enum SessionFlag Source # | |||||
Defined in Network.TLS.Types.Session Methods succ :: SessionFlag -> SessionFlag pred :: SessionFlag -> SessionFlag toEnum :: Int -> SessionFlag fromEnum :: SessionFlag -> Int enumFrom :: SessionFlag -> [SessionFlag] enumFromThen :: SessionFlag -> SessionFlag -> [SessionFlag] enumFromTo :: SessionFlag -> SessionFlag -> [SessionFlag] enumFromThenTo :: SessionFlag -> SessionFlag -> SessionFlag -> [SessionFlag] | |||||
| Generic SessionFlag Source # | |||||
Defined in Network.TLS.Types.Session Associated Types
| |||||
| Show SessionFlag Source # | |||||
Defined in Network.TLS.Types.Session Methods showsPrec :: Int -> SessionFlag -> ShowS show :: SessionFlag -> String showList :: [SessionFlag] -> ShowS | |||||
| Serialise SessionFlag Source # | |||||
Defined in Network.TLS.Types.Session Methods encode :: SessionFlag -> Encoding decode :: Decoder s SessionFlag encodeList :: [SessionFlag] -> Encoding decodeList :: Decoder s [SessionFlag] | |||||
| type Rep SessionFlag Source # | |||||
Defined in Network.TLS.Types.Session type Rep SessionFlag = D1 ('MetaData "SessionFlag" "Network.TLS.Types.Session" "tls-2.5.3-6PbT8OLNCQHJtBhAX9JoBW" 'False) (C1 ('MetaCons "SessionEMS" 'PrefixI 'False) (U1 :: Type -> Type)) | |||||
data TLS13TicketInfo Source #
Instances
| Eq TLS13TicketInfo Source # | |||||
Defined in Network.TLS.Types.Session Methods (==) :: TLS13TicketInfo -> TLS13TicketInfo -> Bool (/=) :: TLS13TicketInfo -> TLS13TicketInfo -> Bool | |||||
| Generic TLS13TicketInfo Source # | |||||
Defined in Network.TLS.Types.Session Associated Types
Methods from :: TLS13TicketInfo -> Rep TLS13TicketInfo x to :: Rep TLS13TicketInfo x -> TLS13TicketInfo | |||||
| Show TLS13TicketInfo Source # | |||||
Defined in Network.TLS.Types.Session Methods showsPrec :: Int -> TLS13TicketInfo -> ShowS show :: TLS13TicketInfo -> String showList :: [TLS13TicketInfo] -> ShowS | |||||
| Serialise TLS13TicketInfo Source # | |||||
Defined in Network.TLS.Types.Session Methods encode :: TLS13TicketInfo -> Encoding decode :: Decoder s TLS13TicketInfo encodeList :: [TLS13TicketInfo] -> Encoding decodeList :: Decoder s [TLS13TicketInfo] | |||||
| type Rep TLS13TicketInfo Source # | |||||
Defined in Network.TLS.Types.Session type Rep TLS13TicketInfo | |||||
is0RTTPossible :: SessionData -> Bool Source #
Validation Cache
data ValidationCache #
Constructors
| ValidationCache | |
Instances
| Default ValidationCache # | |
Defined in Data.X509.Validation.Cache Methods | |
type ValidationCacheQueryCallback = ServiceID -> Fingerprint -> Certificate -> IO ValidationCacheResult #
type ValidationCacheAddCallback = ServiceID -> Fingerprint -> Certificate -> IO () #
data ValidationCacheResult #
Constructors
| ValidationCachePass | |
| ValidationCacheDenied String | |
| ValidationCacheUnknown |
Instances
| Eq ValidationCacheResult # | |
Defined in Data.X509.Validation.Cache Methods (==) :: ValidationCacheResult -> ValidationCacheResult -> Bool (/=) :: ValidationCacheResult -> ValidationCacheResult -> Bool | |
| Show ValidationCacheResult # | |
Defined in Data.X509.Validation.Cache Methods showsPrec :: Int -> ValidationCacheResult -> ShowS show :: ValidationCacheResult -> String showList :: [ValidationCacheResult] -> ShowS | |
exceptionValidationCache :: [(ServiceID, Fingerprint)] -> ValidationCache #
Types
For Supported
Versions known to TLS
Constructors
| Version Word16 |
Bundled Patterns
| pattern SSL2 :: Version | |
| pattern SSL3 :: Version | |
| pattern TLS10 :: Version | |
| pattern TLS11 :: Version | |
| pattern TLS12 :: Version | |
| pattern TLS13 :: Version |
Instances
| Eq Version Source # | |||||
| Ord Version Source # | |||||
| Generic Version Source # | |||||
Defined in Network.TLS.Types.Version Associated Types
| |||||
| Show Version Source # | |||||
| Serialise Version Source # | |||||
Defined in Network.TLS.Types.Version | |||||
| type Rep Version Source # | |||||
Defined in Network.TLS.Types.Version type Rep Version = D1 ('MetaData "Version" "Network.TLS.Types.Version" "tls-2.5.3-6PbT8OLNCQHJtBhAX9JoBW" 'True) (C1 ('MetaCons "Version" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word16))) | |||||
data Compression Source #
every compression need to be wrapped in this, to fit in structure
Constructors
| CompressionC a => Compression a |
Instances
| Eq Compression Source # | |
Defined in Network.TLS.Compression | |
| Show Compression Source # | |
Defined in Network.TLS.Compression Methods showsPrec :: Int -> Compression -> ShowS show :: Compression -> String showList :: [Compression] -> ShowS | |
nullCompression :: Compression Source #
default null compression
newtype SignatureScheme Source #
A signature scheme: the 16-bit number that travels on the wire, with a name for each one this library knows.
A scheme is one number, not a hash and a signature algorithm. TLS 1.2
read the two bytes separately and some of the values still line up that
way, but from TLS 1.3 the number is indivisible, and for ML-DSA neither
byte means what it does elsewhere -- 0x09 is no hash, and the second byte
repeats numbers RSASSA-PSS uses, so mldsa87 read byte by byte looks
like rsa_pss_rsae_sha512. Code that took the halves apart got that
wrong, which is why the halves are gone.
The names are pattern synonyms with no COMPLETE pragma, so a case
over them needs a catch-all and a scheme named in a later release breaks
nothing that compiled against this one. Show is written out for the
same reason: a program built against an older hs-tls still says something
useful about a scheme a newer one produced.
Constructors
| SignatureScheme | |
Fields
| |
Bundled Patterns
Instances
| Eq SignatureScheme Source # | |
Defined in Network.TLS.SignatureScheme Methods (==) :: SignatureScheme -> SignatureScheme -> Bool (/=) :: SignatureScheme -> SignatureScheme -> Bool | |
| Ord SignatureScheme Source # | |
Defined in Network.TLS.SignatureScheme Methods compare :: SignatureScheme -> SignatureScheme -> Ordering (<) :: SignatureScheme -> SignatureScheme -> Bool (<=) :: SignatureScheme -> SignatureScheme -> Bool (>) :: SignatureScheme -> SignatureScheme -> Bool (>=) :: SignatureScheme -> SignatureScheme -> Bool max :: SignatureScheme -> SignatureScheme -> SignatureScheme min :: SignatureScheme -> SignatureScheme -> SignatureScheme | |
| Show SignatureScheme Source # | The IANA name, and the number for a scheme this release does not know. |
Defined in Network.TLS.SignatureScheme Methods showsPrec :: Int -> SignatureScheme -> ShowS show :: SignatureScheme -> String showList :: [SignatureScheme] -> ShowS | |
type HashAndSignatureAlgorithm = SignatureScheme Source #
Deprecated: Use SignatureScheme
What a signature scheme used to be called, when it was a pair.
Kept so that code which only names the type goes on compiling. Code that took the pair apart cannot be helped by a synonym and has to say which scheme it meant.
supportedSignatureSchemes :: [SignatureScheme] Source #
What this library offers, best first.
signatureSchemesForTLS13 :: [SignatureScheme] Source #
The subset of supportedSignatureSchemes that TLS 1.3 allows in
CertificateVerify. RFC 8446 section 4.2.3 defines the
RSASSA-PKCS1-v1_5 schemes, and the two SHA-1 ones, for signatures in
certificates only.
Constructors
| Group Word16 |
Bundled Patterns
| pattern FFDHE2048 :: Group | |
| pattern FFDHE3072 :: Group | |
| pattern FFDHE4096 :: Group | |
| pattern FFDHE6144 :: Group | |
| pattern FFDHE8192 :: Group | |
| pattern MLKEM1024 :: Group | |
| pattern MLKEM512 :: Group | |
| pattern MLKEM768 :: Group | |
| pattern P256 :: Group | |
| pattern P256MLKEM768 :: Group | |
| pattern P384 :: Group | |
| pattern P384MLKEM1024 :: Group | |
| pattern P521 :: Group | |
| pattern X25519 :: Group | |
| pattern X25519MLKEM768 :: Group | |
| pattern X448 :: Group |
Instances
| Eq Group Source # | |||||
| Generic Group Source # | |||||
Defined in Network.TLS.Crypto.Types Associated Types
| |||||
| Show Group Source # | |||||
| Serialise Group Source # | |||||
Defined in Network.TLS.Crypto.Types | |||||
| type Rep Group Source # | |||||
Defined in Network.TLS.Crypto.Types type Rep Group = D1 ('MetaData "Group" "Network.TLS.Crypto.Types" "tls-2.5.3-6PbT8OLNCQHJtBhAX9JoBW" 'True) (C1 ('MetaCons "Group" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word16))) | |||||
supportedNamedGroups :: [Group] Source #
A list for named groups. The ordering is for client preference because server preference is not used in our server implementation.
Client or server policy regarding Extended Main Secret
Constructors
| NoEMS | Extended Main Secret is not used |
| AllowEMS | Extended Main Secret is allowed |
| RequireEMS | Extended Main Secret is required |
For parameters and hooks
data GroupUsage Source #
Group usage callback possible return values.
Constructors
| GroupUsageValid | usage of group accepted |
| GroupUsageInsecure | usage of group provides insufficient security |
| GroupUsageUnsupported String | usage of group rejected for other reason (specified as string) |
| GroupUsageInvalidPublic | usage of group with an invalid public value |
Instances
| Eq GroupUsage Source # | |
Defined in Network.TLS.Parameters | |
| Show GroupUsage Source # | |
Defined in Network.TLS.Parameters Methods showsPrec :: Int -> GroupUsage -> ShowS show :: GroupUsage -> String showList :: [GroupUsage] -> ShowS | |
data CertificateUsage Source #
Certificate Usage callback possible returns values.
Constructors
| CertificateUsageAccept | usage of certificate accepted |
| CertificateUsageReject CertificateRejectReason | usage of certificate rejected |
Instances
| Eq CertificateUsage Source # | |
Defined in Network.TLS.X509 Methods (==) :: CertificateUsage -> CertificateUsage -> Bool (/=) :: CertificateUsage -> CertificateUsage -> Bool | |
| Show CertificateUsage Source # | |
Defined in Network.TLS.X509 Methods showsPrec :: Int -> CertificateUsage -> ShowS show :: CertificateUsage -> String showList :: [CertificateUsage] -> ShowS | |
data CertificateRejectReason Source #
Certificate and Chain rejection reason
Constructors
| CertificateRejectExpired | |
| CertificateRejectRevoked | |
| CertificateRejectUnknownCA | |
| CertificateRejectAbsent | |
| CertificateRejectOther String |
Instances
| Eq CertificateRejectReason Source # | |
Defined in Network.TLS.X509 Methods (==) :: CertificateRejectReason -> CertificateRejectReason -> Bool (/=) :: CertificateRejectReason -> CertificateRejectReason -> Bool | |
| Show CertificateRejectReason Source # | |
Defined in Network.TLS.X509 Methods showsPrec :: Int -> CertificateRejectReason -> ShowS show :: CertificateRejectReason -> String showList :: [CertificateRejectReason] -> ShowS | |
newtype CertificateType Source #
Some of the IANA registered code points for CertificateType are not
currently supported by the library. Nor should they be, they're are either
unwise, obsolete or both. There's no point in conveying these to the user
in the client certificate request callback. The request callback will be
filtered to exclude unsupported values. If the user cannot find a certificate
for a supported code point, we'll go ahead without a client certificate and
hope for the best, unless the user's callback decides to throw an exception.
Constructors
| CertificateType | |
Fields
| |
Bundled Patterns
| pattern CertificateType_DSA_Sign :: CertificateType | TLS10 and up, RFC5246 |
| pattern CertificateType_ECDSA_Sign :: CertificateType | TLS10 and up, RFC8422 |
| pattern CertificateType_Ed25519_Sign :: CertificateType | |
| pattern CertificateType_Ed448_Sign :: CertificateType | |
| pattern CertificateType_RSA_Sign :: CertificateType | TLS10 and up, RFC5246 |
Instances
| Eq CertificateType Source # | |
Defined in Network.TLS.Struct Methods (==) :: CertificateType -> CertificateType -> Bool (/=) :: CertificateType -> CertificateType -> Bool | |
| Ord CertificateType Source # | |
Defined in Network.TLS.Struct Methods compare :: CertificateType -> CertificateType -> Ordering (<) :: CertificateType -> CertificateType -> Bool (<=) :: CertificateType -> CertificateType -> Bool (>) :: CertificateType -> CertificateType -> Bool (>=) :: CertificateType -> CertificateType -> Bool max :: CertificateType -> CertificateType -> CertificateType min :: CertificateType -> CertificateType -> CertificateType | |
| Show CertificateType Source # | |
Defined in Network.TLS.Struct Methods showsPrec :: Int -> CertificateType -> ShowS show :: CertificateType -> String showList :: [CertificateType] -> ShowS | |
newtype CertificateChain #
Constructors
| CertificateChain [SignedExact Certificate] |
Instances
| Eq CertificateChain # | |
Defined in Data.X509.CertificateChain Methods (==) :: CertificateChain -> CertificateChain -> Bool (/=) :: CertificateChain -> CertificateChain -> Bool | |
| Show CertificateChain # | |
Defined in Data.X509.CertificateChain Methods showsPrec :: Int -> CertificateChain -> ShowS show :: CertificateChain -> String showList :: [CertificateChain] -> ShowS | |
data MaxFragmentEnum Source #
Constructors
| MaxFragment512 | |
| MaxFragment1024 | |
| MaxFragment2048 | |
| MaxFragment4096 |
Instances
| Eq MaxFragmentEnum Source # | |
Defined in Network.TLS.Extension Methods (==) :: MaxFragmentEnum -> MaxFragmentEnum -> Bool (/=) :: MaxFragmentEnum -> MaxFragmentEnum -> Bool | |
| Show MaxFragmentEnum Source # | |
Defined in Network.TLS.Extension Methods showsPrec :: Int -> MaxFragmentEnum -> ShowS show :: MaxFragmentEnum -> String showList :: [MaxFragmentEnum] -> ShowS | |
Advanced APIs
Backend
ctxBackend :: Context -> Backend Source #
return the backend object associated with this context
contextFlush :: Context -> IO () Source #
A shortcut for 'backendFlush . ctxBackend'.
contextClose :: Context -> IO () Source #
A shortcut for 'backendClose . ctxBackend'.
For a Socket, this is close, which
also wakes up threads blocked on the socket. If no thread is left on
it, call bye and then unsafeClose (network 3.2.11 or
later) on the socket instead, or give contextNew a
Backend whose backendClose does so.
Information gathering
data Information Source #
Information related to a running context, e.g. current cipher
Instances
| Eq Information Source # | |
Defined in Network.TLS.Parameters | |
| Show Information Source # | |
Defined in Network.TLS.Parameters Methods showsPrec :: Int -> Information -> ShowS show :: Information -> String showList :: [Information] -> ShowS | |
contextGetInformation :: Context -> IO (Maybe Information) Source #
Information about the current context
infoVersion :: Information -> Version Source #
infoCipher :: Information -> Cipher Source #
infoMainSecret :: Information -> Maybe ByteString Source #
infoExtendedMainSecret :: Information -> Bool Source #
infoClientRandom :: Information -> Maybe ClientRandom Source #
infoServerRandom :: Information -> Maybe ServerRandom Source #
infoSupportedGroup :: Information -> Maybe Group Source #
infoTLS12Resumption :: Information -> Bool Source #
infoTLS13HandshakeMode :: Information -> Maybe HandshakeMode13 Source #
infoIsEarlyDataAccepted :: Information -> Bool Source #
infoIsECHAccepted :: Information -> Bool Source #
infoServerSignatureScheme :: Information -> Maybe SignatureScheme Source #
The scheme of the server's signature: ServerKeyExchange in TLS 1.2,
CertificateVerify in TLS 1.3. Nothing on resumption.
infoClientSignatureScheme :: Information -> Maybe SignatureScheme Source #
The scheme of the client's CertificateVerify. Nothing without a
client certificate or on resumption.
data ClientRandom Source #
Instances
| Eq ClientRandom Source # | |
Defined in Network.TLS.Struct | |
| Show ClientRandom Source # | |
Defined in Network.TLS.Struct Methods showsPrec :: Int -> ClientRandom -> ShowS show :: ClientRandom -> String showList :: [ClientRandom] -> ShowS | |
data ServerRandom Source #
Instances
| Eq ServerRandom Source # | |
Defined in Network.TLS.Struct | |
| Show ServerRandom Source # | |
Defined in Network.TLS.Struct Methods showsPrec :: Int -> ServerRandom -> ShowS show :: ServerRandom -> String showList :: [ServerRandom] -> ShowS | |
unClientRandom :: ClientRandom -> ByteString Source #
unServerRandom :: ServerRandom -> ByteString Source #
data HandshakeMode13 Source #
Type to show which handshake mode is used in TLS 1.3.
Constructors
| FullHandshake | Full handshake is used. |
| HelloRetryRequest | Full handshake is used with hello retry request. |
| PreSharedKey | Server authentication is skipped. |
| RTT0 | Server authentication is skipped and early data is sent. |
Instances
| Eq HandshakeMode13 Source # | |
Defined in Network.TLS.Handshake.State Methods (==) :: HandshakeMode13 -> HandshakeMode13 -> Bool (/=) :: HandshakeMode13 -> HandshakeMode13 -> Bool | |
| Show HandshakeMode13 Source # | |
Defined in Network.TLS.Handshake.State Methods showsPrec :: Int -> HandshakeMode13 -> ShowS show :: HandshakeMode13 -> String showList :: [HandshakeMode13] -> ShowS | |
getClientCertificateChain :: Context -> IO (Maybe CertificateChain) Source #
Getting certificates from a client, if any. A client sends no certificate on resumption; then this returns the leaf certificate it was authenticated with in the original connection. That chain was validated then and is not checked again.
getServerCertificateChain :: Context -> IO (Maybe CertificateChain) Source #
Negotiated
getNegotiatedProtocol :: MonadIO m => Context -> m (Maybe ByteString) Source #
If the ALPN extensions have been used, this will return get the protocol agreed upon.
getClientSNI :: MonadIO m => Context -> m (Maybe HostName) Source #
If the Server Name Indication extension has been used, return the hostname specified by the client.
Post-handshake actions
updateKey :: MonadIO m => Context -> KeyUpdateRequest -> m Bool Source #
Updating application traffic secrets for TLS 1.3.
If the keys are updated, True is returned.
Otherwise, that is, for TLS 1.2 or after 2^48-1 updates, False is
returned.
data KeyUpdateRequest Source #
How to update keys in TLS 1.3
Instances
| Eq KeyUpdateRequest Source # | |
Defined in Network.TLS.Handshake.Server.TLS13 Methods (==) :: KeyUpdateRequest -> KeyUpdateRequest -> Bool (/=) :: KeyUpdateRequest -> KeyUpdateRequest -> Bool | |
| Show KeyUpdateRequest Source # | |
Defined in Network.TLS.Handshake.Server.TLS13 Methods showsPrec :: Int -> KeyUpdateRequest -> ShowS show :: KeyUpdateRequest -> String showList :: [KeyUpdateRequest] -> ShowS | |
requestCertificate :: Context -> IO Bool Source #
Deprecated: Application data before the response closes the connection; use requestCertificateAsync
Post-handshake certificate request with TLS 1.3. Returns False
if the request was impossible, i.e. the remote client does not support
post-handshake authentication or the connection is established in
TLS 1.2. Returns True if the client authentication succeeds. An
exception is thrown if the authentication fails. Server only.
This reads the client's response by itself, so it must not be called
while another thread is in recvData, and application data received
before the response closes the connection, against RFC 9846 Section 4.7.2.
requestCertificateAsync :: Context -> IO (Bool -> IO PHAResult) Source #
Post-handshake certificate request with TLS 1.3, without waiting for
the response. The response is processed by recvData, so another
thread or the caller itself must keep calling it. The returned action
gives the result; with True it blocks until the result is known, with
False it returns PHAPending meanwhile. Only one request may be
pending. getClientCertificateChain gives the authenticated chain.
Server only.
The result of requestCertificateAsync.
Constructors
| PHAUnavailable | The request could not be sent: TLS 1.2, no post_handshake_auth from the client, or another request pending. |
| PHAPending | No response yet. Only when not waiting. |
| PHAAccepted CertificateChain | The client was authenticated with this chain. |
| PHADeclined | The client sent an empty certificate, accepted by
|
| PHAFailed TLSError | The verification failed or the connection was closed. |
getTLSUnique :: Context -> IO (Maybe ByteString) Source #
Getting the "tls-unique" channel binding for TLS 1.2 (RFC5929).
For TLS 1.3, Nothing is returned.
supportedExtendedMainSecret must be RequireEMS
But in general, it is highly recommended to upgrade to TLS 1.3
and use the "tls-exporter" channel binding via getTLSExporter.
getTLSExporter :: Context -> IO (Maybe ByteString) Source #
Getting the "tls-exporter" channel binding for TLS 1.3 (RFC9266).
For TLS 1.2, Nothing is returned.
getTLSServerEndPoint :: Context -> IO (Maybe ByteString) Source #
Getting the "tls-server-end-point" channel binding (RFC5929).
This hashes the server's leaf certificate, exactly as it appears in the Certificate message, with the hash its own signature names, and with SHA-256 standing in for MD5 and SHA-1. Since it depends on nothing but the certificate, it is computed for TLS 1.2 and for certificate-authenticated TLS 1.3 alike -- though RFC 5929 predates TLS 1.3 and no RFC defines it there.
Nothing is returned when there is no server certificate, as on a
resumption or with a pre-shared key, and when the certificate's
signature names no hash to use: an Ed25519 or Ed448 signature names the
whole scheme and the binding is undefined for it.
getFinished :: Context -> IO (Maybe VerifyData) Source #
Deprecated: Use getTLSUnique instead
Getting TLS Finished sent to peer.
getPeerFinished :: Context -> IO (Maybe VerifyData) Source #
Deprecated: Use getTLSUnique instead
Getting TLS Finished received from peer.
Modifying hooks in context
A collection of hooks actions.
defaultHooks :: Hooks Source #
hookRecvHandshake :: Hooks -> Handshake -> IO Handshake Source #
called at each handshake message received
hookRecvHandshake13 :: Hooks -> Handshake13 -> IO Handshake13 Source #
called at each handshake message received for TLS 1.3
hookRecvCertificates :: Hooks -> CertificateChain -> IO () Source #
called at each certificate chain message received
hookLogging :: Hooks -> Logging Source #
hooks on IO and packets, receiving and sending.
Instances
data Handshake13 Source #
Instances
| Eq Handshake13 Source # | |
Defined in Network.TLS.Struct13 | |
| Show Handshake13 Source # | |
Defined in Network.TLS.Struct13 Methods showsPrec :: Int -> Handshake13 -> ShowS show :: Handshake13 -> String showList :: [Handshake13] -> ShowS | |
contextHookSetHandshake13Recv :: Context -> (Handshake13 -> IO Handshake13) -> IO () Source #
contextHookSetCertificateRecv :: Context -> (CertificateChain -> IO ()) -> IO () Source #
Hooks for logging
This is called when sending and receiving packets and IO
loggingPacketSent :: Logging -> String -> IO () Source #
loggingPacketRecv :: Logging -> String -> IO () Source #
loggingIOSent :: Logging -> ByteString -> IO () Source #
loggingIORecv :: Logging -> Header -> ByteString -> IO () Source #
Constructors
| Header ProtocolType Version Word16 |
newtype ProtocolType Source #
Constructors
| ProtocolType | |
Fields
| |
Bundled Patterns
| pattern ProtocolType_Alert :: ProtocolType | |
| pattern ProtocolType_AppData :: ProtocolType | |
| pattern ProtocolType_ChangeCipherSpec :: ProtocolType | |
| pattern ProtocolType_Handshake :: ProtocolType |
Instances
| Eq ProtocolType Source # | |
Defined in Network.TLS.Struct | |
| Show ProtocolType Source # | |
Defined in Network.TLS.Struct Methods showsPrec :: Int -> ProtocolType -> ShowS show :: ProtocolType -> String showList :: [ProtocolType] -> ShowS | |
contextHookSetLogging :: Context -> Logging -> IO () Source #
Errors and exceptions
Errors
TLSError that might be returned through the TLS stack.
Prior to version 1.8.0, this type had an Exception instance.
In version 1.8.0, this instance was removed, and functions in
this library now only throw TLSException.
Constructors
| Error_Misc String | mainly for instance of Error |
| Error_Protocol String AlertDescription | A fatal error condition was encountered at a low level. The elements of the tuple give (freeform text description, structured error description). |
| Error_Protocol_Warning String AlertDescription | A non-fatal error condition was encountered at a low level at a low level. The elements of the tuple give (freeform text description, structured error description). |
| Error_Certificate String | |
| Error_HandshakePolicy String | handshake policy failed. |
| Error_EOF | |
| Error_Packet String | |
| Error_Packet_unexpected String String | |
| Error_Packet_Parsing String | |
| Error_TCP_Terminate |
Constructors
| RSAError Error | |
| KxUnsupported |
newtype AlertDescription Source #
Constructors
| AlertDescription | |
Fields
| |
Bundled Patterns
Instances
| Eq AlertDescription Source # | |
Defined in Network.TLS.Error Methods (==) :: AlertDescription -> AlertDescription -> Bool (/=) :: AlertDescription -> AlertDescription -> Bool | |
| Show AlertDescription Source # | |
Defined in Network.TLS.Error Methods showsPrec :: Int -> AlertDescription -> ShowS show :: AlertDescription -> String showList :: [AlertDescription] -> ShowS | |
Exceptions
data TLSException Source #
TLS Exceptions. Some of the data constructors indicate incorrect use of
the library, and the documentation for those data constructors calls
this out. The others wrap TLSError with some kind of context to explain
when the exception occurred.
Constructors
| Terminated Bool String TLSError | Early termination exception with the reason and the error associated |
| HandshakeFailed TLSError | Handshake failed for the reason attached. |
| PostHandshake TLSError | Failure occurred while sending or receiving data after the TLS handshake succeeded. |
| Uncontextualized TLSError | Lifts a |
| ConnectionNotEstablished | Usage error when the connection has not been established and the user is trying to send or receive data. Indicates that this library has been used incorrectly. |
| MissingHandshake | Expected that a TLS handshake had already taken place, but no TLS handshake had occurred. Indicates that this library has been used incorrectly. |
Instances
| Eq TLSException Source # | |
Defined in Network.TLS.Error | |
| Exception TLSException Source # | |
Defined in Network.TLS.Error Methods toException :: TLSException -> SomeException fromException :: SomeException -> Maybe TLSException displayException :: TLSException -> String backtraceDesired :: TLSException -> Bool | |
| Show TLSException Source # | |
Defined in Network.TLS.Error Methods showsPrec :: Int -> TLSException -> ShowS show :: TLSException -> String showList :: [TLSException] -> ShowS | |
Raw types
Compressions class
class CompressionC a where Source #
supported compression algorithms need to be part of this class
Methods
compressionCID :: a -> CompressionID Source #
compressionCDeflate :: a -> ByteString -> (a, ByteString) Source #
compressionCInflate :: a -> ByteString -> (a, ByteString) Source #
type CompressionID = Word8 Source #
Compression identification
Crypto Key
Constructors
| PubKeyRSA PublicKey | |
| PubKeyDSA PublicKey | |
| PubKeyDH (Integer, Integer, Integer, Maybe Integer, ([Word8], Integer)) | |
| PubKeyEC PubKeyEC | |
| PubKeyX25519 PublicKey | |
| PubKeyX448 PublicKey | |
| PubKeyEd25519 PublicKey | |
| PubKeyEd448 PublicKey | |
| PubKeyMLDSA44 (VerificationKey MLDSA44) | |
| PubKeyMLDSA65 (VerificationKey MLDSA65) | |
| PubKeyMLDSA87 (VerificationKey MLDSA87) | |
| PubKeyUnknown OID ByteString |
Constructors
| PrivKeyRSA PrivateKey | |
| PrivKeyDSA PrivateKey | |
| PrivKeyEC PrivKeyEC | |
| PrivKeyX25519 SecretKey | |
| PrivKeyX448 SecretKey | |
| PrivKeyEd25519 SecretKey | |
| PrivKeyEd448 SecretKey | |
| PrivKeyMLDSA44 (PrivKeyMLDSA MLDSA44) | |
| PrivKeyMLDSA65 (PrivKeyMLDSA MLDSA65) | |
| PrivKeyMLDSA87 (PrivKeyMLDSA MLDSA87) |
Instances
| DebugShow PrivKey # | |
Defined in Data.X509.PrivateKey | |
| ASN1Object PrivKey # | |
Defined in Data.X509.PrivateKey | |
| Eq PrivKey # | |
| Show PrivKey # | |
data ExtKeyUsagePurpose #
Constructors
| KeyUsagePurpose_ServerAuth | |
| KeyUsagePurpose_ClientAuth | |
| KeyUsagePurpose_CodeSigning | |
| KeyUsagePurpose_EmailProtection | |
| KeyUsagePurpose_TimeStamping | |
| KeyUsagePurpose_OCSPSigning | |
| KeyUsagePurpose_Unknown OID |
Instances
| Eq ExtKeyUsagePurpose # | |
Defined in Data.X509.Ext Methods (==) :: ExtKeyUsagePurpose -> ExtKeyUsagePurpose -> Bool (/=) :: ExtKeyUsagePurpose -> ExtKeyUsagePurpose -> Bool | |
| Ord ExtKeyUsagePurpose # | |
Defined in Data.X509.Ext Methods compare :: ExtKeyUsagePurpose -> ExtKeyUsagePurpose -> Ordering (<) :: ExtKeyUsagePurpose -> ExtKeyUsagePurpose -> Bool (<=) :: ExtKeyUsagePurpose -> ExtKeyUsagePurpose -> Bool (>) :: ExtKeyUsagePurpose -> ExtKeyUsagePurpose -> Bool (>=) :: ExtKeyUsagePurpose -> ExtKeyUsagePurpose -> Bool max :: ExtKeyUsagePurpose -> ExtKeyUsagePurpose -> ExtKeyUsagePurpose min :: ExtKeyUsagePurpose -> ExtKeyUsagePurpose -> ExtKeyUsagePurpose | |
| Show ExtKeyUsagePurpose # | |
Defined in Data.X509.Ext Methods showsPrec :: Int -> ExtKeyUsagePurpose -> ShowS show :: ExtKeyUsagePurpose -> String showList :: [ExtKeyUsagePurpose] -> ShowS | |
Ciphers & Predefined ciphers
cipherAllowedForVersion :: Version -> Cipher -> Bool Source #
Check if a specific Cipher is allowed to be used
with the version specified
cipherKeyBlockSize :: Cipher -> Int Source #
elemCipher :: [CipherId] -> Cipher -> Bool Source #
hasMAC :: BulkFunctions -> Bool Source #
hasRecordIV :: BulkFunctions -> Bool Source #
intersectCiphers :: [CipherId] -> [Cipher] -> [Cipher] Source #
Constructors
| Bulk | |
Fields
| |
type BulkAEAD = BulkNonce -> ByteString -> BulkAdditionalData -> (ByteString, AuthTag) Source #
type BulkAdditionalData = ByteString Source #
data BulkDirection Source #
Constructors
| BulkEncrypt | |
| BulkDecrypt |
Instances
| Eq BulkDirection Source # | |
Defined in Network.TLS.Types.Cipher | |
| Show BulkDirection Source # | |
Defined in Network.TLS.Types.Cipher Methods showsPrec :: Int -> BulkDirection -> ShowS show :: BulkDirection -> String showList :: [BulkDirection] -> ShowS | |
data BulkFunctions Source #
Constructors
| BulkBlockF (BulkDirection -> BulkKey -> BulkBlock) | |
| BulkStreamF (BulkDirection -> BulkKey -> BulkStream) | |
| BulkAeadF (BulkDirection -> BulkKey -> BulkAEAD) |
newtype BulkStream Source #
Constructors
| BulkStream (ByteString -> (ByteString, BulkStream)) |
Cipher algorithm
Constructors
| Cipher | |
Fields
| |
data CipherKeyExchangeType Source #
Constructors
Instances
| Eq CipherKeyExchangeType Source # | |
Defined in Network.TLS.Types.Cipher Methods (==) :: CipherKeyExchangeType -> CipherKeyExchangeType -> Bool (/=) :: CipherKeyExchangeType -> CipherKeyExchangeType -> Bool | |
| Show CipherKeyExchangeType Source # | |
Defined in Network.TLS.Types.Cipher Methods showsPrec :: Int -> CipherKeyExchangeType -> ShowS show :: CipherKeyExchangeType -> String showList :: [CipherKeyExchangeType] -> ShowS | |
Deprecated
recvData' :: MonadIO m => Context -> m ByteString Source #
Deprecated: use recvData that returns strict bytestring
same as recvData but returns a lazy bytestring.
data ValidationChecks #
Constructors
| ValidationChecks | |
Fields
| |
Instances
| Default ValidationChecks # | |
Defined in Data.X509.Validation Methods | |
| Eq ValidationChecks # | |
Defined in Data.X509.Validation Methods (==) :: ValidationChecks -> ValidationChecks -> Bool (/=) :: ValidationChecks -> ValidationChecks -> Bool | |
| Show ValidationChecks # | |
Defined in Data.X509.Validation Methods showsPrec :: Int -> ValidationChecks -> ShowS show :: ValidationChecks -> String showList :: [ValidationChecks] -> ShowS | |
data ValidationHooks #
Constructors
| ValidationHooks | |
Fields
| |
Instances
| Default ValidationHooks # | |
Defined in Data.X509.Validation Methods | |
clientUseMaxFragmentLength :: ClientParams -> Maybe MaxFragmentEnum Source #
Deprecated: UseMaxFragmentLength is deprecated
Default: Nothing