tls-1.3.11: TLS/SSL protocol native implementation (Server and Client)

LicenseBSD-style
MaintainerVincent Hanquez <vincent@snarc.org>
Stabilityexperimental
Portabilityunknown
Safe HaskellNone
LanguageHaskell98

Network.TLS

Contents

Description

 

Synopsis

Context configuration

data ClientParams #

Constructors

ClientParams 

Fields

data ServerParams #

Constructors

ServerParams 

Fields

data DebugParams #

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

  • 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

data ClientHooks #

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

Constructors

ClientHooks 

Fields

data ServerHooks #

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

Constructors

ServerHooks 

Fields

data Supported #

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 chosed.

  • supportedCiphers :: [Cipher]

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

  • supportedCompressions :: [Compression]

    supported compressions methods

  • 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 also used to restrict the choice of hash and signature algorithm, 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.

  • 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.

  • 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.

  • supportedSession :: Bool

    Set if we support session.

  • supportedFallbackScsv :: Bool

    Support for fallback SCSV defined in RFC7507. If True, servers reject handshakes which suggest a lower protocol than the highest protocol supported.

  • 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.

data Hooks #

A collection of hooks actions.

Constructors

Hooks 

Fields

Instances

Default Hooks # 

Methods

def :: Hooks #

data Logging #

Hooks for logging

This is called when sending and receiving packets and IO

Constructors

Logging 

Instances

data Measurement #

record some data about this connection.

Constructors

Measurement 

Fields

data CertificateUsage #

Certificate Usage callback possible returns values.

Constructors

CertificateUsageAccept

usage of certificate accepted

CertificateUsageReject CertificateRejectReason

usage of certificate rejected

raw types

data Header #

Instances

Eq Header # 

Methods

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

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

Show Header # 

Session

type SessionID = ByteString #

A session ID

data SessionManager #

A session manager

Constructors

SessionManager 

Fields

Backend abstraction

data Backend #

Connection IO backend

Constructors

Backend 

Fields

Context object

data Context #

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

ctxConnection :: Context -> Backend #

return the backend object associated with this context

class TLSParams a #

Minimal complete definition

getTLSCommonParams, getTLSRole, getCiphers, doHandshake, doHandshakeWith

Creating a context

contextNew #

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.

contextNewOnHandle #

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 #

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.

Information gathering

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

Information about the current context

Credentials

credentialLoadX509 #

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 :: Bytes -> Bytes -> Either String Credential #

similar to credentialLoadX509 but take the certificate and private key from memory instead of from the filesystem.

credentialLoadX509Chain #

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 :: Bytes -> [Bytes] -> Bytes -> Either String Credential #

similar to credentialLoadX509FromMemory but also allow specifying chain certificates.

Initialisation and Termination of context

bye :: MonadIO m => Context -> m () #

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

handshake :: MonadIO m => Context -> m () #

Handshake for a new TLS connection This is to be called at the beginning of a connection, and during renegotiation

Next Protocol Negotiation

getNegotiatedProtocol :: MonadIO m => Context -> m (Maybe ByteString) #

If the Next Protocol Negotiation or ALPN extensions have been used, this will return get the protocol agreed upon.

Server Name Indication

getClientSNI :: MonadIO m => Context -> m (Maybe HostName) #

If the Server Name Indication extension has been used, return the hostname specified by the client.

High level API

sendData :: MonadIO m => Context -> ByteString -> m () #

sendData sends a bunch of data. It will automatically chunk data to acceptable packet size

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

recvData get data out of Data packet, and automatically renegotiate if a Handshake ClientHello is received

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

Deprecated: use recvData that returns strict bytestring

same as recvData but returns a lazy bytestring.

Crypto Key

data PubKey :: * #

Public key types known and used in X.509

Constructors

PubKeyRSA PublicKey

RSA public key

PubKeyDSA PublicKey

DSA public key

PubKeyDH (Integer, Integer, Integer, Maybe Integer, ([Word8], Integer))

DH format with (p,g,q,j,(seed,pgenCounter))

PubKeyEC PubKeyEC

EC public key

PubKeyUnknown OID ByteString

unrecognized format

Instances

data PrivKey :: * #

Private key types known and used in X.509

Constructors

PrivKeyRSA PrivateKey

RSA private key

PrivKeyDSA PrivateKey

DSA private key

PrivKeyEC PrivKeyEC

EC private key

Instances

Compressions & Predefined compressions

class CompressionC a where #

supported compression algorithms need to be part of this class

data Compression #

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

Constructors

CompressionC a => Compression a 

type CompressionID = Word8 #

Compression identification

nullCompression :: Compression #

default null compression

data NullCompression #

This is the default compression which is a NOOP.

member redefined for the class abstraction

