You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2011/10/10 10:08:50 UTC

svn commit: r1180820 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/ssl/ native/include/acr/ native/modules/openssl/ test/org/apache/commons/runtime/

Author: mturk
Date: Mon Oct 10 08:08:49 2011
New Revision: 1180820

URL: http://svn.apache.org/viewvc?rev=1180820&view=rev
Log:
Use the SSL prefix for public classes and axe global password handler. It is oxymoron in threaded environment

Added:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLPasswordCallback.java
      - copied, changed from r1180317, commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/PasswordCallback.java
Removed:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/PasswordCallback.java
Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLCertificate.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLKey.java
    commons/sandbox/runtime/trunk/src/main/native/include/acr/ssl.h
    commons/sandbox/runtime/trunk/src/main/native/modules/openssl/init.c
    commons/sandbox/runtime/trunk/src/main/native/modules/openssl/password.c
    commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestSSL.java
    commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestSSLCert.java

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLCertificate.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLCertificate.java?rev=1180820&r1=1180819&r2=1180820&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLCertificate.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLCertificate.java Mon Oct 10 08:08:49 2011
@@ -60,7 +60,7 @@ public final class SSLCertificate extend
         this.desc = desc;
     }
 
-    public synchronized void load(String file, SSLCertificateFormat format, PasswordCallback cb)
+    public synchronized void load(String file, SSLCertificateFormat format, SSLPasswordCallback cb)
         throws IllegalStateException,
                SSLCannotDecryptException,
                SSLInvalidCertificateException
@@ -108,7 +108,7 @@ public final class SSLCertificate extend
     }
 
     public synchronized void load(byte[] b, int off, int len,
-                                  SSLCertificateFormat format, PasswordCallback cb)
+                                  SSLCertificateFormat format, SSLPasswordCallback cb)
         throws IllegalStateException,
                SSLCannotDecryptException,
                SSLInvalidCertificateException

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLKey.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLKey.java?rev=1180820&r1=1180819&r2=1180820&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLKey.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLKey.java Mon Oct 10 08:08:49 2011
@@ -59,7 +59,7 @@ public final class SSLKey extends SSLObj
         this.desc = desc;
     }
 
-    public synchronized void load(String file, SSLKeyFormat format, PasswordCallback cb)
+    public synchronized void load(String file, SSLKeyFormat format, SSLPasswordCallback cb)
         throws IllegalStateException,
                SSLCannotDecryptException,
                SSLInvalidKeyException
@@ -122,7 +122,7 @@ public final class SSLKey extends SSLObj
         this.format   = SSLKeyFormat.UNDEF;
     }
 
-    public synchronized void load(SSLKeyFormat format, PasswordCallback cb, byte[] b, int off, int len)
+    public synchronized void load(SSLKeyFormat format, SSLPasswordCallback cb, byte[] b, int off, int len)
         throws IllegalStateException,
                SSLCannotDecryptException,
                SSLInvalidKeyException

Copied: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLPasswordCallback.java (from r1180317, commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/PasswordCallback.java)
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLPasswordCallback.java?p2=commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLPasswordCallback.java&p1=commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/PasswordCallback.java&r1=1180317&r2=1180820&rev=1180820&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/PasswordCallback.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLPasswordCallback.java Mon Oct 10 08:08:49 2011
@@ -21,7 +21,7 @@ import org.apache.commons.runtime.Callba
 /**
  * Abstract password prompt handler.
  */
