tls-1.6.0: TLS/SSL protocol native implementation (Server and Client)
LicenseBSD-style
MaintainerVincent Hanquez <vincent@snarc.org>
Stabilityexperimental
Portabilityunknown
Safe HaskellSafe-Inferred
LanguageHaskell2010

Network.TLS

Description

Native Haskell TLS and SSL protocol implementation for server and client.

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 SSL3.0, TLS1.0, TLS1.1, TLS1.2 and TLS 1.3 protocol, and support RSA and Ephemeral (Elliptic curve and regular) Diffie Hellman key exchanges, and many extensions.

Some debug tools linked with tls, are available through the http://hackage.haskell.org/package/tls-debug/.

Synopsis

Basic APIs

data Context Source #

A TLS Context keep tls specific state, parameters and backend information.

contextNew Source #

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

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.

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

Backend abstraction

class HasBackend a where Source #

Methods

initializeBackend :: a -> IO () Source #

getBackend :: a -> Backend Source #

Instances

Instances details
HasBackend Handle Source # 
Instance details

Defined in Network.TLS.Backend

Methods

initializeBackend :: Handle -> IO () Source #

getBackend :: Handle -> Backend Source #

HasBackend Socket Source # 
Instance details

Defined in Network.TLS.Backend

Methods

initializeBackend :: Socket -> IO () Source #

getBackend :: Socket -> Backend Source #

HasBackend Backend Source # 
Instance details

Defined in Network.TLS.Backend

data Backend Source #

Connection IO backend

Constructors

Backend 

Fields

  • backendFlush :: IO ()

    Flush the connection sending buffer, if any.

  • backendClose :: IO ()

    Close the connection.

  • backendSend :: ByteString -> IO ()

    Send a bytestring through the connection.

  • backendRecv :: Int -> IO ByteString

    Receive specified number of bytes from the connection.

Instances

Instances details
HasBackend Backend Source # 
Instance details

Defined in Network.TLS.Backend

Parameters

class TLSParams a Source #

Minimal complete definition

getTLSCommonParams, getTLSRole, doHandshake, doHandshakeWith, doRequestCertificate, doPostHandshakeAuthWith

data ClientParams Source #

Constructors

ClientParams 

Fields

Instances

Instances details
Show ClientParams Source # 
Instance details

Defined in Network.TLS.Parameters

Methods

showsPrec :: Int -> ClientParams -> ShowS

show :: ClientParams -> String

showList :: [ClientParams] -> ShowS

TLSParams ClientParams Source # 
Instance details

Defined in Network.TLS.Context

data ServerParams Source #

Constructors

ServerParams 

Fields

Instances

Instances details
Show ServerParams Source # 
Instance details

Defined in Network.TLS.Parameters

Methods

showsPrec :: Int -> ServerParams -> ShowS

show :: ServerParams -> String

showList :: [ServerParams] -> ShowS

Default ServerParams Source # 
Instance details

Defined in Network.TLS.Parameters

Methods

def :: ServerParams

TLSParams ServerParams Source # 
Instance details

Defined in Network.TLS.Context

Shared

data Shared Source #

Parameters that are common to clients and servers.

Constructors

Shared 

Fields

  • sharedCredentials :: Credentials

    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 :: SessionManager

    Callbacks used by clients and servers in order to resume TLS sessions. The default implementation never resumes sessions. Package tls-session-manager provides an in-memory implementation.

    Default: noSessionManager

  • sharedCAStore :: CertificateStore

    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 x509-system gives access to a default certificate store configured in the system.

    Default: mempty

  • sharedValidationCache :: ValidationCache

    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 :: [ExtensionRaw]

    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: []

Instances

Instances details
Show Shared Source # 
Instance details

Defined in Network.TLS.Parameters

Methods

showsPrec :: Int -> Shared -> ShowS

show :: Shared -> String

showList :: [Shared] -> ShowS

Default Shared Source # 
Instance details

Defined in Network.TLS.Parameters

Methods

def :: Shared

Hooks

data ClientHooks Source #

A set of callbacks run by the clients for various corners of TLS establishment

Constructors

ClientHooks 

