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

Portabilityunknown
Stabilityexperimental
MaintainerVincent Hanquez <vincent@snarc.org>
Safe HaskellNone

Network.TLS

Contents

Description

 

Synopsis

Context configuration

data Params

Constructors

forall s . SessionManager s => Params 

Fields

pConnectVersion :: Version

version to use on client connection.

pAllowedVersions :: [Version]

allowed versions that we can use.

pCiphers :: [Cipher]

all ciphers supported ordered by priority.

pCompressions :: [Compression]

all compression supported ordered by priority.

pHashSignatures :: [HashAndSignatureAlgorithm]

All supported hash/signature algorithms pair for client certificate verification, ordered by decreasing priority.

pUseSecureRenegotiation :: Bool

notify that we want to use secure renegotation

pUseSession :: Bool

generate new session if specified

pCertificates :: [(X509, Maybe PrivateKey)]

the cert chain for this context with the associated keys if any.

pLogging :: Logging

callback for logging

onHandshake :: Measurement -> IO Bool

callback on a beggining of handshake

onCertificatesRecv :: [X509] -> IO CertificateUsage

callback to verify received cert chain.

pSessionManager :: s
 
onSuggestNextProtocols :: IO (Maybe [ByteString])

suggested next protocols accoring to the next protocol negotiation extension.

onNPNServerSuggest :: Maybe ([ByteString] -> IO ByteString)
 
roleParams :: RoleParams
 

Instances

data ClientParams

Constructors

ClientParams 

Fields

clientUseMaxFragmentLength :: Maybe MaxFragmentEnum
 
clientUseServerName :: Maybe HostName
 
clientWantSessionResume :: Maybe (SessionID, SessionData)

try to establish a connection using this session.

onCertificateRequest :: ([CertificateType], Maybe [HashAndSignatureAlgorithm], [DistinguishedName]) -> IO [(X509, Maybe PrivateKey)]

This action is called when the server sends a certificate request. The parameter is the information from the request. The action should select a certificate chain of one of the given certificate types where the last certificate in the chain should be signed by one of the given distinguished names. Each certificate should be signed by the following one, except for the last. At least the first of the certificates in the chain must have a corresponding private key, because that is used for signing the certificate verify message.

Note that is is the responsibility of this action to select a certificate matching one of the requested certificate types. Returning a non-matching one will lead to handshake failure later.

Returning a certificate chain not matching the distinguished names may lead to problems or not, depending whether the server accepts it.

data ServerParams

Constructors

ServerParams 

Fields

serverWantClientCert :: Bool

request a certificate from client.

serverCACertificates :: [X509]

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.

onClientCertificate :: [X509] -> 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.

onUnverifiedClientCert :: IO Bool

This action is called when the client certificate cannot be verified. A Nothing argument indicates a wrong signature, a 'Just e' message signals a crypto error.

onCipherChoosing :: Version -> [Cipher] -> Cipher

callback on server to modify the cipher chosen.

data Measurement

record some data about this connection.

Constructors

Measurement 

Fields

nbHandshakes :: !Word32

number of handshakes on this context

bytesReceived :: !Word32

bytes received since last handshake

bytesSent :: !Word32

bytes sent since last handshake

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

Session

type SessionID = ByteString

A session ID

data SessionData

Session data to resume

class SessionManager a where

A session manager

Methods

sessionResume :: a -> SessionID -> IO (Maybe SessionData)

used on server side to decide whether to resume a client session

sessionEstablish :: a -> SessionID -> SessionData -> IO ()

used when a session is established.

sessionInvalidate :: a -> SessionID -> IO ()

used when a session is invalidated

setSessionManager :: SessionManager s => s -> Params -> Params

Set a new session manager in a parameters structure.

Backend abstraction

data Backend

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.

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

Creating a context

contextNew

Arguments

:: (MonadIO m, CPRG rng) 
=> Backend

Backend abstraction with specific method to interact with the connection type.

-> Params

Parameters of the context.

-> rng

Random number generator associated with this context.

-> m Context 

create a new context using the backend and parameters specified.

contextNewOnHandle

Arguments

:: (MonadIO m, CPRG rng) 
=> Handle

Handle of the connection.

-> Params

Parameters of the context.

-> rng

Random number generator associated with this context.

-> m Context 

create a new context on an handle.

deprecated type aliases

deprecated values

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 extension has been used, this will return get the protocol agreed upon.

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

same as recvData but returns a lazy bytestring.

Crypto Key

data PrivateKey

Constructors

PrivRSA PrivateKey 

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

forall a . CompressionC a => Compression a 

Instances

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

data Hash

Constructors

Hash 

type CipherID = Word16

Cipher identification

type IV = ByteString

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

Constructors

RSAError Error 

Instances

Exceptions

data Terminated

Early termination exception with the reason and the TLS error associated