1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
|
-- |
-- 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 tipical usage is:
--
-- > socket <- ...
-- > ctx <- contextNew socket <params>
-- > handshake ctx
-- > ... (using recvData and sendData)
-- > bye
module Network.TLS (
-- * Basic APIs
Context,
contextNew,
handshake,
sendData,
recvData,
bye,
-- * Exceptions
-- $exceptions
-- * Backend abstraction
HasBackend (..),
Backend (..),
-- * Parameters
-- intentionally hide the internal methods even haddock warns.
TLSParams,
-- ** Client parameters
ClientParams,
defaultParamsClient,
clientServerIdentification,
clientUseServerNameIndication,
clientWantSessionResume,
clientWantSessionResumeList,
clientShared,
clientHooks,
clientSupported,
clientDebug,
clientUseEarlyData,
-- ** Server parameters
ServerParams,
defaultParamsServer,
serverWantClientCert,
serverCACertificates,
serverDHEParams,
serverHooks,
serverShared,
serverSupported,
serverDebug,
serverEarlyDataSize,
serverTicketLifetime,
-- ** Shared
Shared,
defaultShared,
sharedCredentials,
sharedSessionManager,
sharedCAStore,
sharedValidationCache,
sharedHelloExtensions,
sharedLimit,
-- ** Client hooks
ClientHooks,
defaultClientHooks,
OnCertificateRequest,
onCertificateRequest,
OnServerCertificate,
onServerCertificate,
validateClientCertificate,
onSuggestALPN,
onCustomFFDHEGroup,
onServerFinished,
-- ** Server hooks
ServerHooks,
defaultServerHooks,
onClientCertificate,
onUnverifiedClientCert,
onCipherChoosing,
onServerNameIndication,
onNewHandshake,
onALPNClientSuggest,
onEncryptedExtensionsCreating,
Measurement,
nbHandshakes,
bytesReceived,
bytesSent,
-- ** Supported
Supported,
defaultSupported,
supportedVersions,
supportedCiphers,
supportedCompressions,
supportedHashSignatures,
supportedSecureRenegotiation,
supportedClientInitiatedRenegotiation,
supportedExtendedMainSecret,
supportedSession,
supportedFallbackScsv,
supportedEmptyPacket,
supportedGroups,
-- ** Debug parameters
DebugParams,
defaultDebugParams,
debugSeed,
debugPrintSeed,
debugVersionForced,
debugKeyLogger,
-- ** Limit parameters
Limit,
defaultLimit,
limitHandshakeFragment,
limitRecordSize,
-- * Shared parameters
-- ** Credentials
Credentials (..),
Credential,
credentialLoadX509,
credentialLoadX509FromMemory,
credentialLoadX509Chain,
credentialLoadX509ChainFromMemory,
-- ** Session manager
SessionManager,
noSessionManager,
sessionResume,
sessionResumeOnlyOnce,
sessionEstablish,
sessionInvalidate,
sessionUseTicket,
SessionID,
SessionIDorTicket,
Ticket,
-- ** Session data
SessionData,
sessionVersion,
sessionCipher,
sessionCompression,
sessionClientSNI,
sessionSecret,
sessionGroup,
sessionTicketInfo,
sessionALPN,
sessionMaxEarlyDataSize,
sessionFlags,
SessionFlag (..),
TLS13TicketInfo,
is0RTTPossible,
-- ** Validation Cache
ValidationCache (..),
defaultValidationCache,
ValidationCacheQueryCallback,
ValidationCacheAddCallback,
ValidationCacheResult (..),
exceptionValidationCache,
-- * Types
-- ** For 'Supported'
Version (..),
Compression (..),
nullCompression,
HashAndSignatureAlgorithm,
supportedSignatureSchemes,
HashAlgorithm (..),
SignatureAlgorithm (..),
Group (..),
supportedNamedGroups,
EMSMode (..),
-- ** For parameters and hooks
DHParams,
DHPublic,
GroupUsage (..),
CertificateUsage (..),
CertificateRejectReason (..),
CertificateType (..),
CertificateChain (..),
HostName,
MaxFragmentEnum (..),
-- * Advanced APIs
-- ** Backend
ctxBackend,
contextFlush,
contextClose,
-- ** Information gathering
Information,
contextGetInformation,
infoVersion,
infoCipher,
infoCompression,
infoMainSecret,
infoExtendedMainSecret,
infoClientRandom,
infoServerRandom,
infoSupportedGroup,
infoTLS12Resumption,
infoTLS13HandshakeMode,
infoIsEarlyDataAccepted,
ClientRandom,
ServerRandom,
unClientRandom,
unServerRandom,
HandshakeMode13 (..),
getClientCertificateChain,
-- ** Negotiated
getNegotiatedProtocol,
getClientSNI,
-- ** Post-handshake actions
updateKey,
KeyUpdateRequest (..),
requestCertificate,
getTLSUnique,
getTLSExporter,
getTLSServerEndPoint,
getFinished,
getPeerFinished,
-- ** Modifying hooks in context
Hooks,
defaultHooks,
hookRecvHandshake,
hookRecvHandshake13,
hookRecvCertificates,
hookLogging,
contextModifyHooks,
Handshake,
contextHookSetHandshakeRecv,
Handshake13,
contextHookSetHandshake13Recv,
contextHookSetCertificateRecv,
Logging,
defaultLogging,
loggingPacketSent,
loggingPacketRecv,
loggingIOSent,
loggingIORecv,
Header (..),
ProtocolType (..),
contextHookSetLogging,
-- * Errors and exceptions
-- ** Errors
TLSError (..),
KxError (..),
AlertDescription (..),
-- ** Exceptions
TLSException (..),
-- * Raw types
-- ** Compressions class
CompressionC (..),
CompressionID,
-- ** Crypto Key
PubKey (..),
PrivKey (..),
-- ** Ciphers & Predefined ciphers
module Network.TLS.Cipher,
-- * Deprecated
recvData',
Bytes,
ValidationChecks (..),
ValidationHooks (..),
clientUseMaxFragmentLength,
) where
import Network.TLS.Backend (Backend (..), HasBackend (..))
import Network.TLS.Cipher
import Network.TLS.Compression (
Compression (..),
CompressionC (..),
nullCompression,
)
import Network.TLS.Context
import Network.TLS.Core
import Network.TLS.Credentials
import Network.TLS.Crypto (
DHParams,
DHPublic,
Group (..),
KxError (..),
supportedNamedGroups,
)
import Network.TLS.Handshake.State (HandshakeMode13 (..))
import Network.TLS.Hooks
import Network.TLS.Measurement
import Network.TLS.Parameters
import Network.TLS.Session
import qualified Network.TLS.State as S
import Network.TLS.Struct (
AlertDescription (..),
CertificateType (..),
ClientRandom (..),
Handshake,
HashAlgorithm (..),
HashAndSignatureAlgorithm,
Header (..),
ProtocolType (..),
ServerRandom (..),
SignatureAlgorithm (..),
TLSError (..),
TLSException (..),
supportedSignatureSchemes,
)
import Network.TLS.Struct13 (Handshake13)
import Network.TLS.Types
import Network.TLS.X509
import Data.ByteString as B
import Data.X509 (PrivKey (..), PubKey (..))
import Data.X509.Validation hiding (HostName, defaultHooks)
{-# DEPRECATED Bytes "Use Data.ByteString.Bytestring instead of Bytes." #-}
type Bytes = B.ByteString
-- | 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.
getClientCertificateChain :: Context -> IO (Maybe CertificateChain)
getClientCertificateChain ctx = usingState_ ctx S.getClientCertificateChain
-- $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.
|