Fields

  • onCertificateRequest :: OnCertificateRequest

    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 HashAndSignatureAlgorithm 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 RSA pairs with a hash component of Intrinsic (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.

    Default: returns Nothing anyway.

  • onServerCertificate :: OnServerCertificate

    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 extension of the end-entity certificate, as this depends on the dynamically-selected cipher and this part should not be cached. Key-usage verification is performed by the library internally.

    Default: validateDefault

  • onSuggestALPN :: IO (Maybe [ByteString])

    This action is called when the client sends ClientHello to determine ALPN values such as '["h2", "http/1.1"]'.

    Default: returns Nothing

  • onCustomFFDHEGroup :: DHParams -> DHPublic -> IO GroupUsage

    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:

    1. rejecting if dh_p is even
    2. rejecting unless 1 < dh_g && dh_g < dh_p - 1
    3. rejecting unless 1 < dh_p && pub < dh_p - 1
    4. rejecting if dh_size < 1024 (to prevent Logjam attack)

    See RFC 7919 section 3.1 for recommandations.

Instances

Instances details
Show ClientHooks Source # 
Instance details

Defined in Network.TLS.Parameters

Methods

showsPrec :: Int -> ClientHooks -> ShowS

show :: ClientHooks -> String

showList :: [ClientHooks] -> ShowS

Default ClientHooks Source # 
Instance details

Defined in Network.TLS.Parameters

Methods

def :: ClientHooks

type OnCertificateRequest = ([CertificateType], Maybe [HashAndSignatureAlgorithm], [DistinguishedName]) -> IO (Maybe (CertificateChain, PrivKey)) Source #

Type for onCertificateRequest. This type synonym is to make document readable.

type OnServerCertificate = CertificateStore -> ValidationCache -> ServiceID -> CertificateChain -> IO [FailedReason] Source #

Type for onServerCertificate. This type synonym is to make document readable.

data ServerHooks Source #

A set of callbacks run by the server for various corners of the TLS establishment

Constructors

ServerHooks 

Fields

  • onClientCertificate :: CertificateChain -> IO CertificateUsage

    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 followings:

    CertificateUsageReject (CertificateRejectOther "no client certificates expected")
    
  • onUnverifiedClientCert :: IO Bool

    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 :: Version -> [Cipher] -> Cipher

    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 prefered with TLS < 1.1)

    The client cipher list cannot be empty.

    Default: taking the head of ciphers.

  • onServerNameIndication :: Maybe HostName -> IO Credentials

    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 :: Measurement -> IO Bool

    At each new handshake, we call this hook to see if we allow handshake to happens.

    Default: returns True

  • onALPNClientSuggest :: Maybe ([ByteString] -> IO ByteString)

    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 :: [ExtensionRaw] -> IO [ExtensionRaw]

    Allow to modify extensions to be sent in EncryptedExtensions of TLS 1.3.

    Default: 'return . id'

Instances

Instances details
Show ServerHooks Source # 
Instance details

Defined in Network.TLS.Parameters

Methods

showsPrec :: Int -> ServerHooks -> ShowS

show :: ServerHooks -> String

showList :: [ServerHooks] -> ShowS

Default ServerHooks Source # 
Instance details

Defined in Network.TLS.Parameters

Methods

def :: ServerHooks

data Measurement Source #

record some data about this connection.

Constructors

Measurement 

Fields

Instances

Instances details
Show Measurement Source # 
Instance details

Defined in Network.TLS.Measurement

Methods

showsPrec :: Int -> Measurement -> ShowS

show :: Measurement -> String

showList :: [Measurement] -> ShowS

Eq Measurement Source # 
Instance details

Defined in Network.TLS.Measurement

Methods

(==) :: Measurement -> Measurement -> Bool

(/=) :: Measurement -> Measurement -> Bool

Supported

data Supported Source #

List all the supported algorithms, versions, ciphers, etc supported.

Constructors

Supported 

