Title: [832] trunk/jopenssl: Bring back 1.4 source compatibility; try to degrade more gracefully when

Diff

Modified: trunk/jopenssl/build.xml (831 => 832)


--- trunk/jopenssl/build.xml	2007-12-12 22:05:25 UTC (rev 831)
+++ trunk/jopenssl/build.xml	2007-12-12 23:01:05 UTC (rev 832)
@@ -9,8 +9,8 @@
   <property name="target.classes.test" value="${target}/test-classes"/>
   <property name="lib.dir" value="lib"/>
   <property name="jruby.jar" value="${jruby.home}/lib/jruby.jar"/>
-  <property name="version.source" value="1.5"/>
-  <property name="version.target" value="1.5"/>
+  <property name="version.source" value="1.4"/>
+  <property name="version.target" value="1.4"/>
 
   <path id="build.classpath">
     <fileset dir="${lib.dir}" includes="*.jar" excludes="jopenssl.jar,jruby.jar"/>

Copied: trunk/jopenssl/lib/bcmail-jdk14-135.jar (from rev 716, trunk/jopenssl/lib/bcmail-jdk14-135.jar)


(Binary files differ)

Deleted: trunk/jopenssl/lib/bcmail-jdk15-137.jar


(Binary files differ)

Copied: trunk/jopenssl/lib/bcprov-jdk14-135.jar (from rev 716, trunk/jopenssl/lib/bcprov-jdk14-135.jar)


(Binary files differ)

Deleted: trunk/jopenssl/lib/bcprov-jdk15-137.jar


(Binary files differ)

Added: trunk/jopenssl/lib/openssl/dummy.rb (0 => 832)


--- trunk/jopenssl/lib/openssl/dummy.rb	                        (rev 0)
+++ trunk/jopenssl/lib/openssl/dummy.rb	2007-12-12 23:01:05 UTC (rev 832)
@@ -0,0 +1,32 @@
+warn "Warning: OpenSSL ASN1/PKey/X509/Netscape/PKCS7 implementation unavailable"
+module OpenSSL
+  module ASN1
+    class ASN1Error < OpenSSLError; end
+    class ASN1Data; end
+    class Primitive; end
+    class Constructive; end
+  end
+  module PKey
+    class PKeyError < OpenSSLError; end
+    class PKey; def initialize(*args); end; end
+    class RSA < PKey; end
+    class DSA < PKey; end
+    class DH < PKey; end
+  end
+  module X509
+    class Name; end
+    class Certificate; end
+    class Extension; end
+    class CRL; end
+    class Revoked; end
+    class Store; end
+    class Request; end
+    class Attribute; end
+  end
+  module Netscape
+    class SPKI; end
+  end
+  module PKCS7
+    class PKCS7; end
+  end
+end
\ No newline at end of file

Added: trunk/jopenssl/lib/openssl/dummyssl.rb (0 => 832)


--- trunk/jopenssl/lib/openssl/dummyssl.rb	                        (rev 0)
+++ trunk/jopenssl/lib/openssl/dummyssl.rb	2007-12-12 23:01:05 UTC (rev 832)
@@ -0,0 +1,12 @@
+warn "Warning: OpenSSL SSL implementation unavailable"
+module OpenSSL
+  module SSL
+    class SSLError < OpenSSLError; end
+    class SSLContext; end
+    class SSLSocket; end
+    VERIFY_NONE = 0
+    VERIFY_PEER = 1
+    VERIFY_FAIL_IF_NO_PEER_CERT = 2
+    VERIFY_CLIENT_ONCE = 4
+  end
+end
\ No newline at end of file

Modified: trunk/jopenssl/src/java/org/jruby/ext/openssl/OpenSSLReal.java (831 => 832)


