Bug #13718
closedopenssl: Reading PEM/DER from an IO object fails on mswin Ruby
Description
I recently decided to locally build/test mswin based on VS2015/140. The current Ruby Appveyor testing is done using VS2013/120. I did so since using Appveyor on my Ruby fork was wasteful and time consuming, especially if the problem was testing related and didn't require a new build.
My choice of VS was based on what I had installed, and also on the fact that OpenSSL is now testing on Appveyor using only 140 for both master and OpenSSL_1_1_0-stable. FYI, OpenSSL_1_0_2-stable tests against several VS versions.
My mswin build is using a custom OpenSSL 1.1.0f package I built, using a script based on the OpenSSL script and info at Building OpenSSL with Visual Studio. Both the package and Ruby OpenSSL pass all tests. For my MinGW builds/tests, I also build a package using 1.1.0f, and it also passes all tests in both the package and Ruby.
When running test-all, I had silent SEGV failures on the net tests - test_ftp.rb, test_imap.rb, and test_smtp.rb. All three currently use the following code for some tests:
ctx = OpenSSL::SSL::SSLContext.new
ctx.ca_file = CA_FILE
ctx.key = File.open(SERVER_KEY) { |f|
OpenSSL::PKey::RSA.new(f)
}
ctx.cert = File.open(SERVER_CERT) { |f|
OpenSSL::X509::Certificate.new(f)
}
From the docs, both OpenSSL::PKey::RSA.new and OpenSSL::X509::Certificate.new expect a string, but they're being passed a File instance. Also, why create a block when one isn't needed?
Obviously, tests written this way currently pass on Travis, Appveyor (using 120), and all of the MinGW builds I have done.
But, they do not pass using VS2015/140. I could push a PR for changes to the test files, but I thought I'd file an issue first. I added a utils.rb file to remove the repetition, and used the following:
ctx = OpenSSL::SSL::SSLContext.new
ctx.ca_file = CA_FILE
ctx.key = OpenSSL::PKey::RSA.new( File.read(SERVER_KEY) )
ctx.cert = OpenSSL::X509::Certificate.new( File.read(SERVER_CERT) )
Any thoughts on this odd behavior?
Files