Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby-openssl
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: d78fa0394af5
Choose a base ref
...
head repository: jruby/jruby-openssl
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 153028d3e4ba
Choose a head ref
  • 4 commits
  • 5 files changed
  • 1 contributor

Commits on May 30, 2018

  1. Copy the full SHA
    777faee View commit details
  2. re-add (2.4) preliminary compat script but load it on 2.3 (JRuby 9.1)

    ... as well - since C openssl is pretty much gem-ified these days
    kares committed May 30, 2018
    Copy the full SHA
    d7968d9 View commit details
  3. Copy the full SHA
    4a94bd1 View commit details
  4. Copy the full SHA
    153028d View commit details
71 changes: 71 additions & 0 deletions lib/jopenssl/_compat23.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# frozen_string_literal: false

module OpenSSL

module PKey

class DH

def set_key(pub_key, priv_key)
self.public_key = pub_key
self.priv_key = priv_key
self
end

def set_pqg(p, q, g)
self.p = p
if respond_to?(:q)
self.q = q
else # TODO self.q = q
OpenSSL.warn "JRuby-OpenSSL does not support setting q param on #{inspect}" if q
end
self.g = g
self
end

end

class DSA

def set_key(pub_key, priv_key)
self.public_key = pub_key
self.priv_key = priv_key
self
end

def set_pqg(p, q, g)
self.p = p
self.q = q
self.g = g
self
end

end

class RSA

def set_key(n, e, d)
self.n = n
self.e = e
self.d = d
self
end

def set_factors(p, q)
self.p = p
self.q = q
self
end

def set_crt_params(dmp1, dmq1, iqmp)
self.dmp1 = dmp1
self.dmq1 = dmq1
self.iqmp = iqmp
self
end

end

end

end
2 changes: 1 addition & 1 deletion lib/jopenssl/load.rb
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@

if RUBY_VERSION > '2.3'
load 'jopenssl23/openssl.rb'
load 'jopenssl24.rb' if RUBY_VERSION >= '2.4'
load 'jopenssl/_compat23.rb'
elsif RUBY_VERSION > '2.2'
load 'jopenssl22/openssl.rb'
elsif RUBY_VERSION > '2.1'
4 changes: 1 addition & 3 deletions lib/openssl/pkcs12.rb
Original file line number Diff line number Diff line change
@@ -28,10 +28,8 @@ def initialize(str = nil, password = '')
@der = str
end

p12_input_stream = java.io.StringBufferInputStream.new(@der)

store = SecurityHelper.getKeyStore("PKCS12")
store.load(p12_input_stream, password.to_java.to_char_array)
store.load(java.io.ByteArrayInputStream.new(@der.to_java_bytes), password.to_java.to_char_array)

aliases = store.aliases
aliases.each do |alias_name|
2 changes: 1 addition & 1 deletion src/main/java/org/jruby/ext/openssl/OpenSSL.java
Original file line number Diff line number Diff line change
@@ -158,7 +158,7 @@ public static IRubyObject Digest(final IRubyObject self, final IRubyObject name)
// OpenSSL::Digest("MD5") -> OpenSSL::Digest::MD5
final Ruby runtime = self.getRuntime();
final RubyClass Digest = runtime.getModule("OpenSSL").getClass("Digest");
return Digest.getConstantAt( name.asString().toString() );
return Digest.getConstantAt( name.asJavaString() );
}

// API "stubs" in JRuby-OpenSSL :
63 changes: 7 additions & 56 deletions src/main/java/org/jruby/ext/openssl/x509store/Lookup.java
Original file line number Diff line number Diff line change
@@ -27,33 +27,12 @@
***** END LICENSE BLOCK *****/
package org.jruby.ext.openssl.x509store;

