streamly-network-tls: TLS connections as Streamly streams

[ bsd3, library, network, streamly ] [ Propose Tags ] [ Report a vulnerability ]

TLS for Streamly, over the tls package, for clients and for servers: a connection whose received bytes are a stream of arrays, and whose sent bytes go through a function or a fold. A client checks the server against the certificates of the system, or against certificates of your own; a server presents its certificate. It knows nothing of the protocols carried: a connection gives a transport, for streamly-http (HTTPS), for streamly-websockets (secure WebSockets) or for anything else.


[Skip to Readme]

Modules

  • Streamly
    • External
      • Network
        • Streamly.External.Network.TLS

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0
Change log CHANGELOG.md
Dependencies base (>=4.19 && <4.22), bytestring (>=0.12 && <0.13), crypton-x509-store (>=1.10 && <1.11), crypton-x509-system (>=1.10 && <1.11), network (>=3.2 && <3.3), streamly-bytestring (>=0.2.3 && <0.3), streamly-core (>=0.3.3 && <0.4), streamly-network-tcp (>=0.1 && <0.2), tls (>=2.5 && <2.6) [details]
Tested with ghc ==9.8.4 || ==9.10.3 || ==9.12.4
License BSD-3-Clause
Author Xavier Dectot
Maintainer Xavier Dectot <xavier@wheredoibegin.fr>
Uploaded by GdeVolpiano at 2026-11-28T10:15:58Z
Category Network, Streamly
Home page https://github.com/GuillaumedeVolpiano/streamly-network-tls
Source repo head: git clone https://github.com/GuillaumedeVolpiano/streamly-network-tls.git
Distributions
Reverse Dependencies 2 direct, 0 indirect [details]
Downloads 0 total (0 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs not available [build log]
All reported builds failed as of 2026-11-28 [all 1 reports]

Readme for streamly-network-tls-0.1.0.0

[back to package description]

streamly-network-tls

TLS for Streamly, for clients and for servers, over the tls package. A connection gives the bytes received as a stream of arrays and takes the bytes to send through a function or a fold. It knows nothing of the protocol carried.

{-# LANGUAGE OverloadedStrings #-}

import Streamly.Data.Stream (toList)
import Streamly.External.ByteString (toArray)
import Streamly.External.Network.TLS (config, received, send, withConnection)

main :: IO ()
main = withConnection (config "example.org" 443) $ \connection -> do
  send connection (toArray "GET / HTTP/1.0\r\nHost: example.org\r\n\r\n")
  toList (received connection) >>= print . length

Certificates

The server must present a certificate valid for the name asked and signed by a trusted authority: those of the system (SystemCertificates, the default) or those of a file or a directory in PEM (CertificatesFrom), which is how a server with a certificate of its own making is reached. There is no way to skip the check.

Servers

acceptConnection does the handshake of a server on a connection it has accepted, with the certificate and the key read by loadCredentials:

credentials <- loadCredentials "certificate.pem" "key.pem"
(peer, _) <- Network.Socket.accept listener
acceptConnection credentials (Just 30000000) peer $ \connection ->
  fold (write connection) (received connection)

HTTPS and secure WebSockets

streamly-http and streamly-websockets take a connection opened by other means, as a Transport: transport gives one from a connection of this library, which depends on neither of them. The packages streamly-http-tls and streamly-websockets-tls put them together; by hand it reads:

import Streamly.External.Network.HTTP (defaultLimits, fetchOver, get)
import Streamly.External.Network.TLS (transport, withConnection)
import Streamly.External.Network.TLS qualified as NT (config)
import Streamly.External.Network.WebSocket (Message (TextMessage), send,
                                            withConnectionOver)
import Streamly.External.Network.WebSocket qualified as WS (config)

page = withConnection (NT.config "example.org" 443) $ \connection ->
  fetchOver defaultLimits (transport connection) (get "example.org" 443 "/")

chat = withConnection (NT.config "example.org" 443) $ \connection ->
  withConnectionOver (transport connection) (WS.config "example.org" 443 "/chat") $ \socket ->
    send socket (TextMessage "hello")

Building

To build against a copy of streamly-network-tcp checked out next to this repository, pass --project-file=cabal.project.siblings.

Limits of this version

  • The connection and its handshake are limited in time (connectTimeout, thirty seconds by default); once open, nothing limits the waits.
  • A server proves its name with a certificate and its key (loadCredentials, acceptConnection); it does not ask clients for certificates.
  • No client certificate, no session resumption, no choice of protocol versions or ciphers: the defaults of the tls package.
  • No application protocol negotiation (ALPN).