Fields

  • supportedVersions :: [Version]

    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 preference order, i.e. higher versions first.

    Default: [TLS13,TLS12,TLS11,TLS10]

  • supportedCiphers :: [Cipher]

    Supported cipher methods. The default is empty, specify a suitable cipher list. ciphersuite_default is often a good choice.

    Default: []

  • supportedCompressions :: [Compression]

    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 :: [HashAndSignatureAlgorithm]

    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, DSS.

    Default:

      [ (HashIntrinsic,     SignatureEd448)
      , (HashIntrinsic,     SignatureEd25519)
      , (Struct.HashSHA256, SignatureECDSA)
      , (Struct.HashSHA384, SignatureECDSA)
      , (Struct.HashSHA512, SignatureECDSA)
      , (HashIntrinsic,     SignatureRSApssRSAeSHA512)
      , (HashIntrinsic,     SignatureRSApssRSAeSHA384)
      , (HashIntrinsic,     SignatureRSApssRSAeSHA256)
      , (Struct.HashSHA512, SignatureRSA)
      , (Struct.HashSHA384, SignatureRSA)
      , (Struct.HashSHA256, SignatureRSA)
      , (Struct.HashSHA1,   SignatureRSA)
      , (Struct.HashSHA1,   SignatureDSS)
      ]
    
  • supportedSecureRenegotiation :: Bool

    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 :: Bool

    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

  • supportedExtendedMasterSec :: EMSMode

    The mode regarding extended master secret. Enabling this extension provides better security for TLS versions 1.0 to 1.2. TLS 1.3 provides the security properties natively and does not need the extension.

    By default the extension is enabled but not required. If mode is set to RequireEMS, the handshake will fail when the peer does not support the extension. It is also advised to disable SSLv3 which does not have this mechanism.

    Default: AllowEMS

  • supportedSession :: Bool

    Set if we support session.

    Default: True

  • supportedFallbackScsv :: Bool

    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 :: Bool

    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 :: [Group]

    A list of supported elliptic curves and finite-field groups in the preferred order.

    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: [X25519,X448,P256,FFDHE3072,FFDHE4096,P384,FFDHE6144,FFDHE8192,P521]

Instances

Instances details
Show Supported Source # 
Instance details

Defined in Network.TLS.Parameters

Methods

showsPrec :: Int -> Supported -> ShowS

show :: Supported -> String

showList :: [Supported] -> ShowS

Default Supported Source # 
Instance details

Defined in Network.TLS.Parameters

Methods

def :: Supported

Eq Supported Source # 
Instance details

Defined in Network.TLS.Parameters

Methods

(==) :: Supported -> Supported -> Bool

(/=) :: Supported -> Supported -> Bool

Debug parameters

data DebugParams Source #

All settings should not be used in production

Constructors

DebugParams 

Fields

  • debugSeed :: Maybe Seed

    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 :: Seed -> IO ()

    Add a way to print the seed that was randomly generated. re-using the same seed will reproduce the same randomness with debugSeed

    Default: no printing

  • debugVersionForced :: Maybe Version

    Force to choose this version in the server side.

    Default: Nothing

  • debugKeyLogger :: String -> IO ()

    Printing master keys.

    Default: no printing

Instances

Instances details
Show DebugParams Source # 
Instance details

Defined in Network.TLS.Parameters

Methods

showsPrec :: Int -> DebugParams -> ShowS

show :: DebugParams -> String

showList :: [DebugParams] -> ShowS

Default DebugParams Source # 
Instance details

Defined in Network.TLS.Parameters

Methods

def :: DebugParams

Shared parameters

Credentials

newtype Credentials Source #

Constructors

Credentials [Credential] 

Instances

Instances details
Monoid Credentials Source # 
Instance details

Defined in Network.TLS.Credentials

Semigroup Credentials Source # 
Instance details

Defined in Network.TLS.Credentials

Methods

(<>) :: Credentials -> Credentials -> Credentials

sconcat :: NonEmpty Credentials -> Credentials

stimes :: Integral b => b -> Credentials -> Credentials

Show Credentials Source # 
Instance details

Defined in Network.TLS.Credentials

Methods

showsPrec :: Int -> Credentials -> ShowS

show :: Credentials -> String

showList :: [Credentials] -> ShowS

type Credential = (CertificateChain, PrivKey) Source #

credentialLoadX509 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

Constructors

SessionManager 

Fields

noSessionManager :: SessionManager Source #

The session manager to do nothing.

type SessionID = ByteString Source #

A session ID

data SessionData Source #

Session data to resume

Instances

Instances details
Show SessionData Source # 
Instance details

Defined in Network.TLS.Types

Methods

showsPrec :: Int -> SessionData -> ShowS

show :: SessionData -> String

showList :: [SessionData] -> ShowS

Eq SessionData Source # 
Instance details

Defined in Network.TLS.Types

Methods

(==) :: SessionData -> SessionData -> Bool

(/=) :: SessionData -> SessionData -> Bool

data SessionFlag Source #

Some session flags

Constructors

SessionEMS

Session created with Extended Master Secret

Instances

Instances details
Enum SessionFlag Source # 
Instance details

