Skip to content

Commit 91619ec

Browse files
committed
X509::Store.set_default_paths ignores FileNotFound errors like MRI does
fixes #68 Sponsored by Lookout Inc.
1 parent 742b9e6 commit 91619ec

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/main/java/org/jruby/ext/openssl/x509store/Store.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import static org.jruby.ext.openssl.x509store.X509Utils.X509_R_CERT_ALREADY_IN_HASH_TABLE;
3333

3434
import java.io.FileNotFoundException;
35+
import java.io.IOException;
3536
import java.security.cert.X509Certificate;
3637
import java.util.ArrayList;
3738
import java.util.Arrays;
@@ -372,6 +373,12 @@ public int setDefaultPaths(Ruby runtime) throws Exception {
372373
catch (FileNotFoundException e) {
373374
// set_default_paths ignores FileNotFound
374375
}
376+
catch (IOException e) {
377+
if (!e.getClass().getSimpleName().equals("NotFound")) {
378+
throw e;
379+
}
380+
// set_default_paths ignores FileNotFound
381+
}
375382

376383
lookup = addLookup(runtime, Lookup.hashDirLookup());
377384
//if ( lookup == null ) return 0;
@@ -382,6 +389,12 @@ public int setDefaultPaths(Ruby runtime) throws Exception {
382389
catch (FileNotFoundException e) {
383390
// set_default_paths ignores FileNotFound
384391
}
392+
catch (IOException e) {
393+
if (!e.getClass().getSimpleName().equals("NotFound")) {
394+
throw e;
395+
}
396+
// set_default_paths ignores FileNotFound
397+
}
385398

386399
X509Error.clearErrors();
387400
return 1;

src/test/ruby/x509/test_x509store.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ 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_use_non_existing_cert_file
59+
ENV['SSL_CERT_FILE'] = 'non-existing-file.crt'
60+
store = OpenSSL::X509::Store.new
61+
store.set_default_paths
62+
assert !store.verify(@cert)
63+
end
64+
5865
def test_verfy_with_wrong_argument
5966
store = OpenSSL::X509::Store.new
6067
assert_raise(TypeError) { store.verify( 'not an cert object' ) }

0 commit comments

Comments
 (0)