Skip to content

Commit b5bec3e

Browse files
cprice404kares
authored andcommitted
Fix ClassCastException in X509Store.verify
This commit changes the logic of the `X509StoreContext.initialize` method, to address some test failures that were showing up in `test_x509store.rb`. The failures would occur during calls to the `verify` method of `X509Store`. It seems that the failures were introduced by the addition of the `X509Cert.toJava` method in ecc1a05 . The `toJava` method seems to be implicitly called when iterating over a RubyArray in Java code, and the implementation of that method now returns a BC object rather than the expected JRuby `X509Cert` object. This commit changes the iteration to use the `.eltOk` method to access the underlying objects w/o the implicit call to `toJava`.
1 parent c621fc1 commit b5bec3e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/main/java/org/jruby/ext/openssl/X509StoreContext.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,17 @@ public IRubyObject initialize(final ThreadContext context, final IRubyObject[] a
127127
final List<X509AuxCertificate> _chain;
128128
if ( ! chain.isNil() ) {
129129
@SuppressWarnings("unchecked")
130-
final List<X509Cert> certs = (List<X509Cert>) chain; // RubyArray
130+
final RubyArray certs = (RubyArray) chain;
131131
_chain = new ArrayList<X509AuxCertificate>( certs.size() );
132-
for ( X509Cert x : certs ) _chain.add( x.getAuxCert() );
132+
133+
for (int i = 0; i < certs.size(); i++) {
134+
// NOTE: if we use the normal java syntax for iterating over this
135+
// RubyArray, the `toJava` method of the X509Cert class will be
136+
// implicitly called, and that will return the BC certificate object
137+
// rather than the JRuby one.
138+
X509Cert c = (X509Cert) certs.eltOk(i);
139+
_chain.add(c.getAuxCert());
140+
}
133141
}
134142
else {
135143
_chain = new ArrayList<X509AuxCertificate>(4);

0 commit comments

Comments
 (0)