--- trunk/jopenssl/src/java/org/jruby/ext/openssl/OpenSSLReal.java	2007-12-12 22:05:25 UTC (rev 831)
+++ trunk/jopenssl/src/java/org/jruby/ext/openssl/OpenSSLReal.java	2007-12-12 23:01:05 UTC (rev 832)
@@ -35,17 +35,19 @@
  * @author <a href="" PROTECTED]">Ola Bini</a>
  */
 public class OpenSSLReal {
+
     public static java.security.Provider PROVIDER;
-    
+
     public static void doWithBCProvider(final Runnable toRun) {
         getWithBCProvider(new Callable() {
+
             public Object call() {
                 toRun.run();
                 return null;
             }
         });
     }
- 
+
     public static Object getWithBCProvider(Callable toRun) {
         if (PROVIDER != null) {
             synchronized (java.security.Security.class) {
@@ -64,38 +66,48 @@
     public static void createOpenSSL(Ruby runtime) {
         if (PROVIDER == null) {
             try {
-                PROVIDER = (java.security.Provider)
-                        Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider").newInstance();
+                PROVIDER = (java.security.Provider) Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider").newInstance();
             } catch (Exception exception) {
-                // no bouncy castle available
+            // no bouncy castle available
             }
         }
 
         RubyModule ossl = runtime.getOrCreateModule("OpenSSL");
         RubyClass standardError = runtime.getClass("StandardError");
-        ossl.defineClassUnder("OpenSSLError",standardError,standardError.getAllocator());
+        ossl.defineClassUnder("OpenSSLError", standardError, standardError.getAllocator());
 
-        ASN1.createASN1(runtime, ossl);
+        if (PROVIDER != null) {
+            ASN1.createASN1(runtime, ossl);
+            PKey.createPKey(runtime, ossl);
+            X509.createX509(runtime, ossl);
+            NetscapeSPKI.createNetscapeSPKI(runtime, ossl);
+            PKCS7.createPKCS7(runtime, ossl);
+        } else {
+            runtime.getLoadService().require("openssl/dummy");
+        }
+
         BN.createBN(runtime, ossl);
         Digest.createDigest(runtime, ossl);
         Cipher.createCipher(runtime, ossl);
         Random.createRandom(runtime, ossl);
-        PKey.createPKey(runtime,ossl);
-        HMAC.createHMAC(runtime,ossl);
-        X509.createX509(runtime,ossl);
-        Config.createConfig(runtime,ossl);
-        NetscapeSPKI.createNetscapeSPKI(runtime,ossl);
-        PKCS7.createPKCS7(runtime,ossl);
-        SSL.createSSL(runtime,ossl);
+        HMAC.createHMAC(runtime, ossl);
+        Config.createConfig(runtime, ossl);
 
-        ossl.setConstant("VERSION",runtime.newString("1.0.0"));
-        ossl.setConstant("OPENSSL_VERSION",runtime.newString("OpenSSL 0.9.8b 04 May 2006 (Java fake)"));
-        
         try {
+            SSL.createSSL(runtime, ossl);
+        } catch (Error err) {
+            runtime.getLoadService().require("openssl/dummyssl");
+        }
+
+        ossl.setConstant("VERSION", runtime.newString("1.0.0"));
+        ossl.setConstant("OPENSSL_VERSION", runtime.newString("OpenSSL 0.9.8b 04 May 2006 (Java fake)"));
+
+        try {
             java.security.MessageDigest.getInstance("SHA224", PROVIDER);
-            ossl.setConstant("OPENSSL_VERSION_NUMBER",runtime.newFixnum(9469999));
-        } catch(java.security.NoSuchAlgorithmException e) {
-            ossl.setConstant("OPENSSL_VERSION_NUMBER",runtime.newFixnum(9469952));
+            ossl.setConstant("OPENSSL_VERSION_NUMBER", runtime.newFixnum(9469999));
+        } catch (Exception e) {
+            ossl.setConstant("OPENSSL_VERSION_NUMBER", runtime.newFixnum(9469952));
         }
     }
 }// OpenSSLReal
+

Modified: trunk/jopenssl/src/java/org/jruby/ext/openssl/PKey.java (831 => 832)


--- trunk/jopenssl/src/java/org/jruby/ext/openssl/PKey.java	2007-12-12 22:05:25 UTC (rev 831)
+++ trunk/jopenssl/src/java/org/jruby/ext/openssl/PKey.java	2007-12-12 23:01:05 UTC (rev 832)
@@ -29,7 +29,6 @@
 
 import java.security.InvalidKeyException;
 import java.security.NoSuchAlgorithmException;
-import java.security.NoSuchProviderException;
 import java.security.PrivateKey;
 import java.security.PublicKey;
 import java.security.Signature;

Modified: trunk/jopenssl/src/java/org/jruby/ext/openssl/SSLContext.java (831 => 832)


--- trunk/jopenssl/src/java/org/jruby/ext/openssl/SSLContext.java	2007-12-12 22:05:25 UTC (rev 831)
+++ trunk/jopenssl/src/java/org/jruby/ext/openssl/SSLContext.java	2007-12-12 23:01:05 UTC (rev 832)
@@ -176,7 +176,6 @@
             this.ctt = ctt;
         }
 
-        @Override
         public String chooseEngineClientAlias(String[] keyType, java.security.Principal[] issuers, javax.net.ssl.SSLEngine engine) {
             PKey k = null;
             if(!ctt.callMethod(ctt.getRuntime().getCurrentContext(),"key").isNil()) {
@@ -195,7 +194,6 @@
             return null;
         }
 
-        @Override
         public String chooseEngineServerAlias(String keyType, java.security.Principal[] issuers, javax.net.ssl.SSLEngine engine) {
             PKey k = null;
             if(!ctt.callMethod(ctt.getRuntime().getCurrentContext(),"key").isNil()) {

Modified: trunk/jopenssl/src/java/org/jruby/ext/openssl/X509Name.java (831 => 832)


--- trunk/jopenssl/src/java/org/jruby/ext/openssl/X509Name.java	2007-12-12 22:05:25 UTC (rev 831)
+++ trunk/jopenssl/src/java/org/jruby/ext/openssl/X509Name.java	2007-12-12 23:01:05 UTC (rev 832)
@@ -29,7 +29,6 @@
 
 import java.util.ArrayList;
 import java.util.Enumeration;
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -54,8 +53,10 @@
 import org.jruby.RubyModule;
 import org.jruby.RubyNumeric;
 import org.jruby.RubyObject;
+import org.jruby.RubyObjectAdapter;
 import org.jruby.RubyString;
 import org.jruby.exceptions.RaiseException;
+import org.jruby.javasupport.JavaEmbedUtils;
 import org.jruby.runtime.Block;
 import org.jruby.runtime.CallbackFactory;
 import org.jruby.runtime.ObjectAllocator;
@@ -96,13 +97,14 @@
         cX509Name.setConstant("DEFAULT_OBJECT_TYPE",runtime.newFixnum(DERTags.UTF8_STRING));
 
         RubyHash hash = new RubyHash(runtime, runtime.newFixnum(DERTags.UTF8_STRING));
-        hash.op_aset(runtime.newString("C"),runtime.newFixnum(DERTags.PRINTABLE_STRING));
-        hash.op_aset(runtime.newString("countryName"),runtime.newFixnum(DERTags.PRINTABLE_STRING));
-        hash.op_aset(runtime.newString("serialNumber"),runtime.newFixnum(DERTags.PRINTABLE_STRING));
-        hash.op_aset(runtime.newString("dnQualifier"),runtime.newFixnum(DERTags.PRINTABLE_STRING));
-        hash.op_aset(runtime.newString("DC"),runtime.newFixnum(DERTags.IA5_STRING));
-        hash.op_aset(runtime.newString("domainComponent"),runtime.newFixnum(DERTags.IA5_STRING));
-        hash.op_aset(runtime.newString("emailAddress"),runtime.newFixnum(DERTags.IA5_STRING));
+        RubyObjectAdapter api = JavaEmbedUtils.newObjectAdapter();
+        api.callMethod(hash, "[]=", new IRubyObject[] {runtime.newString("C"), runtime.newFixnum(DERTags.PRINTABLE_STRING)});
+        api.callMethod(hash, "[]=", new IRubyObject[] {runtime.newString("countryName"),runtime.newFixnum(DERTags.PRINTABLE_STRING)});
+        api.callMethod(hash, "[]=", new IRubyObject[] {runtime.newString("serialNumber"),runtime.newFixnum(DERTags.PRINTABLE_STRING)});
+        api.callMethod(hash, "[]=", new IRubyObject[] {runtime.newString("dnQualifier"),runtime.newFixnum(DERTags.PRINTABLE_STRING)});
+        api.callMethod(hash, "[]=", new IRubyObject[] {runtime.newString("DC"),runtime.newFixnum(DERTags.IA5_STRING)});
+        api.callMethod(hash, "[]=", new IRubyObject[] {runtime.newString("domainComponent"),runtime.newFixnum(DERTags.IA5_STRING)});
+        api.callMethod(hash, "[]=", new IRubyObject[] {runtime.newString("emailAddress"),runtime.newFixnum(DERTags.IA5_STRING)});
         cX509Name.setConstant("OBJECT_TYPE_TEMPLATE", hash);
     }
 

Modified: trunk/jopenssl/test/test_openssl.rb (831 => 832)


--- trunk/jopenssl/test/test_openssl.rb	2007-12-12 22:05:25 UTC (rev 831)
+++ trunk/jopenssl/test/test_openssl.rb	2007-12-12 23:01:05 UTC (rev 832)
@@ -1,32 +1,21 @@
 
-run_tests = true
-if RUBY_PLATFORM =~ /java/
-  require 'java'
-  run_tests = false
-  begin
-    java.lang.StringBuilder
-    run_tests = true
-  rescue 
-    nil
-  end
-end
+require 'java' if RUBY_PLATFORM =~ /java/
 begin
-  if run_tests
-    require 'openssl/test_asn1'
-    require 'openssl/test_cipher'
-    require 'openssl/test_digest'
-    require 'openssl/test_hmac'
-    require 'openssl/test_ns_spki'
-    # require 'openssl/test_pair'
-    require 'openssl/test_pkey_rsa'
-    # require 'openssl/test_ssl' # won't work, since kill and pid is used.
-    require 'openssl/test_x509cert'
-    require 'openssl/test_x509crl'
-    require 'openssl/test_x509name'
-    require 'openssl/test_x509ext'
-    require 'openssl/test_x509req'
-    require 'openssl/test_x509store'
-  end
+  require 'openssl/test_asn1'
+  require 'openssl/test_cipher'
+  require 'openssl/test_digest'
+  require 'openssl/test_hmac'
+  require 'openssl/test_ns_spki'
+  # require 'openssl/test_pair'
+  require 'openssl/test_pkey_rsa'
+  # require 'openssl/test_ssl' # won't work, since kill and pid is used.
+  require 'openssl/test_x509cert'
+  require 'openssl/test_x509crl'
+  require 'openssl/test_x509name'
+  require 'openssl/test_x509ext'
+  require 'openssl/test_x509req'
+  require 'openssl/test_x509store'
 rescue Exception => e
   $stderr.puts "Had exception: #{e.inspect}"
+  $stderr.puts(*(e.backtrace))
 end
_______________________________________________
Jruby-extras-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/jruby-extras-devel

Reply via email to