compressionID :: Compression -> CompressionID #

return the associated ID for this algorithm

compressionDeflate :: ByteString -> Compression -> (Compression, ByteString) #

deflate (compress) a bytestring using a compression context and return the result along with the new compression context.

compressionInflate :: ByteString -> Compression -> (Compression, ByteString) #

inflate (decompress) a bytestring using a compression context and return the result along the new compression context.

helper

compressionIntersectID :: [Compression] -> [Word8] -> [Compression] #

intersect a list of ids commonly given by the other side with a list of compression the function keeps the list of compression in order, to be able to find quickly the prefered compression.

Ciphers & Predefined ciphers

data Bulk #

Instances

Eq Bulk # 

Methods

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

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

Show Bulk # 

Methods

showsPrec :: Int -> Bulk -> ShowS #

show :: Bulk -> String #

showList :: [Bulk] -> ShowS #

newtype BulkStream #

data Hash #

Constructors

MD5 
SHA1 
SHA224 
SHA256 
SHA384 
SHA512 
SHA1_MD5 

Instances

Eq Hash # 

Methods

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

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

Show Hash # 

Methods

showsPrec :: Int -> Hash -> ShowS #

show :: Hash -> String #

showList :: [Hash] -> ShowS #

type CipherID = Word16 #

Cipher identification

cipherAllowedForVersion :: Version -> Cipher -> Bool #

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

Versions

data Version #

Versions known to TLS

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

Constructors

SSL2 
SSL3 
TLS10 
TLS11 
TLS12 

Errors

data KxError #

Instances

Exceptions

data TLSException #

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

X509 Validation

data ValidationChecks :: * #

A set of checks to activate or parametrize to perform on certificates.

It's recommended to use defaultChecks to create the structure, to better cope with future changes or expansion of the structure.

Constructors

ValidationChecks 

Fields

  • checkTimeValidity :: Bool

    check time validity of every certificate in the chain. the make sure that current time is between each validity bounds in the certificate

  • checkAtTime :: Maybe DateTime

    The time when the validity check happens. When set to Nothing, the current time will be used

  • checkStrictOrdering :: Bool

    Check that no certificate is included that shouldn't be included. unfortunately despite the specification violation, a lots of real world server serves useless and usually old certificates that are not relevant to the certificate sent, in their chain.

  • checkCAConstraints :: Bool

    Check that signing certificate got the CA basic constraint. this is absolutely not recommended to turn it off.

  • checkExhaustive :: Bool

    Check the whole certificate chain without stopping at the first failure. Allow gathering a exhaustive list of failure reasons. if this is turn off, it's absolutely not safe to ignore a failed reason even it doesn't look serious (e.g. Expired) as other more serious checks would not have been performed.

  • checkLeafV3 :: Bool

    Check that the leaf certificate is version 3. If disable, version 2 certificate is authorized in leaf position and key usage cannot be checked.

  • checkLeafKeyUsage :: [ExtKeyUsageFlag]

    Check that the leaf certificate is authorized to be used for certain usage. If set to empty list no check are performed, otherwise all the flags is the list need to exists in the key usage extension. If the extension is not present, the check will pass and behave as if the certificate key is not restricted to any specific usage.

  • checkLeafKeyPurpose :: [ExtKeyUsagePurpose]

    Check that the leaf certificate is authorized to be used for certain purpose. If set to empty list no check are performed, otherwise all the flags is the list need to exists in the extended key usage extension if present. If the extension is not present, then the check will pass and behave as if the certificate is not restricted to any specific purpose.

  • checkFQHN :: Bool

    Check the top certificate names matching the fully qualified hostname (FQHN). it's not recommended to turn this check off, if no other name checks are performed.

data ValidationHooks :: * #

A set of hooks to manipulate the way the verification works.

BEWARE, it's easy to change behavior leading to compromised security.

Constructors

ValidationHooks 

Fields

X509 Validation Cache

data ValidationCache :: * #

All the callbacks needed for querying and adding to the cache.

Constructors

ValidationCache 

Fields

data ValidationCacheResult :: * #

The result of a cache query

Constructors

ValidationCachePass

cache allow this fingerprint to go through

ValidationCacheDenied String

cache denied this fingerprint for further validation

ValidationCacheUnknown

unknown fingerprint in cache

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

create a simple constant cache that list exceptions to the certification validation. Typically this is use to allow self-signed certificates for specific use, with out-of-bounds user checks.

No fingerprints will be added after the instance is created.

The underlying structure for the check is kept as a list, as usually the exception list will be short, but when the list go above a dozen exceptions it's recommended to use another cache mechanism with a faster lookup mechanism (hashtable, map, etc).

Note that only one fingerprint is allowed per ServiceID, for other use, another cache mechanism need to be use.