Defined in Network.TLS.Types

Show SessionFlag Source # 
Instance details

Defined in Network.TLS.Types

Methods

showsPrec :: Int -> SessionFlag -> ShowS

show :: SessionFlag -> String

showList :: [SessionFlag] -> ShowS

Eq SessionFlag Source # 
Instance details

Defined in Network.TLS.Types

Methods

(==) :: SessionFlag -> SessionFlag -> Bool

(/=) :: SessionFlag -> SessionFlag -> Bool

data TLS13TicketInfo Source #

Instances

Instances details
Show TLS13TicketInfo Source # 
Instance details

Defined in Network.TLS.Types

Methods

showsPrec :: Int -> TLS13TicketInfo -> ShowS

show :: TLS13TicketInfo -> String

showList :: [TLS13TicketInfo] -> ShowS

Eq TLS13TicketInfo Source # 
Instance details

Defined in Network.TLS.Types

Validation Cache

data ValidationCache #

Instances

Instances details
Default ValidationCache 
Instance details

Defined in Data.X509.Validation.Cache

type ValidationCacheQueryCallback = ServiceID -> Fingerprint -> Certificate -> IO ValidationCacheResult #

type ValidationCacheAddCallback = ServiceID -> Fingerprint -> Certificate -> IO () #

exceptionValidationCache :: [(ServiceID, Fingerprint)] -> ValidationCache #

Types

For Supported

data Version Source #

Versions known to TLS

SSL2 is just defined, but this version is and will not be supported.

Constructors

SSL2 
SSL3 
TLS10 
TLS11 
TLS12 
TLS13 

Instances

Instances details
Bounded Version Source # 
Instance details

Defined in Network.TLS.Types

Show Version Source # 
Instance details

Defined in Network.TLS.Types

Methods

showsPrec :: Int -> Version -> ShowS

show :: Version -> String

showList :: [Version] -> ShowS

Eq Version Source # 
Instance details

Defined in Network.TLS.Types

Methods

(==) :: Version -> Version -> Bool

(/=) :: Version -> Version -> Bool

Ord Version Source # 
Instance details

Defined in Network.TLS.Types

Methods

compare :: Version -> Version -> Ordering

(<) :: Version -> Version -> Bool

(<=) :: Version -> Version -> Bool

(>) :: Version -> Version -> Bool

(>=) :: Version -> Version -> Bool

max :: Version -> Version -> Version

min :: Version -> Version -> Version

data Compression Source #

every compression need to be wrapped in this, to fit in structure

Constructors

forall a.CompressionC a => Compression a 

Instances

Instances details
Show Compression Source # 
Instance details

Defined in Network.TLS.Compression

Methods

showsPrec :: Int -> Compression -> ShowS

show :: Compression -> String

showList :: [Compression] -> ShowS

Eq Compression Source # 
Instance details

Defined in Network.TLS.Compression

Methods

(==) :: Compression -> Compression -> Bool

(/=) :: Compression -> Compression -> Bool

nullCompression :: Compression Source #

default null compression

data HashAlgorithm Source #

Instances

Instances details
Show HashAlgorithm Source # 
Instance details

Defined in Network.TLS.Struct

Methods

showsPrec :: Int -> HashAlgorithm -> ShowS

show :: HashAlgorithm -> String

showList :: [HashAlgorithm] -> ShowS

Eq HashAlgorithm Source # 
Instance details

Defined in Network.TLS.Struct

data Group Source #

Instances

Instances details
Show Group Source # 
Instance details

Defined in Network.TLS.Crypto.Types

Methods

showsPrec :: Int -> Group -> ShowS

show :: Group -> String

showList :: [Group] -> ShowS

Eq Group Source # 
Instance details

Defined in Network.TLS.Crypto.Types

Methods

(==) :: Group -> Group -> Bool

(/=) :: Group -> Group -> Bool

data EMSMode Source #

Client or server policy regarding Extended Master Secret

Constructors

NoEMS

Extended Master Secret is not used

AllowEMS

Extended Master Secret is allowed

RequireEMS

Extended Master Secret is required

Instances

Instances details
Show EMSMode Source # 
Instance details

Defined in Network.TLS.Parameters

Methods

showsPrec :: Int -> EMSMode -> ShowS

show :: EMSMode -> String

showList :: [EMSMode] -> ShowS

Eq EMSMode Source # 
Instance details

Defined in Network.TLS.Parameters

Methods

(==) :: EMSMode -> EMSMode -> Bool

(/=) :: EMSMode -> EMSMode -> Bool

For parameters and hooks

type DHParams = Params Source #

type DHPublic = PublicNumber Source #

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

Instances details
Show GroupUsage Source # 
Instance details

Defined in Network.TLS.Parameters

Methods

showsPrec :: Int -> GroupUsage -> ShowS

show :: GroupUsage -> String

showList :: [GroupUsage] -> ShowS

Eq GroupUsage Source # 
Instance details

Defined in Network.TLS.Parameters

Methods

(==) :: GroupUsage -> GroupUsage -> Bool

(/=) :: GroupUsage -> GroupUsage -> Bool

data CertificateUsage Source #

Certificate Usage callback possible returns values.

Constructors

CertificateUsageAccept

usage of certificate accepted

CertificateUsageReject CertificateRejectReason

usage of certificate rejected

Instances

Instances details
Show CertificateUsage Source # 
Instance details

Defined in Network.TLS.X509

Methods

showsPrec :: Int -> CertificateUsage -> ShowS

show :: CertificateUsage -> String

showList :: [CertificateUsage] -> ShowS

Eq CertificateUsage Source # 
Instance details

Defined in Network.TLS.X509

data 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_RSA_Sign

TLS10 and up, RFC5246

CertificateType_DSS_Sign

TLS10 and up, RFC5246

CertificateType_ECDSA_Sign

TLS10 and up, RFC8422

CertificateType_Ed25519_Sign

TLS13 and up, synthetic

CertificateType_Ed448_Sign

TLS13 and up, synthetic | None of the below will ever be presented to the callback. Any future public key algorithms valid for client certificates go above this line.

CertificateType_RSA_Fixed_DH 
CertificateType_DSS_Fixed_DH 
CertificateType_RSA_Ephemeral_DH 
CertificateType_DSS_Ephemeral_DH 
CertificateType_fortezza_dms 
CertificateType_RSA_Fixed_ECDH 
CertificateType_ECDSA_Fixed_ECDH 
CertificateType_Unknown Word8 

type HostName = String Source #

data MaxFragmentEnum Source #

Instances

Instances details
Show MaxFragmentEnum Source # 
Instance details

Defined in Network.TLS.Extension

Methods

showsPrec :: Int -> MaxFragmentEnum -> ShowS

show :: MaxFragmentEnum -> String

showList :: [MaxFragmentEnum] -> ShowS

Eq MaxFragmentEnum Source # 
Instance details

Defined in Network.TLS.Extension

Advanced APIs

Backend

ctxConnection :: Context -> Backend Source #

return the backend object associated with this context

contextFlush :: Context -> IO () Source #

A shortcut for 'backendFlush . ctxConnection'.

contextClose :: Context -> IO () Source #

A shortcut for 'backendClose . ctxConnection'.

Information gathering

data Information Source #

Information related to a running context, e.g. current cipher

Instances

Instances details
Show Information Source # 
Instance details

Defined in Network.TLS.Context.Internal

Methods

showsPrec :: Int -> Information -> ShowS

show :: Information -> String

showList :: [Information] -> ShowS

Eq Information Source # 
Instance details

Defined in Network.TLS.Context.Internal

Methods

(==) :: Information -> Information -> Bool

(/=) :: Information -> Information -> Bool

contextGetInformation :: Context -> IO (Maybe Information) Source #

Information about the current context

data ClientRandom Source #

Instances

Instances details
Show ClientRandom Source # 
Instance details

Defined in Network.TLS.Struct

Methods

showsPrec :: Int -> ClientRandom -> ShowS

show :: ClientRandom -> String

showList :: [ClientRandom] -> ShowS

Eq ClientRandom Source # 
Instance details

Defined in Network.TLS.Struct

Methods

(==) :: ClientRandom -> ClientRandom -> Bool

(/=) :: ClientRandom -> ClientRandom -> Bool

data ServerRandom Source #

Instances

Instances details
Show ServerRandom Source # 
Instance details

Defined in Network.TLS.Struct

Methods

showsPrec :: Int -> ServerRandom -> ShowS

show :: ServerRandom -> String

showList :: [ServerRandom] -> ShowS

Eq ServerRandom Source # 
Instance details

Defined in Network.TLS.Struct

Methods

(==) :: ServerRandom -> ServerRandom -> Bool

