Skip to content

Software License Dongle for R

R reaches the dongle through a small C layer that R compiles when the package is installed, the way it does for any package from CRAN — so the binding has no dependencies beyond R itself. 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.

install.packages("remotes")
remotes::install_github("AB-KeyNub/KeyNub-SDK", subdir = "bindings/r")Code language: R (r)

Reading a license

library(KeyNubLicDongle)

ctx <- licd_context()
dongle <- licd_open(ctx)                 # first dongle, or licd_open(ctx, serial)
licd_verify_genuine(dongle)              # signals an error unless genuine

license <- licd_with_session(dongle,    # the session closes on every exit path
  licd_record_read(dongle, "license"))

licd_close(dongle)
licd_close(ctx)Code language: R (r)

What you are actually protecting

R sits where MATLAB and Julia sit — statisticians, quantitative analysts, pharmaceutical and engineering groups, often the same organisation. And as with those two, if you sell an R package the valuable part is usually not the code. It is the fitted model, the calibrated parameters, the validated coefficients, a proprietary correlation set: the part that took years of data to build and that a competitor cannot regenerate from your documentation.

That makes the strong pattern easy here, because the thing worth protecting is already data rather than logic:

# Weak -- one deleted line.
if (!licd_is_genuine(dongle)) stop("unlicensed")

# Strong -- the parameters only exist with the dongle present.
coefficients <- unserialize(
  licd_app_decrypt(dongle, sealed_blob_shipped_with_your_package))Code language: R (r)

licd_with_session() closes the session even when an error unwinds through it, so there is no cleanup path to forget. Every failure is a condition with a class of its own (licd_no_device, licd_not_genuine, licd_auth_required, …), so tryCatch() branches on what happened without parsing a message.

Shipping the native library with an R application

The KeyNubLicDongle package has a small C layer that CRAN compiles for Windows and macOS and that R builds with the system compiler on Linux, as for any source package. It loads the SDK’s native library at run time and does not carry it: take keynub_licdongle for the platform from the SDK’s natives/ folder and name it with KEYNUB_LICDONGLE_LIBRARY, or put it on the system search path.

A Shiny application on a customer’s premises, an RStudio add-in or a plain script deployment all take the same package. On Linux, install the udev rule from NATIVES.md once, so that ordinary users may open the device.

Questions R developers ask

Which R versions does the binding support?

R 4.0 and later, on Windows, Linux and macOS; the package is on CRAN.

Can an R package or Shiny app be protected with a hardware dongle?

Yes, when it runs where the dongle is: a workstation, a laboratory server, an on-premises Shiny server. Ship the model, table or coefficients sealed with the dongle and decrypt them when the session starts.

Does a R 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 R 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.

Can a license written from R 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: r/verify_and_read.R. Binding source: bindings/r. 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