JRuby-OpenSSL is an extension gem for
JRuby that emulates the Ruby OpenSSL native library.
Under the hood it uses the Bouncy Castle Crypto APIs.
All jruby-openssl gem releases include the Bouncy Castle library (BC Provider, BC JSSE and PKIX/CMS/EAC/PKCS/OCSP/TSP/OPENSSL jars), usually the latest available version.
Please report bugs and incompatibilities (preferably with test-cases) to either the JRuby mailing list or the bug tracker.
Java compatibility is expected to be the same as with supported JRuby versions.
Check latest jruby-openssl gem spec's jar requirements for (BC) compatibility.
require 'openssl'
JOpenSSL::VERSIONFor older versions of the gem compatibility wasn't reported:
| JRuby-OpenSSL | JRuby compat | JVM compat | supported BC |
|---|---|---|---|
| ~>0.12.x | 9.1.x-9.3.x | Java 8-15 | 1.65-1.68 |
| ~>0.13.x | 9.1.x-9.4.x | Java 8-17 | 1.68-1.69 |
| ~>0.14.x | 9.1.x-9.4.x | Java 8-21 | 1.71-1.74 |
| ~>0.15.x | 9.2.x-10.0.x | Java 8-25 | 1.78-1.83 |
| ~>0.16.x | 9.3.x-10.1.x | Java 8-25 | 1.83-1.86 |
| ~>0.19.x | 9.2.x-10.1.x | Java 8-25 | 1.80-1.87 |
Upgrading Bouncy Castle libraries to 1.87 resolves several security issues (including
unbounded PKCS#12 MAC iteration counts, quadratic X500Name comparison and stricter
RFC 3161 timestamp validation), and introduces a few behavioral changes to be aware of:
- Stricter RFC 3161 timestamp validation (
OpenSSL::Timestamp):OpenSSL::Timestamp::Response.newrejects tokens whose CMSsigning-timeattribute disagrees withTSTInfo.genTime(beyond tokenaccuracy+ 1 minute). Tokens generated on BC1.87alignsigning-timewithgenTimeautomatically, previously persisted tokens created on BC<= 1.86(with a customfactory.gen_time) will require:-J-Dorg.bouncycastle.tsp.allow_inconsistent_signing_time=trueOpenSSL::Timestamp::Response#verifyrejectsMD5message imprints by default. If you must verify MD5 timestamps, override the allowed digest list via:-J-Dorg.bouncycastle.tsp.allowed_imprint_algorithms=MD5,SHA-1,SHA-256,SHA-384,SHA-512
- Bounded legacy PBE / PKCS#12 MAC iteration counts (
OpenSSL::PKCS12): Classic PKCS#12 MAC and PBES1 PBE derivation now honororg.bouncycastle.pbe.max_iteration_count(default10000000, matching PBKDF2). - Stricter ASN.1, date, and Base64 decoding:
UTCTimeandGeneralizedTimenow reject impossible calendar dates (such as Feb 30) unless:-J-Dorg.bouncycastle.asn1.allow_non_der_time=trueis set; ASN.1SEQUENCEdecoders reject duplicate/out-of-order optional fields and trailing elements; andBase64decoding rejects truncated 1-byte trailing blocks in malformed PEM inputs.
JRuby-OpenSSL is an essential part of JRuby, please report security vulnerabilities to
security@jruby.org as detailed on JRuby's security page or using GitHub.
Please note that most OpenSSL vulnerabilities do not affect JRuby since it's not using any of OpenSSL's C code, only Ruby parts (*.rb) are the same as in MRI's OpenSSL library.
Most runtime knobs are Java system properties.
Under JRuby you pass them as -J-D... flags, e.g. JRUBY_OPTS='-J-Djruby.openssl.debug=true'.
| Property | Default | Effect |
|---|---|---|
jruby.openssl.load.jars |
true |
If set to false, lib/jopenssl/load.rb skips auto-loading the bundled BouncyCastle jars - handy when the BC jars are on the JVM classpath. |
jruby.openssl.debug |
false |
Turns on internal debug logging and stack traces from the Java extension, has the same effect as setting OpenSSL.debug = true at runtime. |
jruby.openssl.warn |
follows JRuby's warning mode (runtime.warningsEnabled()) |
Enables or disables warnings from the extension, set false to stay quiet regardless of -w. |
jruby.openssl.log.logger |
default stdout/stderr logger | Selects the internal logger implementation, set to JUL to route logs through java.util.logging. |
jruby.openssl.log.silence |
true |
Silences a few noisy BC / BC-JSSE loggers by default, set false to leave their levels untouched. |
jruby.openssl.provider.ssl |
BCJSSE |
Selects the SSL provider. BCJSSE, BC, or true all mean BC-JSSE, an empty string or false falls back to the platform JSSE provider. |
jruby.openssl.ssl.error_wait_nonblock.backtrace |
falls back to jruby.errno.backtrace (which defaults to false) |
Whether SSLErrorWaitReadable / SSLErrorWaitWritable carry backtraces. |
jruby.openssl.x509.lookup.cache |
disabled | Caching for X.509 lookup results. true turns on a soft cache; an integer such as 8 gives a bounded strong/soft cache of that size, unset or false disables it. |
The underlying Bouncy Castle and BCJSSE providers also honor Java system properties (-J-D...) that can be used to adjust strictness, security limits, or legacy interoperability:
| Property | Default | Effect |
|---|---|---|
jdk.tls.namedGroups |
includes X25519MLKEM768 (BC 1.87+) |
Comma-separated list of TLS named groups to offer (e.g. x25519,secp256r1,secp384r1,secp521r1 to omit hybrid PQC groups). |
org.bouncycastle.jsse.client.earlyKeyShares |
hybrid + classical share (BC 1.87+) | Comma-separated named groups for which a TLS 1.3 client sends key shares in its first ClientHello (e.g. x25519 to keep ClientHello compact). |
org.bouncycastle.jsse.hostname_check_cn_fallback |
false |
When true, allows BCJSSE hostname verification to fall back to subject CN when a server certificate has no SAN dNSName entries. |
org.bouncycastle.jsse.useNamedGroupsOrder |
false |
When true, BCJSSE TLS 1.3 servers prefer their own named-group order over the client's. |
org.bouncycastle.tsp.allow_inconsistent_signing_time |
false |
When true, OpenSSL::Timestamp::Response.new accepts tokens whose CMS signing-time attribute disagrees with TSTInfo.genTime (BC 1.87+). |
org.bouncycastle.tsp.allowed_imprint_algorithms |
TSPAlgorithms.ALLOWED (no MD5) |
Comma-separated digest names or OIDs accepted for RFC 3161 message imprints in OpenSSL::Timestamp::Response#verify (BC 1.87+). |
org.bouncycastle.pbe.max_iteration_count |
10000000 |
Maximum PBE / PBKDF2 / PKCS#12 MAC iteration count accepted on read (applies to legacy PBES1 and PKCS#12 PBE as well in BC 1.87+). |
org.bouncycastle.pbe.max_scrypt_memory |
1073741824 (1 GiB) |
Maximum scrypt working memory (in bytes) allowed when decrypting PBES2-protected PKCS#8 / PEM private keys. |
org.bouncycastle.asn1.allow_non_der_time |
unset (lenient write / strict read) | Set true to accept impossible calendar dates (e.g. Feb 30) in UTCTime / GeneralizedTime on read (BC 1.87+); set false to enforce strict DER on write. |
org.bouncycastle.asn1.allow_zoneless_utctime |
false |
When true, allows parsing zone-less 12-digit UTCTime values (YYMMDDHHMMSS) as GMT (rejected by default since BC 1.85). |
org.bouncycastle.asn1.allow_wrong_oid_enc |
false |
When true, allows reading non-canonical / malformed ASN.1 OBJECT IDENTIFIER encodings. |
org.bouncycastle.asn1.max_cons_depth |
64 |
Maximum nesting depth of constructed ASN.1 objects accepted during decoding. |
org.bouncycastle.x509.allow_empty_issuer_cert |
false |
When true, allows parsing X.509 certificates with an empty issuer DN. |
org.bouncycastle.x509.allow_lenient_rfc822_name |
false |
When true, restores lenient rfc822Name parsing during X.509 name-constraint checks. |
org.bouncycastle.rsa.max_size / dh.max_size / dsa.max_size |
16384 |
Maximum key/prime size in bits accepted when importing RSA, DH, or DSA keys (org.bouncycastle.{rsa,dh,dsa}.max_size). |
org.bouncycastle.pkcs1.strict_digestinfo |
false |
When true, rejects RSA PKCS#1 v1.5 signatures whose DigestInfo omits the RFC 8017 NULL parameter. |
org.bouncycastle.gcm.allow_short_tags |
false |
When true, allows AES-GCM GCMParameters tag lengths down to 32 bits (4 octets) instead of requiring 96-128 bits. |
| Variable | Default | Effect |
|---|---|---|
SSL_CERT_FILE |
platform / packaged default CA file | Overrides the default certificate bundle used for X.509 default-path loading, .crt, .cer, or .pem are read as a PEM bundle, otherwise treated as a Java CA store path. |
SSL_CERT_DIR |
platform / packaged default CA directory | Overrides the default certificate directory list for X.509 default-path loading, separate multiple directories with the platform path separator. |
OPENSSL_ALLOW_PROXY_CERTS |
unset / disabled | When set to anything other than false, proxy certificates are allowed during certificate chain validation. |
OpenSSL.debug = truegives you the same internal debug logging as-Djruby.openssl.debug=true- when
jruby.openssl.warnis unset, JRuby's own warning mode (ruby -w) decides whether warnings show OpenSSL::Configcan look up variables from the process environment through theENVsection, matching the upstream Ruby OpenSSL config parser
JRuby-OpenSSL aims to be a source-compatible drop-in for MRI's openssl - same Ruby API and
same require 'openssl'. But there are limitations on the JVM (with JCE and JSSE) as well as
Bouncy Castle libraries, so some entry points are unavailable, behave differently, or are no-ops.
Engine
OpenSSL::Engineis not implemented - there is no hardware/engine layer,OpenSSL::EngineraisesNameError(uninitialized constant)
SSL / TLS (backed by JSSE)
SSLSocket#stateand NPN (#npn_protocol) are unimplemented and returnnil- use ALPN insteadSSLSocket#close_writecloses both TLS directions even on TLS 1.3; reading a peer response afterward is unsupported, use message lengths or delimiters to frame requests instead of TLS EOF NOTE: that you can enforce the half-close when using the JDK built-in SunJSSE provider- Forced session resumption (
SSLSocket#session=) is best-effort and only fully works with the BouncyCastle JSSE provider;session_reused?may returnnil("can't decide") SSL::Session#id=/#time=are no-opsSSL::Session.newon a non-socket raisesNotImplementedError- Hostname /
subjectAltNamematching runs over Java's certificate parsing and can differ from MRI'sGeneralNamehandling in edge cases
Cipher (JCE / Bouncy Castle)
- The available cipher set is provider-dependent (what JCE/BC offer on your JVM), not the fixed libcrypto list (some OpenSSL ciphers may be missing or vary by JDK)
- CFB1 mode (
*-cfb1) is excluded (doesn't match OpenSSL under BC) - AEAD is limited to what JCE exposes;
iv_len=on a non-AEAD cipher raises
PKey (EC / DH / EdDSA)
- EC is limited to prime curves (
:GFp); binary-field curves (:GF2m) fail EC::Point#mulwith array arguments and encrypted EC private-key export are not implementedDH#set_pqgignores theqparameter (and warns when it is non-nil)- EdDSA (
Ed25519/Ed448) rejects digest arguments
X509
- multi-valued RDNs (the
+separator in a DN string) are not supported and raiseX509::NameError - few
authorityKeyIdentifierextension configurations are unsupported
Random
- randomness comes from the JVM's
SecureRandom; the EGD and seed-file APIs (Random.egd,egd_bytes,load_random_file,write_random_file) are no-ops
BN
BN#get_flagsalways returns zero;BN#set_flags(0)is a no-op; the OpenSSL constant-time mode (BN::CONSTTIME) is not supported
Other
OpenSSL.fips_mode = trueraisesNotImplementedErrorunless the separate FIPS variant gem is installed- some rarely-used entry points are no-ops (
OpenSSL.check_func,deprecated_warning_flag) andOPENSSL_NO_SOCKisnilrather than a boolean - a few PKCS7 content types can't be reconstructed purely from ASN.1 (may surface when parsing some S/MIME structures)
Hitting something not listed here that MRI's OpenSSL supports? Please report it on the bug tracker, ideally with a test case.
A FIPS 140-3 build of jruby-openssl is available as a separate gem. It's the very same library but uses the NIST-validated BC FIPS module (BC-FJA) instead of regular Bouncy Castle, for deployments that need a validated cryptographic module. Ships separately under GPL 3.0, with commercial licensing available - see the FIPS variant wiki page for details.
NOTE: unlike C OpenSSL, OpenSSL.fips_mode cannot be changed at runtime, the flag reports
which gem variant is activated (true under the FIPS gem, false otherwise).
(c) 2009-2026 JRuby distributed under EPL 1.0 / GPL 2.0 / LGPL 2.1