Skip to content

Commit

Permalink
the default cert could be PEM or a java keystore. it should load both…
Browse files Browse the repository at this point in the history
… whatver is used as default.
mkristian committed Aug 19, 2015
1 parent 1b5dbbe commit 1d3ba21
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/jopenssl/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Jopenssl
module Version
VERSION = '0.9.9'
VERSION = '0.9.10'
BOUNCY_CASTLE_VERSION = '1.50'
end
end
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
@@ -205,7 +205,7 @@ static boolean isDebug(final Ruby runtime) {
return getDebug( OpenSSL ) == runtime.getTrue();
}

static void debugStackTrace(final Ruby runtime, final Throwable e) {
public static void debugStackTrace(final Ruby runtime, final Throwable e) {
if ( isDebug(runtime) ) e.printStackTrace(runtime.getOut());
}

22 changes: 22 additions & 0 deletions src/main/java/org/jruby/ext/openssl/x509store/Lookup.java
Original file line number Diff line number Diff line change
@@ -27,6 +27,9 @@
***** END LICENSE BLOCK *****/
package org.jruby.ext.openssl.x509store;


import static org.jruby.ext.openssl.OpenSSL.debugStackTrace;

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;
@@ -239,6 +242,10 @@ else if ( type == X509_FILETYPE_ASN1 ) {
return 0; // NOTE: really?
}
}
catch(IOException e) {
debugStackTrace(runtime, e);
return 0;
}
finally {
if ( reader != null ) {
try { reader.close(); } catch (Exception ignored) {}
@@ -285,6 +292,10 @@ else if ( type == X509_FILETYPE_ASN1 ) {
return 0; // NOTE: really?
}
}
catch(IOException e) {
debugStackTrace(runtime, e);
return 0;
}
finally {
if ( reader != null ) {
try { reader.close(); } catch (Exception ignored) {}
@@ -345,6 +356,10 @@ else if ( cert instanceof CRL ) {
}
return count;
}
catch(IOException e) {
debugStackTrace(runtime, e);
return 0;
}
finally {
if ( reader != null ) {
try { reader.close(); } catch (Exception ignored) {}
@@ -367,6 +382,9 @@ public int loadDefaultJavaCACertsFile() throws IOException, GeneralSecurityExcep
count++;
}
}
catch(IOException e) {
return 0;
}
finally {
try { fin.close(); } catch (Exception ignored) {}
}
@@ -522,6 +540,10 @@ public int call(final Lookup ctx, final Integer cmd, final String argp, final Nu
ok = ctx.loadCertificateOrCRLFile(file, X509_FILETYPE_PEM) != 0 ? 1 : 0;
} else {
ok = (ctx.loadDefaultJavaCACertsFile() != 0) ? 1: 0;
// it could be a PEM file
if (ok == 0) {
ok = ctx.loadCertificateOrCRLFile(file, X509_FILETYPE_PEM) != 0 ? 1 : 0;
}
}
if (ok == 0) {
X509Error.addError(X509_R_LOADING_DEFAULTS);

9 comments on commit 1d3ba21

@kares
Copy link
Member

@kares kares commented on 1d3ba21 Aug 20, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change has consequences such as no longer breaking the flow on exceptions e.g. add_file set_default_paths will no longer throw a StoreError ... wish it at least had some tests included - since I'm not sure if that behavioral change is desired thus am inclined to revert (and possibly do decision logic on a higher front than the lowest level helper) ... could this be worked on for a while before rushing into a release?

@headius
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "fixed" logic obviously has problems. I'm wondering if we should perhaps revert this change and the keystore change until we understand exactly how we should be doing this search.

@kares
Copy link
Member

@kares kares commented on 1d3ba21 Aug 20, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not part of 0.9.9 thus that should be good - 0.9.10 seems only in staging (not yet released as a gem)
what (other) key-store change you mean, related to default paths from #61 (part of 0.9.9) ?

@mkristian
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not able to see any error in set_default_paths on MRI !? example please ! I will see for the add_file part.

but it is OK to revert those patches. yes, I just closed it on sonatype to be able to use it with jruby-1_7 as if it comes from rubygems.org. so 0.9.10 is not released !!! just drop it on sonatype

@kares
Copy link
Member

@kares kares commented on 1d3ba21 Aug 20, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... probably cause there's not enough tests for all these no where ;( - will drop and test another 0.9.10, thx!

pls try to come up with test-cases - also a hint for the debug helpers on OpenSSL there's a reason they're not used outside the "frontend" Ruby classes - this way we get stack-traces always come from the direct caller (we're also avoid potential double-logging), the sub-packages usually do not know much about JRuby's classes - Lookout being (already) an "unfortunate" exception to this since it needs to resolve paths the JRuby-way. I think it's ripe for some refactoring - meaningful/useful tests might show us the path to follow ...

@enebo
Copy link
Member

@enebo enebo commented on 1d3ba21 Aug 20, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are calling the wrong methods on the wrong files but the port of that code has c-style returns. I would argue catching the exceptions is still appropriate OR we change these to be exception throwing vs c-returns. So I think the code needs to change but if we keep c-returns then lets also catch exceptions like this patch does.

@enebo
Copy link
Member

@enebo enebo commented on 1d3ba21 Aug 20, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should qualify my comment a bit more. We should not be trying to load a .pem file as a java keystore (wrong methods on wrong files).

@kares
Copy link
Member

@kares kares commented on 1d3ba21 Aug 20, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@enebo yy ... whole thing seems "hacky" - and that is why we probably better have tests before shipping

@enebo
Copy link
Member

@enebo enebo commented on 1d3ba21 Aug 20, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kares yeah that sounds reasonable to me.

Please sign in to comment.