(/=) :: ServerRandom -> ServerRandom -> Bool

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

Instances details
Show HandshakeMode13 Source # 
Instance details

Defined in Network.TLS.Handshake.State

Methods

showsPrec :: Int -> HandshakeMode13 -> ShowS

show :: HandshakeMode13 -> String

showList :: [HandshakeMode13] -> ShowS

Eq HandshakeMode13 Source # 
Instance details

Defined in Network.TLS.Handshake.State

getClientCertificateChain :: Context -> IO (Maybe CertificateChain) Source #

Getting certificates from a client, if any. Note that the certificates are not sent by a client on resumption even if client authentication is required. So, this API would be replaced by the one which can treat both cases of full-negotiation and resumption.

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 appication traffic secrets for TLS 1.3. If this API is called for TLS 1.3, True is returned. Otherwise, False is returned.

data KeyUpdateRequest Source #

How to update keys in TLS 1.3

Constructors

OneWay

Unidirectional key update

TwoWay

Bidirectional key update (normal case)

Instances

Instances details
Show KeyUpdateRequest Source # 
Instance details

Defined in Network.TLS.Core

Methods

showsPrec :: Int -> KeyUpdateRequest -> ShowS

show :: KeyUpdateRequest -> String

showList :: [KeyUpdateRequest] -> ShowS

Eq KeyUpdateRequest Source # 
Instance details

Defined in Network.TLS.Core

requestCertificate :: MonadIO m => Context -> m Bool Source #

Post-handshake certificate request with TLS 1.3. Returns True if the request was possible, i.e. if TLS 1.3 is used and the remote client supports post-handshake authentication.

getFinished :: Context -> IO (Maybe FinishedData) Source #

Get TLS Finished sent to peer

getPeerFinished :: Context -> IO (Maybe FinishedData) Source #

Get TLS Finished received from peer

Modifying hooks in context

data Hooks Source #

A collection of hooks actions.

Constructors

Hooks 

Fields

Instances

Instances details
Default Hooks Source # 
Instance details

Defined in Network.TLS.Hooks

Methods

def :: Hooks

data Handshake Source #

Instances

Instances details
Show Handshake Source # 
Instance details

Defined in Network.TLS.Struct

Methods

showsPrec :: Int -> Handshake -> ShowS

show :: Handshake -> String

showList :: [Handshake] -> ShowS

Eq Handshake Source # 
Instance details

Defined in Network.TLS.Struct

Methods

(==) :: Handshake -> Handshake -> Bool

(/=) :: Handshake -> Handshake -> Bool

data Handshake13 Source #

Instances

Instances details
Show Handshake13 Source # 
Instance details

Defined in Network.TLS.Struct13

Methods

showsPrec :: Int -> Handshake13 -> ShowS

show :: Handshake13 -> String

showList :: [Handshake13] -> ShowS

Eq Handshake13 Source # 
Instance details

Defined in Network.TLS.Struct13

Methods

(==) :: Handshake13 -> Handshake13 -> Bool

(/=) :: Handshake13 -> Handshake13 -> Bool

contextHookSetCertificateRecv :: Context -> (CertificateChain -> IO ()) -> IO () Source #

data Logging Source #

Hooks for logging

This is called when sending and receiving packets and IO

Constructors

Logging 

Fields

Instances

Instances details
Default Logging Source # 
Instance details

Defined in Network.TLS.Hooks

Methods

def :: Logging

data Header Source #

Constructors

Header ProtocolType Version Word16 

Instances

Instances details
Show Header Source # 
Instance details

Defined in Network.TLS.Struct

Methods

showsPrec :: Int -> Header -> ShowS

show :: Header -> String

showList :: [Header] -> ShowS

Eq Header Source # 
Instance details

Defined in Network.TLS.Struct

Methods

(==) :: Header -> Header -> Bool

(/=) :: Header -> Header -> Bool

data ProtocolType Source #

Instances

Instances details
Show ProtocolType Source # 
Instance details

Defined in Network.TLS.Struct

Methods

showsPrec :: Int -> ProtocolType -> ShowS

show :: ProtocolType -> String

showList :: [ProtocolType] -> ShowS

Eq ProtocolType Source # 
Instance details

Defined in Network.TLS.Struct

Methods

(==) :: ProtocolType -> ProtocolType -> Bool

(/=) :: ProtocolType -> ProtocolType -> Bool

Errors and exceptions

Errors

data TLSError Source #

