package tls

  1. Overview
  2. Docs
Transport Layer Security purely in OCaml

Install

dune-project
 Dependency

Authors

Maintainers

Sources

tls-2.0.2.tbz
sha256=9ba50fd0cd20c9be1b6c9980f0d71343cc317446db55217eb39937ac4a8cb21a
sha512=c401deb74c8d78f4c729400ef58a5f8a8049fd53d6efa7dfc968c5b2ced167cc2d819228a4778a4b7f257719964d08a50fe94d9cb2985ab38559fbb6940b8767

Description

Transport Layer Security (TLS) is probably the most widely deployed security protocol on the Internet. It provides communication privacy to prevent eavesdropping, tampering, and message forgery. Furthermore, it optionally provides authentication of the involved endpoints. TLS is commonly deployed for securing web services (HTTPS), emails, virtual private networks, and wireless networks.

TLS uses asymmetric cryptography to exchange a symmetric key, and optionally authenticate (using X.509) either or both endpoints. It provides algorithmic agility, which means that the key exchange method, symmetric encryption algorithm, and hash algorithm are negotiated.

Read our Usenix Security 2015 paper.

Tags

org:mirage

Published: 22 Aug 2025

README

TLS - Transport Layer Security purely in OCaml

v2.0.2

Transport Layer Security (TLS) is probably the most widely deployed security protocol on the Internet. It provides communication privacy to prevent eavesdropping, tampering, and message forgery. Furthermore, it optionally provides authentication of the involved endpoints. TLS is commonly deployed for securing web services (HTTPS), emails, virtual private networks, and wireless networks.

TLS uses asymmetric cryptography to exchange a symmetric key, and optionally authenticate (using X.509) either or both endpoints. It provides algorithmic agility, which means that the key exchange method, symmetric encryption algorithm, and hash algorithm are negotiated.

Read our Usenix Security 2015 paper for further details.

Documentation

API documentation

Installation

opam install tls will install this library.

You can also build this locally by conducting the steps:

opam install --deps-only -t . # or a named package instead of `.` - i.e. ./tls-lwt.opam
dune build --profile=release # you can also put a package list here, i.e. tls,tls-lwt -- you can also use `@all` target to compile examples as well

Usage

The core of ocaml-tls (the opam package tls, available in the lib subdirectory) is an library independent of schedulers and does not perform any I/O operations. The library is designed so that a Tls.Engine.state state informs you of when to write and when to feed more data. It does not use mutation and is in a value-passing style (so, read data and state is the input, and data to be sent or presented to the upper layer, and state is the output).

There are therefore ocaml-tls derivations with different schedulers that perform read and write operations. These derivations offer an interface similar to what an SSL socket (like ssl) can offer.

  • lwt: tls-lwt proposes to initiate a TLS flow with Lwt_io.{input,output}_channel from a Unix socket. It can also propose an abstract type Tls_lwt.Unix.t (which can be created from a Unix socket) associated with a Tls_lwt.Unix interface similar to a Unix socket.
  • miou: tls-miou-unix proposes a TLS flow via an abstract type Tls_miou_unix.t and an interface similar to a Unix socket from a Miou_unix.file_descr socket.
  • MirageOS: tls-mirage proposes a composition of a Mirage_flow.S module to obtain a new Mirage_flow.S (corresponding to the TLS layer) which uses the lwt scheduler.
  • eio: tls-eio proposes the creation of an eio flow from another eio flow.
  • async: tls-async proposes a TLS flow via Async.{Reader,Writer}.t from a Async.Socket.

Depending on the scheduler you choose, you should choose one of these ocaml-tls derivations, distributed in the mentioned opam packages (tls-lwt, tls-mirage, tls-eio, tls-async). Each one takes advantage of what the scheduler used has to offer.

Composability

ocaml-tls can also be used as it is in order to be able to compose with other protocols without choosing a scheduler. This is the case, for example, with sendmail.starttls, which composes the SMTP and TLS protocols. The user can also be more selective about the use of certificates involved in a TLS connection, as albatross can offer in its transactions between clients and the server.

When seen as OCaml values, the critical elements that enable instantiation of a TLS connection can be very finely controlled.

Portability

ocaml-tls is currently used for MirageOS unikernels, which makes it portable and available on many systems (even the most restricted ones such as Solo5 as long as OCaml is available on them.

Dependencies (14)

  1. digestif >= "1.2.0"
  2. ohex >= "0.2.0"
  3. ipaddr
  4. logs
  5. kdf >= "1.0.0"
  6. fmt >= "0.8.7"
  7. domain-name >= "0.3.0"
  8. x509 >= "1.0.0"
  9. mirage-crypto-rng >= "1.2.0"
  10. mirage-crypto-pk >= "1.0.0"
  11. mirage-crypto-ec >= "1.0.0"
  12. mirage-crypto >= "1.1.0"
  13. dune >= "3.0"
  14. ocaml >= "4.13.0"

Dev Dependencies (3)

  1. cmdliner with-test & >= "1.3.0"
  2. alcotest with-test
  3. ounit2 with-test & >= "2.2.0"

Used by (26)

  1. albatross >= "2.3.0"
  2. anthropic
  3. capnp-rpc-net = "1.2.4"
  4. caqti >= "2.1.2"
  5. caqti-mirage >= "2.1.2"
  6. caqti-tls >= "2.1.2"
  7. conduit-mirage >= "7.1.0"
  8. dns-resolver >= "9.1.0"
  9. git-mirage >= "3.17.0"
  10. git-net
  11. git-paf >= "3.17.0"
  12. git-unix >= "3.17.0"
  13. http-lwt-client >= "0.3.2"
  14. http-mirage-client >= "0.0.8"
  15. ldp_tls >= "0.3.0"
  16. letters >= "0.4.0"
  17. paf >= "0.7.0"
  18. sendmail >= "0.9.0"
  19. sendmail-lwt >= "0.9.0"
  20. sendmail-mirage
  21. tls-async >= "2.0.2"
  22. tls-eio >= "2.0.2"
  23. tls-liquidsoap
  24. tls-lwt >= "2.0.2"
  25. tls-miou-unix >= "2.0.2"
  26. tls-mirage >= "2.0.2"

Conflicts (1)

  1. result < "1.5"
OCaml

Innovation. Community. Security.