
Security News
Follow-up and Clarification on Recent Malicious Ruby Gems Campaign
A clarification on our recent research investigating 60 malicious Ruby gems.
Secure random number generation for Ruby using system RNG facilities e.g. /dev/urandom
, getrandom(2)
System/OS-level random number generators like /dev/urandom
and getrandom(2)
provide the best option for generating cryptographically secure random numbers.
Ruby's built-in SecureRandom does not provide this, but instead uses OpenSSL's userspace RNG. This has been a source of vulnerabilities in Ruby, and an open Ruby bug ticket contains much discussion on the issue with no clear path to resolution.
This gem aims to solve the problem.
In cryptography circles, the prevailing advice is to use OS RNG functionality,
namely /dev/urandom
or equivalent calls which use an OS-level CSPRNG to
produce random numbers.
This gem provides an easy-to-install repackaging of the randombytes
functionality from libsodium for the purpose of generating secure random
numbers trustworthy for use in cryptographic contexts, such as generating
cryptographic keys, initialization vectors, or nonces.
The following random number generators are utilized:
Platform | RNG |
---|---|
Linux | getrandom(2) if available, otherwise /dev/urandom |
Windows | RtlGenRandom CryptGenRandom without CryptoAPI deps |
OpenBSD | arc4random(3) with ChaCha20 CSPRNG (not RC4) |
JRuby | NativePRNGNonBlocking on Java 8, otherwise SHA1PRNG |
Others | /dev/urandom |
Sysrandom is tested on the following Ruby implementations:
Add this line to your application's Gemfile:
gem 'sysrandom'
And then execute:
$ bundle
Or install it yourself as:
$ gem install sysrandom
Sysrandom
aims to be API-compatible with Ruby's built-in SecureRandom
class,
but always prefers OS-level RNG wherever it's available:
>> Sysrandom.random_number(42)
=> 15
>> Sysrandom.random_bytes(32)
=> "\xD6J\xB3\xD2\x8B\x7F*9D\xB7\xF9\xEA\xE2\\\xAAH\tV#\xEC\x84\xE3E\r\x97\xB9\b\xFCH\x17\xA0\v"
>> Sysrandom.base64(32)
=> "WXPkxfAuLRpnI6Z4zFb4E+MIenx6w6vKhe01+rMPuIQ="
>> Sysrandom.urlsafe_base64(32)
=> "37rsMfR4X8g7Bb-uDJEekRHnB3r_7nO03cv52ilaWqE="
>> Sysrandom.hex(32)
=> "c950496ce200abf7d18eb1414e9206c6335f971a37d0394114f56439b59831ba"
>> Sysrandom.uuid
=> "391c6f52-8017-4838-9790-131a9b979c63"
Since Sysrandom is SecureRandom-compatible, it can be patched in-place of SecureRandom if you prefer its RNG behavior.
To do this, require sysrandom/securerandom
:
>> SecureRandom
=> SecureRandom
>> require "sysrandom/securerandom"
=> true
>> SecureRandom
=> Sysrandom
>> SecureRandom.hex(32)
=> "d1bbe8c1ab78fc2fe514c5623d913a27ffd2dcdc9e002f3b358bb01a996962f1"
Copyright (c) 2013-2017 Frank Denis, Tony Arcieri. See LICENSE.txt for further details.
FAQs
Unknown package
We found that sysrandom demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.
Security News
ESLint now supports parallel linting with a new --concurrency flag, delivering major speed gains and closing a 10-year-old feature request.
Research
/Security News
A malicious Go module posing as an SSH brute forcer exfiltrates stolen credentials to a Telegram bot controlled by a Russian-speaking threat actor.