|
27 | 27 | ***** END LICENSE BLOCK *****/ |
28 | 28 | package org.jruby.ext.openssl.x509store; |
29 | 29 |
|
30 | | -import org.jruby.ext.openssl.OpenSSL; |
31 | | -import org.jruby.ext.openssl.util.Cache; |
32 | | -import static org.jruby.ext.openssl.x509store.X509Utils.X509_CERT_DIR; |
33 | | -import static org.jruby.ext.openssl.x509store.X509Utils.X509_FILETYPE_ASN1; |
34 | | -import static org.jruby.ext.openssl.x509store.X509Utils.X509_FILETYPE_DEFAULT; |
35 | | -import static org.jruby.ext.openssl.x509store.X509Utils.X509_FILETYPE_PEM; |
36 | | -import static org.jruby.ext.openssl.x509store.X509Utils.X509_LU_CRL; |
37 | | -import static org.jruby.ext.openssl.x509store.X509Utils.X509_LU_FAIL; |
38 | | -import static org.jruby.ext.openssl.x509store.X509Utils.X509_LU_X509; |
39 | | -import static org.jruby.ext.openssl.x509store.X509Utils.X509_L_ADD_DIR; |
40 | | -import static org.jruby.ext.openssl.x509store.X509Utils.X509_L_FILE_LOAD; |
41 | | -import static org.jruby.ext.openssl.x509store.X509Utils.X509_R_BAD_X509_FILETYPE; |
42 | | -import static org.jruby.ext.openssl.x509store.X509Utils.X509_R_INVALID_DIRECTORY; |
43 | | -import static org.jruby.ext.openssl.x509store.X509Utils.X509_R_LOADING_CERT_DIR; |
44 | | -import static org.jruby.ext.openssl.x509store.X509Utils.X509_R_LOADING_DEFAULTS; |
45 | | -import static org.jruby.ext.openssl.x509store.X509Utils.X509_R_WRONG_LOOKUP_TYPE; |
46 | | -import static org.jruby.ext.openssl.x509store.X509Utils.getDefaultCertificateDirectoryEnvironment; |
47 | | -import static org.jruby.ext.openssl.x509store.X509Utils.getDefaultCertificateFileEnvironment; |
48 | | - |
49 | | -import java.io.BufferedInputStream; |
50 | 30 | import java.io.BufferedReader; |
51 | 31 | import java.io.File; |
52 | 32 | import java.io.FileInputStream; |
53 | 33 | import java.io.IOException; |
54 | 34 | import java.io.InputStream; |
55 | 35 | import java.io.InputStreamReader; |
56 | | -import java.io.Reader; |
57 | 36 | import java.math.BigInteger; |
58 | 37 | import java.security.GeneralSecurityException; |
59 | 38 | import java.security.KeyStore; |
|
67 | 46 | import java.util.Iterator; |
68 | 47 |
|
69 | 48 | import org.jruby.Ruby; |
70 | | -import org.jruby.RubyHash; |
| 49 | +import org.jruby.ext.openssl.OpenSSL; |
71 | 50 | import org.jruby.ext.openssl.SecurityHelper; |
| 51 | +import org.jruby.ext.openssl.util.Cache; |
72 | 52 | import org.jruby.util.JRubyFile; |
73 | 53 | import org.jruby.util.SafePropertyAccessor; |
74 | | -import org.jruby.util.io.ChannelDescriptor; |
75 | | -import org.jruby.util.io.ChannelStream; |
76 | | -import org.jruby.util.io.FileExistsException; |
77 | | -import org.jruby.util.io.InvalidValueException; |
78 | | -import org.jruby.util.io.ModeFlags; |
| 54 | + |
| 55 | +import static org.jruby.ext.openssl.x509store.X509Utils.*; |
79 | 56 |
|
80 | 57 | /** |
81 | 58 | * X509_LOOKUP |
|
84 | 61 | */ |
85 | 62 | public class Lookup { |
86 | 63 |
|
87 | | - boolean init = false; |
88 | 64 | boolean skip = false; |
89 | 65 |
|
90 | 66 | final LookupMethod method; |
@@ -376,37 +352,11 @@ public int loadDefaultJavaCACertsFile(String certsFile) throws IOException, Gene |
376 | 352 | } |
377 | 353 |
|
378 | 354 | private InputStream wrapJRubyNormalizedInputStream(String file) throws IOException { |
379 | | - try { |
380 | | - return JRubyFile.createResource(runtime, file).inputStream(); |
381 | | - } |
382 | | - catch (NoSuchMethodError e) { // JRubyFile.createResource.inputStream (JRuby < 1.7.17) |
383 | | - try { |
384 | | - ChannelDescriptor descriptor = ChannelDescriptor.open(runtime.getCurrentDirectory(), file, new ModeFlags(ModeFlags.RDONLY)); |
385 | | - return ChannelStream.open(runtime, descriptor).newInputStream(); |
386 | | - } |
387 | | - catch (NoSuchMethodError ex) { |
388 | | - File f = new File(file); |
389 | | - if ( ! f.isAbsolute() ) { |
390 | | - f = new File(runtime.getCurrentDirectory(), file); |
391 | | - } |
392 | | - return new BufferedInputStream(new FileInputStream(f)); |
393 | | - } |
394 | | - catch (FileExistsException ex) { |
395 | | - // should not happen because ModeFlag does not contain CREAT. |
396 | | - OpenSSL.debugStackTrace(ex); |
397 | | - throw new IllegalStateException(ex); |
398 | | - } |
399 | | - catch (InvalidValueException ex) { |
400 | | - // should not happen because ModeFlasg does not contain APPEND. |
401 | | - OpenSSL.debugStackTrace(ex); |
402 | | - throw new IllegalStateException(ex); |
403 | | - } |
404 | | - } |
| 355 | + return JRubyFile.createResource(runtime, file).inputStream(); |
405 | 356 | } |
406 | 357 |
|
407 | 358 | private String envEntry(final String key) { |
408 | | - RubyHash env = (RubyHash) runtime.getObject().getConstant("ENV"); |
409 | | - return (String) env.get( runtime.newString(key) ); |
| 359 | + return (String) runtime.getENV().get( runtime.newString(key) ); |
410 | 360 | } |
411 | 361 |
|
412 | 362 | /** |
@@ -679,6 +629,7 @@ else if ( type == X509_LU_CRL ) { |
679 | 629 | buffer.append('.').append(postfix).append(k); |
680 | 630 |
|
681 | 631 | final String path = buffer.toString(); |
| 632 | + |
682 | 633 | if ( ! new File(path).exists() ) break; |
683 | 634 |
|
684 | 635 | if ( type == X509_LU_X509 ) { |
|
0 commit comments