Skip to content

Software License Dongle for Ruby

Like PHP, Ruby ships as source, so the dongle earns its place when you install on customer hardware rather than hosting yourself.

RubyGems version badge

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 genuinely 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.

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