package dkim
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=dd5c3c6bcce680880500b47a9488edcc0cacaf18ed649011fe8fcfc307d243a9
sha512=ac6e53cf5ed40cefea5f07db3d7ca3fa9efd502addf86fdc3c549e3c1a3f7f65b2be3f590317de079bee499dfbc04f399621c464783d646acda029960ff2c5d8
Description
A library and a binary to verify and sign an email with the DKIM mechanism described by the RFC 6376
Published: 18 Sep 2024
README
ocaml-dkim
ocaml-dkim
is a pure implementation of DKIM in OCaml. It permits to verify and sign an incoming email. It can be use as a SMTP filter service (verify) or as a SMTP submission service (sign).
Usage
How to install it?
You must have an OPAM environment. Then, ocaml-dkim
can be installed with:
$ opam install dkim
$ opam install dkim-bin
How to use it?
ocaml-dkim
provides 2 binaries, one to verify, the second to sign an email.
$ dkim.verify test/raw/001.mail
[ok]: sendgrid.info
[ok]: github.com
It shows all domains which signed the given email and whether the signature is correct or not (for the last case, it shows you the selector). ocaml-dkim
is able to sign an email from a private RSA key and a specific domain such as:
$ dkim.sign -k private-key.pem --selector admin --hostname x25519.net \
test/raw/001.mail
DKIM-Signature: ...
Rest of the email
It prints the signed email then. The user is able to use a specific RSA private key or it can use a seed used to generate the RSA private key with the fortuna random number generator.
Note about end-of-line characters
ocaml-dkim
was designed to work with an SMTP flow where lines are delimited by \r\n
. In this sense, ocaml-dkim
can work with \n
as the line delimiter (the default behavior for distributed binaries) or \r\n
(see the --newline
argument). Be sure to recognize the end-of-line delimiter of your incoming emails! For instance, if you use binaries with an email which terminates lines by \r\n
, you will get an error.
DNS servers used to verify
The dkim.verify
gives the opportunity to the user to specify the nameserver he/she wants to get DKIM public keys. The user can use DNS or DNS over TLS with values required to verify certificates.
For instance, you can use unicast.uncensoreddns.org:
$ dkim.verify test/raw/001.mail \
--nameserver 'tls:89.233.43.71!cert-fp:sha256:ZGDOiBng2T0tx11GsrQDifAV8hVWFcI8kBfqz4mf9U4='
[ok]: sendgrid.info
[ok]: github.com
Usage on bigger projects
ocaml-dkim
is used by an implementation of an SMTP server available here: ptt
. You can follow a mini tutorial to download/deploy the unikernel which can sign incoming emails here: Deploy an SMTP service (2/3)
The project is also used by a simple client to manipulate emails: blaze
Designs & considerations
ocaml-dkim
was made with the objective to stream the verification. Unlike other implementations, ocaml-dkim only makes one pass to check your email. In this sense, it can have a predictable memory consumption (corresponding to a chunk that will be filled concurrently with the analysis).
The calculation of the signature, as well as the production of the DKIM-Signature
field, also requires only one pass. However, to add the field to the email, you will need to keep the whole email somewhere and add the new field beforehand.
Unikernels compatibility
ocaml-dkim
has been designed so that the core library does not depend on POSIX. Thus, the project can be integrated into a unikernel without difficulties.
ocaml-dkim
has received funding from the Next Generation Internet Initiative (NGI) within the framework of the DAPSI Project.
Dependencies (18)
-
x509
>= "1.0.0"
-
mirage-crypto-pk
>= "1.0.0"
-
mirage-crypto
>= "1.0.0"
-
base64
>= "3.0.0"
- fpath
-
fmt
>= "0.8.7"
- logs
-
cmdliner
>= "1.1.0"
-
dns-client
>= "6.4.0"
- domain-name
- hmap
- base-unix
-
astring
>= "0.8.5"
- ipaddr
-
digestif
>= "0.9.0"
-
mrmime
>= "0.6.1"
-
dune
>= "2.0.0"
-
ocaml
>= "4.08.0"
Dev Dependencies (2)
-
alcotest
with-test
-
mirage-crypto-rng
with-test & >= "1.0.0"
Used by (2)
-
dkim-bin
>= "0.7.0"
-
dkim-mirage
>= "0.7.0"
Conflicts
None