Like PHP, Ruby ships as source, so the dongle earns its place when you install on customer hardware rather than hosting yourself.
gem install keynub_licdongleCode language: Bash (bash)
require 'keynub_licdongle'
KeyNubLicDongle::Context.open do |ctx|
dongle = ctx.open # first dongle, or ctx.open(serial)
dongle.verify_genuine! # raises unless genuine
dongle.session do |session| # closed on every exit path
license = session.read_record('license')
end
endCode language: Ruby (ruby)
The block form closes the device when the block exits, including when it exits by raising. The FFI layer is Fiddle, from Ruby’s standard library, so there is no native gem to compile.
And the rule that matters in every language: do not branch on a boolean. Encrypt data your program needs with appEncrypt at build time and decrypt it through the dongle at run time, so removing the check leaves the program with nothing to compute rather than a working unlicensed copy.
No Gem to Build
The FFI layer is Fiddle, which ships in Ruby’s own standard library. Nothing to install, nothing to compile, and no native extension to go stale when a customer upgrades Ruby. For licensing there is a second reason to prefer it: a third-party gem sitting in the load path is a third-party gem somebody can replace with a stub of their own that always answers yes. With Fiddle there is nothing in the load path but Ruby itself.
The cost is that the C signatures live in the binding as data, not checked by a compiler, so each one is held to the C prototype it mirrors. Ruby 3.0 and later, on Windows, Linux and macOS.
Shipping the Native Library with a Ruby Application
The keynub_licdongle gem uses Fiddle from the standard library, so there is no native extension to compile at install time and no ffi gem. It looks for the core library in KEYNUB_LICDONGLE_LIBRARY, then in vendor/ inside the gem, then beside its own lib/ folder, then on the system search path.
For a shipped application, put the platform’s library where the third or fourth step finds it, or set the environment variable from your launcher. 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 Ruby Developers Ask
Which Ruby Versions Does the Binding Support?
Ruby 3.0 and later, on Windows, Linux and macOS, with no gems beyond the standard library.
Does a Ruby 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 Ruby 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 Ruby 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.
How Do I Test the Ruby Integration?
Against a dongle. The samples in the repository run against real hardware; with no dongle attached they print what to do and exit cleanly, which makes them a quick check that the library is found and the device is accessible.
Code
Runnable sample: ruby/verify_and_read.rb. Binding source: bindings/ruby. 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