Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't read OpenSSL::X509::Certificate in der format using jruby9000 for windows #4279

Closed
jacquesdufeu opened this issue Nov 14, 2016 · 1 comment

Comments

@jacquesdufeu
Copy link

jacquesdufeu commented Nov 14, 2016

Environment

  • jruby 9.1.5.0 (2.3.1) 2016-09-07 036ce39 Java HotSpot(TM) 64-Bit Server VM 25.112-b15 on 1.8.0_112-b15 +jit [mswin32-x86_64]
  • OS: windows 7 enterprise SP1

Expected Behavior

Can read the OpenSSL::X509::Certificate previously created using this sample code

`require 'openssl'

name = OpenSSL::X509::Name.parse("CN=example.com/C=EE")
cert = OpenSSL::X509::Certificate.new
cert.version     = 2
cert.serial      = 0
cert.not_before  = Time.now
cert.not_after   = cert.not_before + 1 * 365 * 24 * 60 * 60 # 1 year validity
key = OpenSSL::PKey::RSA.new(2048)
cert.public_key  = key.public_key
cert.subject     = name
cert.issuer = name
cert.sign key, OpenSSL::Digest::SHA1.new
cert_path = "C:/temp/cert.der"
open cert_path, "w" do |io| io.write cert.to_der end

begin
raw = File.read cert_path  # DER- or PEM-encoded
certificate = OpenSSL::X509::Certificate.new raw
puts certificate.inspect
rescue  => exception
puts exception.backtrace
puts exception.inspect
end

Actual Behavior

reading the certificate throws an exception
#<OpenSSL::X509::CertificateError: No message available>

FYI, this sample code works using

  • the same jruby/jdk on linux rh6

  • jruby 1.7.24 on the same OS (windows 7 enterprise SP1)

It also works if you replace
raw = File.read cert_path
with
raw = File.binread cert_path

@jacquesdufeu jacquesdufeu changed the title can't read OpenSSL::X509::Certificate in der format jruby9000 for windows can't read OpenSSL::X509::Certificate in der format using jruby9000 for windows Nov 14, 2016
@kares kares added this to the Invalid or Duplicate milestone Feb 15, 2020
@kares kares added the openssl label Feb 15, 2020
@kares
Copy link
Member

kares commented Feb 15, 2020

jruby -v cert_read.rb 
jruby 9.2.9.0 (2.5.7) 2019-10-30 458ad3e Java HotSpot(TM) 64-Bit Server VM 25.171-b11 on 1.8.0_171-b11 +jit [linux-x86_64]

#<OpenSSL::X509::Certificate:0x5170bcf4 subject=/CN=example.com/C=EE, issuer=/CN=example.com/C=EE, serial=1, not_before=2020-02-15 14:57:45 UTC, not_after=2021-02-14 14:57:45 UTC>

certificate is read just fine on recent JRuby (9.2.9.0 tested)

@kares kares closed this as completed Feb 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants