Skip to content

Software License Dongle for OCaml

OCaml reaches the dongle through the SDK’s flat C API with ctypes-foreign, resolving the functions from the library at run time, so the package is pure OCaml with no C stubs to compile and nothing to link. keynub-licdongle from opam, OCaml 4.08 or later, on Windows, Linux and macOS. For a licensing component that is the right shape: nothing sits in the path of the check that a customer could substitute for something more agreeable.

opam install keynub-licdongle
; and in your dune file:
(libraries keynub-licdongle)Code language: OCaml (ocaml)

Reading a license

open Keynub_licdongle

let license =
  with_dongle (fun d ->                 (* first dongle, or ~serial:"..." *)
    ignore (verify_genuine d);          (* raises unless genuine *)
    with_session d (fun () ->
      read_record d "license"))Code language: OCaml (ocaml)

What you are actually protecting

OCaml software that is sold is usually the kind whose value is in what it knows rather than in its syntax: a static analyser, a verified compiler back end, a pricing or risk engine, a proof tool. The binary is native code, but a check that returns a bool is still one conditional branch in it, and patching one of those is a beginner exercise.

So the strong pattern is the one to reach for: the data the program needs only exists when the dongle is present.

(* Weak: one patched branch. *)
if not (is_genuine d) then exit 1

(* Strong: the parameters only exist with the dongle present. *)
let parameters =
  decode_parameters (with_session d (fun () -> app_decrypt d sealed_blob_shipped_with_your_program))Code language: OCaml (ocaml)

Failures raise Error with the status (No_device, Not_genuine, Auth_required, …), the operation and the library’s detail; is_genuine fails closed. with_dongle and with_session release the dongle and the session on every exit path. The package calls the SDK’s flat companion API, the one designed for foreign function interfaces: integer handles and buffers, no hand-written structure layouts.

Code

Runnable sample: ocaml/verify_and_read.ml. Binding source: bindings/ocaml. Both are Apache-2.0, in the public SDK repository; the prebuilt native libraries are in the repository’s natives/ folder, one per platform.

All supported languages · All industries · Buy a KeyNub · Ask us something