Skip to content

Commit 742b9e6

Browse files
committed
check type on X509::Store.verify
throw a TypeError if the argument is not a OpenSSL::X509::Certificate fixes #69 Sponsored by Lookout Inc.
1 parent ad93636 commit 742b9e6

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,16 @@ public IRubyObject initialize(final ThreadContext context, final IRubyObject[] a
114114
if ( args.length > 2) chain = args[2];
115115
}
116116

117-
final X509AuxCertificate _cert = cert.isNil() ? null : ((X509Cert) cert).getAuxCert();
117+
final X509AuxCertificate _cert;
118+
if (cert.isNil()) {
119+
_cert = null;
120+
}
121+
else {
122+
if (! (cert instanceof X509Cert)) {
123+
throw getRuntime().newTypeError(cert, "OpenSSL::X509::Certificate");
124+
}
125+
_cert = ((X509Cert) cert).getAuxCert();
126+
}
118127
final List<X509AuxCertificate> _chain;
119128
if ( ! chain.isNil() ) {
120129
@SuppressWarnings("unchecked")

src/test/ruby/x509/test_x509store.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ def test_add_file_to_store_with_custom_cert_file
5555
assert store.verify( OpenSSL::X509::Certificate.new(File.read(@pem)))
5656
end
5757

58+
def test_verfy_with_wrong_argument
59+
store = OpenSSL::X509::Store.new
60+
assert_raise(TypeError) { store.verify( 'not an cert object' ) }
61+
end
62+
5863
def test_add_cert_concurrently
5964
store = OpenSSL::X509::Store.new
6065
t = []

0 commit comments

Comments
 (0)