Skip to content

Commit

Permalink
Merge 8a56e43 into 7cac411
Browse files Browse the repository at this point in the history
  • Loading branch information
mbyczkowski committed Nov 26, 2019
2 parents 7cac411 + 8a56e43 commit 79bea44
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
16 changes: 10 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@ branches:
- master

before_install:
- gem install bundler
- gem uninstall bundler -a
- gem install bundler -v '~> 1.0' # pin to a 1.x release, otherwise 2.x is installed

bundler_args: --without development

rvm:
- 2.0.0
- 2.1.10
- 2.2.4
- 2.3.0
- 2.4
- 2.5
- 2.6
matrix:
include:
- rvm: jruby-9.0.5.0
- rvm: jruby-9.0
env: JRUBY_OPTS="--debug" # for simplecov
- rvm: jruby-9.1
env: JRUBY_OPTS="--debug" # for simplecov
- rvm: jruby
env: JRUBY_OPTS="--debug" # for simplecov
fast_finish: true
17 changes: 3 additions & 14 deletions lib/rails/auth/x509/filter/java.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
require "java"
require "stringio"

module Rails
module Auth
module X509
module Filter
# Extract OpenSSL::X509::Certificates from Java's sun.security.x509.X509CertImpl
# Extract OpenSSL::X509::Certificates from java.security.cert.Certificate
class Java
def call(certs)
return unless certs
OpenSSL::X509::Certificate.new(extract_der(certs[0])).freeze
end

private

def extract_der(cert)
stringio = StringIO.new
cert.derEncode(stringio.to_outputstream)
stringio.string
return if certs.nil? || certs.empty?
OpenSSL::X509::Certificate.new(certs[0].get_encoded).freeze
end
end
end
Expand Down
5 changes: 3 additions & 2 deletions spec/rails/auth/x509/middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@

let(:java_cert) do
ruby_cert = OpenSSL::X509::Certificate.new(valid_cert_pem)
Java::SunSecurityX509::X509CertImpl.new(ruby_cert.to_der.to_java_bytes)
java_cert_klass = java.security.cert::CertificateFactory.getInstance("X.509")
java_cert_klass.generateCertificate(java.io::ByteArrayInputStream.new(ruby_cert.to_der.to_java_bytes))
end

it "extracts Rails::Auth::Credential::X509 from a Java::SunSecurityX509::X509CertImpl" do
it "extracts Rails::Auth::Credential::X509 from a java.security.cert.Certificate" do
skip "JRuby only" unless defined?(JRUBY_VERSION)

_response, env = middleware.call(request.merge(example_key => [java_cert]))
Expand Down

0 comments on commit 79bea44

Please sign in to comment.