-public abstract class PasswordCallback
+public abstract class SSLPasswordCallback
     extends SSLObject implements Callback
 {
 
@@ -31,7 +31,6 @@ public abstract class PasswordCallback
     private boolean     echoOn;
     private String      prompt;
     private native long new0();
-    private native void def0(long pointer);
     private native void del0(long pointer);
     private native void set0(long pointer, String password);
     private native void set1(long pointer, byte[] password);
@@ -44,7 +43,7 @@ public abstract class PasswordCallback
     /**
      * Creates a new object instance
      */
-    protected PasswordCallback()
+    protected SSLPasswordCallback()
     {
         super.pointer = new0();
         prompt = Local.sm.get("password.PROMPT");
@@ -54,7 +53,7 @@ public abstract class PasswordCallback
     /**
      * Creates a new object instance
      */
-    protected PasswordCallback(String prompt, boolean echoOn)
+    protected SSLPasswordCallback(String prompt, boolean echoOn)
     {
         super.pointer = new0();
         this.prompt   = prompt;
@@ -73,16 +72,6 @@ public abstract class PasswordCallback
         }
     }
 
-    /**
-     * Set this callback as default for all password prompts.
-     */
-    public final void setDefault()
-    {
-        synchronized(lock) {
-            def0(super.pointer);
-        }
-    }
-    
     public final void setPrompt(String prompt)
     {
         this.prompt = prompt;

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/ssl.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/ssl.h?rev=1180820&r1=1180819&r2=1180820&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/ssl.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/ssl.h Mon Oct 10 08:08:49 2011
@@ -313,12 +313,7 @@ typedef struct ssl_obj_t {
     } u;
 } ssl_obj_t;
 
-
-/* Default password callback that
- * does no propts.
- */
-extern ssl_pass_cb_t *acr_ssl_password_cb;
-extern UI_METHOD     *acr_ssl_password_ui;
+extern UI_METHOD *acr_ssl_password_ui;
 
 typedef struct acr_ssl_srv_t    acr_ssl_srv_t;
 
@@ -468,6 +463,7 @@ void        ssl_init_app_data2_idx(void)
 void       *ssl_get_app_data2(SSL *);
 void        ssl_set_app_data2(SSL *, void *);
 int         ssl_password_callback(char *, int, int, void *);
+void        ssl_setup_ui_method(void);
 int         ssl_no_password_callback(char *buf, int bufsiz, int verify, void *cb);
 int         ssl_password_set(ssl_pass_cb_t *, const char *);
 void        ssl_bio_close(BIO *);

Modified: commons/sandbox/runtime/trunk/src/main/native/modules/openssl/init.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/modules/openssl/init.c?rev=1180820&r1=1180819&r2=1180820&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/modules/openssl/init.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/modules/openssl/init.c Mon Oct 10 08:08:49 2011
@@ -191,7 +191,6 @@ ACR_SSL_EXPORT(jint, SSL, init0)(JNI_STD
 
     if (ssl_initialized != 0)
         return 0;
-    memset(&acr_ssl_password_cb, 0, sizeof(ssl_pass_cb_t));
     /* We must register the library in full, to ensure our configuration
      * code can successfully test the SSL environment.
      */
@@ -235,6 +234,7 @@ ACR_SSL_EXPORT(jint, SSL, init0)(JNI_STD
          */
         return ACR_EINIT;
     }
+    ssl_setup_ui_method();
     ssl_initialized = 1;
     return 0;
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/modules/openssl/password.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/modules/openssl/password.c?rev=1180820&r1=1180819&r2=1180820&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/modules/openssl/password.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/modules/openssl/password.c Mon Oct 10 08:08:49 2011
@@ -26,9 +26,8 @@
 #error "Cannot compile this file without HAVE_OPENSSL defined"
 #endif
 
-/* Global password callback */
-ssl_pass_cb_t *acr_ssl_password_cb = 0;
-UI_METHOD     *acr_ssl_password_ui = 0;
+/* Global password UI */
+UI_METHOD *acr_ssl_password_ui = 0;
 
 int ssl_no_password_callback(char *buf, int bufsiz, int verify, void *cb)
 {
@@ -39,13 +38,9 @@ int ssl_password_callback(char *buf, int
 {
     ssl_pass_cb_t *pcb = (ssl_pass_cb_t *)cb;
 
-    if (buf == 0 || bufsiz < 0)
+    if (buf == 0 || bufsiz < 0 || pcb == 0)
         return -1;
     memset(buf, 0, bufsiz);
-    if (pcb == 0)
-        pcb = acr_ssl_password_cb;
-    if (pcb == 0)
-        return -1;
     if (pcb->password == 0 && pcb->cb != 0) {
         int rc, rv  = 0;
         jstring str = 0;
@@ -151,7 +146,7 @@ void ssl_destroy_ui_method()
     }
 }
 
-ACR_SSL_EXPORT(jlong, PasswordCallback, new0)(JNI_STDARGS)
+ACR_SSL_EXPORT(jlong, SSLPasswordCallback, new0)(JNI_STDARGS)
 {
     ssl_pass_cb_t *pc;
 
@@ -167,28 +162,18 @@ ACR_SSL_EXPORT(jlong, PasswordCallback, 
     return P2J(pc);
 }
 
-ACR_SSL_EXPORT(void, PasswordCallback, del0)(JNI_STDARGS, jlong ph)
+ACR_SSL_EXPORT(void, SSLPasswordCallback, del0)(JNI_STDARGS, jlong ph)
 {
     ssl_pass_cb_t *pc = J2P(ph, ssl_pass_cb_t *);
 
     if (pc != 0) {
-        if (pc == acr_ssl_password_cb) {
-            /* XXX: Should we allow that ? */
-            acr_ssl_password_cb = 0;
-        }
         AcrCallbackFree(env, pc->cb);
         AcrMemCleanse(pc->buf, sizeof(pc->buf));
         AcrFree(pc);
     }
 }
 
-ACR_SSL_EXPORT(void, PasswordCallback, def0)(JNI_STDARGS, jlong ph)
-{
-    ssl_pass_cb_t *pc = J2P(ph, ssl_pass_cb_t *);
-    acr_ssl_password_cb = pc;
-}
-
-ACR_SSL_EXPORT(void, PasswordCallback, set0)(JNI_STDARGS, jlong ph, jstring password)
+ACR_SSL_EXPORT(void, SSLPasswordCallback, set0)(JNI_STDARGS, jlong ph, jstring password)
 {
     ssl_pass_cb_t *pc = J2P(ph, ssl_pass_cb_t *);
 
@@ -206,7 +191,7 @@ ACR_SSL_EXPORT(void, PasswordCallback, s
     }
 }
 
-ACR_SSL_EXPORT(void, PasswordCallback, set1)(JNI_STDARGS, jlong ph,
+ACR_SSL_EXPORT(void, SSLPasswordCallback, set1)(JNI_STDARGS, jlong ph,
                                              jbyteArray password)
 {
     ssl_pass_cb_t *pc = J2P(ph, ssl_pass_cb_t *);
@@ -226,13 +211,14 @@ ACR_SSL_EXPORT(void, PasswordCallback, s
 }
 
 #if defined(ENABLE_TEST_PRIVATE)
-ACR_SSL_EXPORT(int, TestSSL, runPasswordCallback)(JNI_STDARGS)
+ACR_SSL_EXPORT(int, TestSSL, runPasswordCallback)(JNI_STDARGS, jlong ph)
 {
-    if (acr_ssl_password_cb != 0) {
+    ssl_pass_cb_t *cb = J2P(ph, ssl_pass_cb_t *);
+    if (cb != 0) {
         jstring str = AcrNewJavaStringA(env, "TestCallback");
-        AcrCallbackRun(env, acr_ssl_password_cb->cb, str, 0, 0);
-        if (acr_ssl_password_cb->password != 0 &&
-            strcmp(acr_ssl_password_cb->password, "nosecret") == 0)
+        AcrCallbackRun(env, cb->cb, str, 0, 0);
+        if (cb->password != 0 &&
+            strcmp(cb->password, "nosecret") == 0)
             return 0;
         else
             return ACR_EINVAL;

Modified: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestSSL.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestSSL.java?rev=1180820&r1=1180819&r2=1180820&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestSSL.java (original)
+++ commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestSSL.java Mon Oct 10 08:08:49 2011
@@ -26,9 +26,9 @@ import org.apache.commons.runtime.Native
 public class TestSSL extends Assert
 {
 
-    private static native int runPasswordCallback();
+    private static native int runPasswordCallback(long ph);
     
-    public class PasswordHandler extends PasswordCallback
+    public class PasswordHandler extends SSLPasswordCallback
     {
         public PasswordHandler()
         {
@@ -103,9 +103,8 @@ public class TestSSL extends Assert
     public void setupPasswordCallback()
     {
         PasswordHandler h = new PasswordHandler();
-        h.setDefault();
         try {
-            assertEquals(runPasswordCallback(), 0);
+            assertEquals(runPasswordCallback(((SSLObject)h).pointer), 0);
         } catch (UnsatisfiedLinkError e) {
             // Ignore cause its compile time defined.
             System.out.println("Skipping native test");

Modified: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestSSLCert.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestSSLCert.java?rev=1180820&r1=1180819&r2=1180820&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestSSLCert.java (original)
+++ commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestSSLCert.java Mon Oct 10 08:08:49 2011
@@ -29,7 +29,7 @@ public class TestSSLCert extends Assert
     private static final String pkey = "certificates/localhost.key";
     private static final String cert = "certificates/localhost.crt";
 
-    public class SimplePasswordHandler extends PasswordCallback
+    public class SimplePasswordHandler extends SSLPasswordCallback
     {
         public SimplePasswordHandler()
         {