D reaches the dongle through the SDK’s flat C API with extern(C) function pointers resolved by name from the native library, which is loaded at run time, so nothing is linked and nothing sits in the path of the check that a customer could substitute for something more agreeable. No dependencies. keynub-licdongle from the DUB registry, D 2.098 or later (ldc or dmd), on Windows, Linux and macOS.
// dub.sdl
dependency "keynub-licdongle" version="~>1.1.1-d"Code language: D (d)
Reading a license
import keynub.licdongle;
auto license = withDongle((ref Dongle d) { // first dongle, or withDongle("serial", ...)
d.verifyGenuine(); // throws unless genuine
return d.withSession(() => // closed on every exit path
d.readRecord("license"));
});Code language: D (d)
What you are actually protecting
D software that is sold is usually the kind whose value is in what it does on a customer’s own machine: a trading engine, a simulation kernel, a game server, a build tool. It ships as a native binary, and a check that returns a bool is still one conditional branch, 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 (!d.isGenuine()) exit(1);
// Strong: the parameters only exist with the dongle present.
auto parameters = d.withSession(() =>
decodeParameters(d.appDecrypt(sealedBlobShippedWithYourProgram)));Code language: D (d)
Every failed call throws LicDongleException with the status (Status.noDevice, Status.notGenuine, Status.authRequired, …), the operation and the library’s detail; isGenuine() fails closed. withDongle and withSession 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.
Shipping the native library with a D application
The keynub-licdongle DUB package resolves the SDK’s flat API by name from the library it opens at run time (dlopen, LoadLibrary), so nothing is linked and there are no dependencies. A shipped executable takes keynub_licdongle_flat for its platform beside it or on the search path, or names it with setLibraryPath or KEYNUB_LICDONGLE_FLAT_LIBRARY.
The prebuilt libraries for every platform are in the SDK repository’s natives/<platform>/ folder, with a SHA-256 manifest: Windows x64, x86 and ARM64, Linux x86_64 and aarch64, and universal macOS binaries for Intel and Apple silicon. On Linux, install the udev rule from NATIVES.md once, so that ordinary users may open the device.
Questions D developers ask
Which D compilers does the binding support?
D 2.098 and later: ldc 1.28 and later and the matching dmd releases, on Windows, Linux and macOS.
Does a D application need administrator rights to talk to the dongle?
No, and no driver either: the dongle is a USB HID device that the operating systems handle with their built-in class drivers. On Linux, install the shipped udev rule once so that ordinary users may open it; without the rule the SDK reports access denied and names the cause in its error detail.
Does a D license check need an internet connection?
No. Verification is a local exchange between your program and the dongle over USB: the SDK checks the dongle’s certificate chain to KeyNub’s root and runs a live challenge-response. There is no activation server and no account, so the check works on air-gapped machines.
Who can read the license records on a dongle?
Anyone holding the dongle: a program opens a session and reads records, and can decrypt data sealed for that dongle. Writing records, erasing them and incrementing counters need your write key. What the dongle guarantees is that none of it is available without the dongle present.
Does it run on ARM: Windows on ARM, Apple silicon, aarch64 Linux?
Yes. The SDK ships native libraries for Windows x64, x86 and ARM64, Linux x86_64 and aarch64, and universal macOS binaries for Intel and Apple silicon.
Can a license written from D be read by a program in another language?
Yes. Every binding drives the same core library and the same dongle, and records and sealed data are language-neutral bytes. Your issuing tool can be written in one language and your product in another.
Code
Runnable sample: d/verify_and_read.d. Binding source: bindings/d. 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