import org.jruby.ext.openssl.OpenSSL;
import org.jruby.ext.openssl.util.Cache;
import static org.jruby.ext.openssl.x509store.X509Utils.X509_CERT_DIR;
import static org.jruby.ext.openssl.x509store.X509Utils.X509_FILETYPE_ASN1;
import static org.jruby.ext.openssl.x509store.X509Utils.X509_FILETYPE_DEFAULT;
import static org.jruby.ext.openssl.x509store.X509Utils.X509_FILETYPE_PEM;
import static org.jruby.ext.openssl.x509store.X509Utils.X509_LU_CRL;
import static org.jruby.ext.openssl.x509store.X509Utils.X509_LU_FAIL;
import static org.jruby.ext.openssl.x509store.X509Utils.X509_LU_X509;
import static org.jruby.ext.openssl.x509store.X509Utils.X509_L_ADD_DIR;
import static org.jruby.ext.openssl.x509store.X509Utils.X509_L_FILE_LOAD;
import static org.jruby.ext.openssl.x509store.X509Utils.X509_R_BAD_X509_FILETYPE;
import static org.jruby.ext.openssl.x509store.X509Utils.X509_R_INVALID_DIRECTORY;
import static org.jruby.ext.openssl.x509store.X509Utils.X509_R_LOADING_CERT_DIR;
import static org.jruby.ext.openssl.x509store.X509Utils.X509_R_LOADING_DEFAULTS;
import static org.jruby.ext.openssl.x509store.X509Utils.X509_R_WRONG_LOOKUP_TYPE;
import static org.jruby.ext.openssl.x509store.X509Utils.getDefaultCertificateDirectoryEnvironment;
import static org.jruby.ext.openssl.x509store.X509Utils.getDefaultCertificateFileEnvironment;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.math.BigInteger;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
@@ -67,15 +46,13 @@
import java.util.Iterator;

import org.jruby.Ruby;
import org.jruby.RubyHash;
import org.jruby.ext.openssl.OpenSSL;
import org.jruby.ext.openssl.SecurityHelper;
import org.jruby.ext.openssl.util.Cache;
import org.jruby.util.JRubyFile;
import org.jruby.util.SafePropertyAccessor;
import org.jruby.util.io.ChannelDescriptor;
import org.jruby.util.io.ChannelStream;
import org.jruby.util.io.FileExistsException;
import org.jruby.util.io.InvalidValueException;
import org.jruby.util.io.ModeFlags;

import static org.jruby.ext.openssl.x509store.X509Utils.*;

/**
* X509_LOOKUP
@@ -84,7 +61,6 @@
*/
public class Lookup {

boolean init = false;
boolean skip = false;

final LookupMethod method;
@@ -376,37 +352,11 @@ public int loadDefaultJavaCACertsFile(String certsFile) throws IOException, Gene
}

private InputStream wrapJRubyNormalizedInputStream(String file) throws IOException {
try {
return JRubyFile.createResource(runtime, file).inputStream();
}
catch (NoSuchMethodError e) { // JRubyFile.createResource.inputStream (JRuby < 1.7.17)
try {
ChannelDescriptor descriptor = ChannelDescriptor.open(runtime.getCurrentDirectory(), file, new ModeFlags(ModeFlags.RDONLY));
return ChannelStream.open(runtime, descriptor).newInputStream();
}
catch (NoSuchMethodError ex) {
File f = new File(file);
if ( ! f.isAbsolute() ) {
f = new File(runtime.getCurrentDirectory(), file);
}
return new BufferedInputStream(new FileInputStream(f));
}
catch (FileExistsException ex) {
// should not happen because ModeFlag does not contain CREAT.
OpenSSL.debugStackTrace(ex);
throw new IllegalStateException(ex);
}
catch (InvalidValueException ex) {
// should not happen because ModeFlasg does not contain APPEND.
OpenSSL.debugStackTrace(ex);
throw new IllegalStateException(ex);
}
}
return JRubyFile.createResource(runtime, file).inputStream();
}

private String envEntry(final String key) {
RubyHash env = (RubyHash) runtime.getObject().getConstant("ENV");
return (String) env.get( runtime.newString(key) );
return (String) runtime.getENV().get( runtime.newString(key) );
}

/**
@@ -679,6 +629,7 @@ else if ( type == X509_LU_CRL ) {
buffer.append('.').append(postfix).append(k);

final String path = buffer.toString();

if ( ! new File(path).exists() ) break;

if ( type == X509_LU_X509 ) {