TLSError that might be returned through the TLS stack

Constructors

Error_Misc String

mainly for instance of Error

Error_Protocol (String, Bool, AlertDescription) 
Error_Certificate String 
Error_HandshakePolicy String

handshake policy failed.

Error_EOF 
Error_Packet String 
Error_Packet_unexpected String String 
Error_Packet_Parsing String 

Instances

Instances details
Exception TLSError Source # 
Instance details

Defined in Network.TLS.Struct

Methods

toException :: TLSError -> SomeException

fromException :: SomeException -> Maybe TLSError

displayException :: TLSError -> String

Show TLSError Source # 
Instance details

Defined in Network.TLS.Struct

Methods

showsPrec :: Int -> TLSError -> ShowS

show :: TLSError -> String

showList :: [TLSError] -> ShowS

Eq TLSError Source # 
Instance details

Defined in Network.TLS.Struct

Methods

(==) :: TLSError -> TLSError -> Bool

(/=) :: TLSError -> TLSError -> Bool

data KxError Source #

Constructors

RSAError Error 
KxUnsupported 

Instances

Instances details
Show KxError Source # 
Instance details

Defined in Network.TLS.Crypto

Methods

showsPrec :: Int -> KxError -> ShowS

show :: KxError -> String

showList :: [KxError] -> ShowS

Exceptions

data TLSException Source #

TLS Exceptions related to bad user usage or asynchronous errors

Constructors

Terminated Bool String TLSError

Early termination exception with the reason and the error associated

HandshakeFailed TLSError

Handshake failed for the reason attached

ConnectionNotEstablished

Usage error when the connection has not been established and the user is trying to send or receive data

Instances

Instances details
Exception TLSException Source # 
Instance details

Defined in Network.TLS.Struct

Methods

toException :: TLSException -> SomeException

fromException :: SomeException -> Maybe TLSException

displayException :: TLSException -> String

Show TLSException Source # 
Instance details

Defined in Network.TLS.Struct

Methods

showsPrec :: Int -> TLSException -> ShowS

show :: TLSException -> String

showList :: [TLSException] -> ShowS

Eq TLSException Source # 
Instance details

Defined in Network.TLS.Struct

Methods

(==) :: TLSException -> TLSException -> Bool

(/=) :: TLSException -> TLSException -> Bool

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

data PubKey #

Constructors

PubKeyRSA PublicKey 
PubKeyDSA PublicKey 
PubKeyDH (Integer, Integer, Integer, Maybe Integer, ([Word8], Integer)) 
PubKeyEC PubKeyEC 
PubKeyX25519 PublicKey 
PubKeyX448 PublicKey 
PubKeyEd25519 PublicKey 
PubKeyEd448 PublicKey 
PubKeyUnknown OID ByteString 

Instances

Instances details
ASN1Object PubKey 
Instance details

Defined in Data.X509.PublicKey

Methods

toASN1 :: PubKey -> ASN1S

fromASN1 :: [ASN1] -> Either String (PubKey, [ASN1])

Show PubKey 
Instance details

Defined in Data.X509.PublicKey

Methods

showsPrec :: Int -> PubKey -> ShowS

show :: PubKey -> String

showList :: [PubKey] -> ShowS

Eq PubKey 
Instance details

Defined in Data.X509.PublicKey

Methods

(==) :: PubKey -> PubKey -> Bool

(/=) :: PubKey -> PubKey -> Bool

data PrivKey #

Constructors

PrivKeyRSA PrivateKey 
PrivKeyDSA PrivateKey 
PrivKeyEC PrivKeyEC 
PrivKeyX25519 SecretKey 
PrivKeyX448 SecretKey 
PrivKeyEd25519 SecretKey 
PrivKeyEd448 SecretKey 

Instances

Instances details
ASN1Object PrivKey 
Instance details

Defined in Data.X509.PrivateKey

Methods

toASN1 :: PrivKey -> ASN1S

fromASN1 :: [ASN1] -> Either String (PrivKey, [ASN1])

Show PrivKey 
Instance details

Defined in Data.X509.PrivateKey

Methods

showsPrec :: Int -> PrivKey -> ShowS

show :: PrivKey -> String

showList :: [PrivKey] -> ShowS

Eq PrivKey 
Instance details

Defined in Data.X509.PrivateKey

Methods

(==) :: PrivKey -> PrivKey -> Bool

(/=) :: PrivKey -> PrivKey -> Bool

Ciphers & Predefined ciphers

data Bulk Source #

Constructors

Bulk 

Fields

Instances

Instances details
Show Bulk Source # 
Instance details

Defined in Network.TLS.Cipher

Methods

showsPrec :: Int -> Bulk -> ShowS

show :: Bulk -> String

showList :: [Bulk] -> ShowS

Eq Bulk Source # 
Instance details

Defined in Network.TLS.Cipher

Methods

(==) :: Bulk -> Bulk -> Bool

(/=) :: Bulk -> Bulk -> Bool

data BulkDirection Source #

Constructors

BulkEncrypt 
BulkDecrypt 

Instances

Instances details
Show BulkDirection Source # 
Instance details

Defined in Network.TLS.Cipher

Methods

showsPrec :: Int -> BulkDirection -> ShowS

show :: BulkDirection -> String

showList :: [BulkDirection] -> ShowS

Eq BulkDirection Source # 
Instance details

Defined in Network.TLS.Cipher

data BulkState Source #

Instances

Instances details
Show BulkState Source # 
Instance details

Defined in Network.TLS.Cipher

Methods

showsPrec :: Int -> BulkState -> ShowS

show :: BulkState -> String

showList :: [BulkState] -> ShowS

newtype BulkStream Source #

Constructors

BulkStream (ByteString -> (ByteString, BulkStream)) 

type BulkBlock = BulkIV -> ByteString -> (ByteString, BulkIV) Source #

type BulkAEAD = BulkNonce -> ByteString -> BulkAdditionalData -> (ByteString, AuthTag) Source #

data Hash Source #

Constructors

MD5 
SHA1 
SHA224 
SHA256 
SHA384 
SHA512 
SHA1_MD5 

Instances

Instances details
Show Hash Source # 
Instance details

Defined in Network.TLS.Crypto

Methods

showsPrec :: Int -> Hash -> ShowS

show :: Hash -> String

showList :: [Hash] -> ShowS

Eq Hash Source # 
Instance details

Defined in Network.TLS.Crypto

Methods

(==) :: Hash -> Hash -> Bool

(/=) :: Hash -> Hash -> Bool

data Cipher Source #

Cipher algorithm

Instances

Instances details
Show Cipher Source # 
Instance details

Defined in Network.TLS.Cipher

Methods

showsPrec :: Int -> Cipher -> ShowS

show :: Cipher -> String

showList :: [Cipher] -> ShowS

Eq Cipher Source # 
Instance details

Defined in Network.TLS.Cipher

Methods

(==) :: Cipher -> Cipher -> Bool

(/=) :: Cipher -> Cipher -> Bool

type CipherID = Word16 Source #

Cipher identification

type BulkKey = ByteString Source #

type BulkIV = ByteString Source #

type BulkNonce = ByteString Source #

type BulkAdditionalData = ByteString Source #

cipherAllowedForVersion :: Version -> Cipher -> Bool Source #

Check if a specific Cipher is allowed to be used with the version specified

Deprecated

recvData' :: MonadIO m => Context -> m ByteString Source #

Deprecated: use recvData that returns strict bytestring

same as recvData but returns a lazy bytestring.

contextNewOnHandle Source #

Arguments

:: (MonadIO m, TLSParams params) 
=> Handle

Handle of the connection.

-> params

Parameters of the context.

-> m Context 

Deprecated: use contextNew

create a new context on an handle.

contextNewOnSocket Source #

Arguments

:: (MonadIO m, TLSParams params) 
=> Socket

Socket of the connection.

-> params

Parameters of the context.

-> m Context 

Deprecated: use contextNew

create a new context on a socket.

type Bytes = ByteString Source #

Deprecated: Use Data.ByteString.Bytestring instead of Bytes.

data ValidationChecks #

Constructors

ValidationChecks 

Fields

Instances

Instances details
Show ValidationChecks 
Instance details

Defined in Data.X509.Validation

Methods

showsPrec :: Int -> ValidationChecks -> ShowS

show :: ValidationChecks -> String

showList :: [ValidationChecks] -> ShowS

Default ValidationChecks 
Instance details

Defined in Data.X509.Validation

Eq ValidationChecks 
Instance details

Defined in Data.X509.Validation

data ValidationHooks #

Constructors

ValidationHooks 

Fields

Instances

Instances details
Default ValidationHooks 
Instance details

Defined in Data.X509.Validation