commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1180788 - in /commons/sandbox/runtime/trunk: ./ src/main/java/org/apache/commons/runtime/platform/linux/ src/main/java/org/apache/commons/runtime/ssl/ src/main/native/ src/main/native/include/acr/ src/main/native/modules/openssl/ src/main/...
Date Mon, 10 Oct 2011 06:16:13 GMT
Author: mturk
Date: Mon Oct 10 06:16:12 2011
New Revision: 1180788

URL: http://svn.apache.org/viewvc?rev=1180788&view=rev
Log:
Add linux AsyncIO and some SSL features

Added:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/linux/AsyncIO.java
  (with props)
    commons/sandbox/runtime/trunk/src/main/native/os/linux/aio.c   (with props)
Modified:
    commons/sandbox/runtime/trunk/build.xml
    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/SSLEngine.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLKey.java
    commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
    commons/sandbox/runtime/trunk/src/main/native/configure
    commons/sandbox/runtime/trunk/src/main/native/include/acr/stdinc.h
    commons/sandbox/runtime/trunk/src/main/native/modules/openssl/api.c
    commons/sandbox/runtime/trunk/src/main/native/modules/openssl/cert.c
    commons/sandbox/runtime/trunk/src/main/native/modules/openssl/ctx.c
    commons/sandbox/runtime/trunk/src/main/native/modules/openssl/key.c
    commons/sandbox/runtime/trunk/src/main/native/os/linux/misc.c
    commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestMain.java

Modified: commons/sandbox/runtime/trunk/build.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/build.xml?rev=1180788&r1=1180787&r2=1180788&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/build.xml (original)
+++ commons/sandbox/runtime/trunk/build.xml Mon Oct 10 06:16:12 2011
@@ -417,7 +417,7 @@ The Apache Software Foundation (http://w
     <!-- Unit tests                                                          -->
     <!-- =================================================================== -->
     <target name="test" depends="tests">
-        <runtest groups="init,core,private,${systemid.subsystem}"/>
+        <runtest groups="init,core,private,${systemid.subsystem},${systemid.os}"/>
     </target>
     <target name="testopenssl" depends="certificates">
         <runtest groups="init,openssl" name="openssl"/>

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/linux/AsyncIO.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/linux/AsyncIO.java?rev=1180788&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/linux/AsyncIO.java
(added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/linux/AsyncIO.java
Mon Oct 10 06:16:12 2011
@@ -0,0 +1,78 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.runtime.platform.linux;
+
+import org.apache.commons.runtime.SystemException;
+import org.apache.commons.runtime.UnsupportedOperatingSystemException;
+
+/**
+ * Low level interface to Linux libaio.so.
+ */
+public class AsyncIO
+{
+
+    private AsyncIO()
+    {
+        // No instance
+    }
+    private static final String  SONAME = "libaio.so";
+    private static final Object  lock;
+    private static       boolean loaded = false;
+
+    static {
+        lock = new Object();
+        try {
+            if (enabled0()) {
+                loaded = load0(SONAME);
+            }
+
+        } catch (Exception e) {
+            // Ignore at startup
+        }
+    }
+    /*
+     * Return true if libaio if supported
+     * @param type OS type to test.
+     */
+    private static native boolean   load0(String soname)
+        throws SystemException;
+    private static native boolean   enabled0();
+        
+    /**
+     * Check if {@code libaio} is supported.
+     *
+     * @return {@code true} if  {@code libaio} support is enabled.
+     * @throws OperatingSystemException if we have error
+     * @throws UnsupportedOperatingSystemException if not running on
+     *          {@code Linux} operating system.
+     */
+    public static boolean  isEnabled()
+        throws SystemException, UnsupportedOperatingSystemException
+    {
+        try {
+            synchronized(lock) {
+                if (enabled0())
+                    return loaded;
+                else
+                    return false;
+            }
+        } catch (UnsatisfiedLinkError e) {
+            throw new UnsupportedOperatingSystemException();
+        }
+    }
+
+}

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/linux/AsyncIO.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=1180788&r1=1180787&r2=1180788&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 06:16:12 2011
@@ -34,6 +34,12 @@ public final class SSLCertificate extend
         throws SSLCannotDecryptException, SSLInvalidCertificateException;
     private static native long  load1(String file, int format, String password)
         throws SSLCannotDecryptException, SSLInvalidCertificateException;
+    private static native long  load2(String desc, int format, long pcb,
+                                      byte[] b, int off, int len)
+        throws SSLCannotDecryptException, SSLInvalidCertificateException;
+    private static native long  load3(String desc, int format, String password,
+                                      byte[] b, int off, int len)
+        throws SSLCannotDecryptException, SSLInvalidCertificateException;
     private static native void  free0(long cert);
 
     /**
@@ -101,6 +107,36 @@ public final class SSLCertificate extend
         this.format   = format;
     }
 
+    public synchronized void load(byte[] b, int off, int len,
+                                  SSLCertificateFormat format, PasswordCallback cb)
+        throws IllegalStateException,
+               SSLCannotDecryptException,
+               SSLInvalidCertificateException
+    {
+        if (super.pointer != 0L) {
+            // Already loaded
+            throw new IllegalStateException();
+        }
+        // TODO: Check byte array params
+        super.pointer = load2(desc, format.valueOf(), ((SSLObject)cb).pointer, b, off, len);
+        this.format   = format;
+    }
+
+    public synchronized void load(byte[] b, int off, int len,
+                                  SSLCertificateFormat format, String password)
+        throws IllegalStateException,
+               SSLCannotDecryptException,
+               SSLInvalidCertificateException
+    {
+        if (super.pointer != 0L) {
+            // Already loaded
+            throw new IllegalStateException();
+        }
+        // TODO: Check byte array params
+        super.pointer = load3(desc, format.valueOf(), password, b, off, len);
+        this.format   = format;
+    }
+
     public SSLCertificateFormat getFormat()
     {
         return format;

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLEngine.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLEngine.java?rev=1180788&r1=1180787&r2=1180788&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLEngine.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLEngine.java
Mon Oct 10 06:16:12 2011
@@ -55,6 +55,8 @@ public final class SSLEngine extends SSL
     public static void initialize(String name)
         throws SystemException
     {
+        if (!SSL.initialized())
+            throw new RuntimeException(Local.sm.get("openssl.EINIT"));
         synchronized(lock) {
             if (global == null) {
                 // Create global Engine instance.

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=1180788&r1=1180787&r2=1180788&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 06:16:12 2011
@@ -35,6 +35,10 @@ public final class SSLKey extends SSLObj
         throws SSLCannotDecryptException, SSLInvalidKeyException;
     private static native long  load2(long engine, String id, String password)
         throws SSLCannotDecryptException, SSLInvalidKeyException;
+    private static native long  load3(String desc, int format, long pcb, byte[] b, int off,
int len)
+        throws SSLCannotDecryptException, SSLInvalidKeyException;
+    private static native long  load4(String desc, int format, String password, byte[] b,
int off, int len)
+        throws SSLCannotDecryptException, SSLInvalidKeyException;
     private static native void  free0(long key);
 
     /**
@@ -118,6 +122,32 @@ public final class SSLKey extends SSLObj
         this.format   = SSLKeyFormat.UNDEF;
     }
 
+    public synchronized void load(SSLKeyFormat format, PasswordCallback cb, byte[] b, int
off, int len)
+        throws IllegalStateException,
+               SSLCannotDecryptException,
+               SSLInvalidKeyException
+    {
+        if (super.pointer != 0L) {
+            // Already loaded
+            throw new IllegalStateException();
+        }
+        super.pointer = load3(desc, format.valueOf(), ((SSLObject)cb).pointer, b, off, len);
+        this.format   = format;
+    }
+
+    public synchronized void load(SSLKeyFormat format, String password, byte[] b, int off,
int len)
+        throws IllegalStateException,
+               SSLCannotDecryptException,
+               SSLInvalidKeyException
+    {
+        if (super.pointer != 0L) {
+            // Already loaded
+            throw new IllegalStateException();
+        }
+        super.pointer = load4(desc, format.valueOf(), password, b, off, len);
+        this.format   = format;
+    }
+
     public SSLKeyFormat getFormat()
     {
         return format;

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in?rev=1180788&r1=1180787&r2=1180788&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in Mon Oct 10 06:16:12 2011
@@ -95,6 +95,7 @@ DARWIN_SOURCES=\
 HPUX_SOURCES=\
 	$(TOPDIR)/os/hpux/os.c
 LINUX_SOURCES=\
+	$(TOPDIR)/os/linux/aio.c \
 	$(TOPDIR)/os/linux/epoll.c \
 	$(TOPDIR)/os/linux/misc.c \
 	$(TOPDIR)/os/linux/sendfile.c \

Modified: commons/sandbox/runtime/trunk/src/main/native/configure
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/configure?rev=1180788&r1=1180787&r2=1180788&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/configure (original)
+++ commons/sandbox/runtime/trunk/src/main/native/configure Mon Oct 10 06:16:12 2011
@@ -117,6 +117,7 @@ has_shared=yes
 has_shared_version=no
 has_zlib_asm=yes
 has_openssl=no
+has_libaio_static=yes
 has_openssl_static=yes
 has_openssl_runtime=no
 openssl_home="$OPENSSL_HOME"
@@ -1220,6 +1221,20 @@ else
     have_port_h=0
     have_kstat=0
 fi
+
+have_libaio_static=0
+if [ ".$host" = ".linux" ]; then
+    have_libaio=`have_include libaio`
+    if [ ".$have_libaio" = .1 ]; then
+        if [ ".$has_libaio_static" = .yes ]; then
+            have_libaio_static=`have_library aio`
+            test ".$have_libaio_static" = .1 && varadds ldflags -laio
+        fi
+    fi
+else
+    have_libaio=0
+fi
+
 have_posixsem=`have_sem_open`
 if [ ".$has_posix_mutex" = .yes ]; then
     if [ ".$has_sysv_mutex_set" = .yes ]; then
@@ -1354,7 +1369,6 @@ extern "C" {
 #define HAVE_LIBGEN_H           `have_include libgen`
 #define HAVE_EXECINFO_H         `have_include execinfo`
 #define HAVE_AIO_H              `have_include aio`
-#define HAVE_LIBAIO_H           `have_include libaio`
 #define HAVE_FNMATCH_H          `have_include fnmatch`
 #define HAVE_LANGINFO_H         `have_include langinfo`
 #define HAVE_LOCALE_H           `have_include locale`
@@ -1464,6 +1478,8 @@ extern "C" {
 #define HAVE_SO_RCVTIMEO        `have_sockopt SO_RCVTIMEO`
 #define HAVE_SO_SNDTIMEO        `have_sockopt SO_SNDTIMEO`
 
+#define HAVE_LIBAIO             $have_libaio
+#define HAVE_LIBAIO_STATIC      $have_libaio_static
 #define HAVE_OPENSSL            $have_openssl
 #define HAVE_OPENSSL_STATIC     $have_openssl_static
 #define HAVE_FIPS               $have_fips

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/stdinc.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/stdinc.h?rev=1180788&r1=1180787&r2=1180788&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/stdinc.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/stdinc.h Mon Oct 10 06:16:12
2011
@@ -168,9 +168,6 @@
 #if HAVE_AIO_H
 #include <aio.h>
 #endif
-#if HAVE_LIBAIO_H
-#include <libaio.h>
-#endif
 #if HAVE_NETDB_H
 #include <netdb.h>
 #endif

Modified: commons/sandbox/runtime/trunk/src/main/native/modules/openssl/api.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/modules/openssl/api.c?rev=1180788&r1=1180787&r2=1180788&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/modules/openssl/api.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/modules/openssl/api.c Mon Oct 10 06:16:12
2011
@@ -89,6 +89,7 @@ struct SSLAPIst {
     void                (*fpBIO_free_all)(BIO *);
     BIO*                (*fpBIO_new)(BIO_METHOD *);
     BIO*                (*fpBIO_new_file)(const char *, const char *);
+    BIO*                (*fpBIO_new_mem_buf)(void *, int);
     BIO*                (*fpBIO_new_fp)(FILE *, int);
     BIO*                (*fpBIO_push)(BIO *, BIO *);
     BIO_METHOD*         (*fpBIO_f_base64)(void);
@@ -148,6 +149,7 @@ struct SSLAPIst {
     X509*               (*fpPEM_read_bio_X509)(BIO *, X509 **, pem_password_cb *, void *);
     X509*               (*fpPEM_read_bio_X509_AUX)(BIO *, X509 **, pem_password_cb *, void
*);
     EVP_PKEY*           (*fpPEM_read_bio_PrivateKey)(BIO *, EVP_PKEY **, pem_password_cb
*, void *);
+    STACK_OF(X509_INFO)*(*fpPEM_X509_INFO_read_bio)(BIO *, STACK_OF(X509_INFO) *, pem_password_cb
*, void *);
 
     /*** PKCS12   ***/
     PKCS12*             (*fpd2i_PKCS12_bio)(BIO *, PKCS12 **);
@@ -236,6 +238,10 @@ struct SSLAPIst {
     
     /*** X509     ***/
     void                (*fpX509_free)(X509 *);
+    void                (*fpX509_INFO_free)(X509_INFO *);
+    int                 (*fpX509_STORE_add_cert)(X509_STORE *, X509 *);
+    int                 (*fpX509_STORE_add_crl)(X509_STORE *, X509_CRL *);
+    X509_LOOKUP*        (*fpX509_STORE_add_lookup)(X509_STORE *, X509_LOOKUP_METHOD *);
     void                (*fpX509_STORE_free)(X509_STORE *);
     X509_STORE*         (*fpX509_STORE_new)(void);
     int                 (*fpX509_STORE_set_flags)(X509_STORE *, unsigned long);
@@ -244,7 +250,12 @@ struct SSLAPIst {
 
     /*** _STACK   ***/
     void                (*fpsk_pop_free)(SSLAPI_STACK *, void (*)(void *));
-
+    int                 (*fpsk_num)(const SSLAPI_STACK *);
+#if (OPENSSL_VERSION_NUMBER >= 0x10000000)
+    void*               (*fpsk_value)(const SSLAPI_STACK *, int);
+#else
+    chsr*               (*fpsk_value)(const SSLAPI_STACK *, int);
+#endif    
     void                (*fpNULL)(void);    
 };
 
@@ -352,6 +363,7 @@ ACR_JNI_EXPORT(jboolean, Native, ldopens
     CRYPTO_FPLOAD(BIO_free_all);
     CRYPTO_FPLOAD(BIO_new);
     CRYPTO_FPLOAD(BIO_new_file);
+    CRYPTO_FPLOAD(BIO_new_mem_buf);
     CRYPTO_FPLOAD(BIO_new_fp);
     CRYPTO_FPLOAD(BIO_push);
     CRYPTO_FPLOAD(BIO_f_base64);
@@ -408,6 +420,7 @@ ACR_JNI_EXPORT(jboolean, Native, ldopens
     CRYPTO_FPLOAD(PEM_read_bio_X509);
     CRYPTO_FPLOAD(PEM_read_bio_X509_AUX);
     CRYPTO_FPLOAD(PEM_read_bio_PrivateKey);
+    CRYPTO_FPLOAD(PEM_X509_INFO_read_bio);
 
     /*** PKCS12   ***/
     CRYPTO_FPLOAD(d2i_PKCS12_bio);
@@ -444,6 +457,10 @@ ACR_JNI_EXPORT(jboolean, Native, ldopens
 
     /*** X509     ***/
     CRYPTO_FPLOAD(X509_free);
+    CRYPTO_FPLOAD(X509_INFO_free);
+    CRYPTO_FPLOAD(X509_STORE_add_cert);
+    CRYPTO_FPLOAD(X509_STORE_add_crl);
+    CRYPTO_FPLOAD(X509_STORE_add_lookup);
     CRYPTO_FPLOAD(X509_STORE_free);
     CRYPTO_FPLOAD(X509_STORE_new);
     CRYPTO_FPLOAD(X509_STORE_set_flags);
@@ -452,6 +469,9 @@ ACR_JNI_EXPORT(jboolean, Native, ldopens
 
     /*** _STACK   ***/
     CRYPTO_FPLOAD(sk_pop_free);
+    CRYPTO_FPLOAD(sk_num);
+    CRYPTO_FPLOAD(sk_value);
+
     /* Optional functions
      * We could compile with the HAVE_FIPS, but target OpenSSL might not
      * have FIPS support for example.
@@ -539,6 +559,11 @@ BIO *BIO_new_file(const char *filename, 
     return SSLAPI_CALL(BIO_new_file)(filename, mode);
 }
 
+BIO *BIO_new_mem_buf(void *buf, int len)
+{
+    return SSLAPI_CALL(BIO_new_mem_buf)(buf, len);
+}
+
 BIO *BIO_new_fp(FILE *stream, int close_flag)
 {
     return SSLAPI_CALL(BIO_new_fp)(stream, close_flag);
@@ -840,6 +865,11 @@ EVP_PKEY *PEM_read_bio_PrivateKey(BIO *b
     return SSLAPI_CALL(PEM_read_bio_PrivateKey)(bp, x, cb, u);
 }
 
+STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb
*cb, void *u)
+{
+    return SSLAPI_CALL(PEM_X509_INFO_read_bio)(bp, sk, cb, u);
+}
+
 void PKCS12_free(PKCS12 *x)
 {
     SSLAPI_CALL(PKCS12_free)(x);
@@ -1143,6 +1173,26 @@ X509 *d2i_X509_bio(BIO *bp,X509 **x509)
     return SSLAPI_CALL(d2i_X509_bio)(bp, x509);
 }
 
+void X509_INFO_free(X509_INFO *a)
+{
+    SSLAPI_CALL(X509_INFO_free)(a);
+}
+
+int X509_STORE_add_cert(X509_STORE *ctx, X509 *x)
+{
+    return SSLAPI_CALL(X509_STORE_add_cert)(ctx, x);
+}
+
+int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x)
+{
+    return SSLAPI_CALL(X509_STORE_add_crl)(ctx, x);
+}
+
+X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, X509_LOOKUP_METHOD *m)
+{
+    return SSLAPI_CALL(X509_STORE_add_lookup)(v, m);
+}
+
 void X509_STORE_free(X509_STORE *v)
 {
     SSLAPI_CALL(X509_STORE_free)(v);
@@ -1169,6 +1219,20 @@ void sk_pop_free(SSLAPI_STACK *st, void 
     SSLAPI_CALL(sk_pop_free)(st, func);
 }
 
+int sk_num(const SSLAPI_STACK *s)
+{
+    return SSLAPI_CALL(sk_num)(s);
+}
+
+#if (OPENSSL_VERSION_NUMBER >= 0x10000000)
+void *sk_value(const SSLAPI_STACK *s, int i)
+#else
+char *sk_value(const SSLAPI_STACK *s, int i)
+#endif
+{
+    return SSLAPI_CALL(sk_value)(s, i);
+}
+
 #if HAVE_FIPS
 int FIPS_mode(void)
 {

Modified: commons/sandbox/runtime/trunk/src/main/native/modules/openssl/cert.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/modules/openssl/cert.c?rev=1180788&r1=1180787&r2=1180788&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/modules/openssl/cert.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/modules/openssl/cert.c Mon Oct 10 06:16:12
2011
@@ -26,24 +26,13 @@
 #error "Cannot compile this file without HAVE_OPENSSL defined"
 #endif
 
-static X509 *load_cert(ssl_pass_cb_t *password_callback, int format,
-                       const char *file, const char *desc)
+static X509 *load_cert_from_bio(ssl_pass_cb_t *password_callback,
+                                int format, BIO *bio)
 {
-    BIO  *bio  = 0;
     X509 *cert = 0;
 
-    if ((bio = BIO_new(BIO_s_file())) == 0)
-        return 0;
-    if (BIO_read_filename(bio, file) <= 0) {
-        BIO_free(bio);
+    if (bio == 0)
         return 0;
-    }
-    if (password_callback != 0) {
-        if (desc != 0)
-            password_callback->desc = desc;
-        else
-            password_callback->desc = file;
-    }
     if (format == SSL_CRT_FORMAT_UNDEF) {
         cert = PEM_read_bio_X509_AUX(bio, 0,
                                      ssl_password_callback,
@@ -69,10 +58,57 @@ static X509 *load_cert(ssl_pass_cb_t *pa
     else {
         /* TODO: Setup unsupported error */
     }
+    return cert;
+}
+
+static X509 *load_cert(ssl_pass_cb_t *password_callback, int format,
+                       const char *file, const char *desc)
+{
+    BIO  *bio;
+    X509 *cert;
+
+    if ((bio = BIO_new(BIO_s_file())) == 0)
+        return 0;
+    if (BIO_read_filename(bio, file) <= 0) {
+        BIO_free(bio);
+        return 0;
+    }
+    if (password_callback != 0) {
+        if (desc != 0)
+            password_callback->desc = desc;
+        else
+            password_callback->desc = file;
+    }    
+    cert = load_cert_from_bio(password_callback, format, bio);
     BIO_free(bio);
     return cert;
 }
 
+static X509 *load_cert_from_bytes(JNI_STDENV, ssl_pass_cb_t *cb, int format,
+                                  jbyteArray buf, jint off, jint len)
+{
+    X509 *cert = 0;
+    BIO  *bio  = 0;
+    char *ptr;
+
+    if ((ptr = (*env)->GetPrimitiveArrayCritical(env, buf, 0)) == 0)
+        return 0;
+    if ((bio = BIO_new_mem_buf(ptr + off, len)) != 0) {
+        cert = load_cert_from_bio(cb, format, bio);
+        if (cert == 0) {
+            int reason = ERR_GET_REASON(ERR_peek_error());
+            if (reason == EVP_R_BAD_DECRYPT)
+                ssl_throw_errno(env, ACR_EX_ESSLBADDEC);
+            else
+                ssl_throw_errno(env, ACR_EX_ESSLBADKEY);
+        }
+    }
+    (*env)->ReleasePrimitiveArrayCritical(env, buf, ptr, 0);
+    if (bio != 0)
+        BIO_free(bio);
+    return cert;
+}
+
 ACR_SSL_EXPORT(jlong, SSLCertificate, load0)(JNI_STDARGS, jstring file,
                                              jstring desc,
                                              jint format,
@@ -83,7 +119,7 @@ ACR_SSL_EXPORT(jlong, SSLCertificate, lo
 
     WITH_CSTR(file) {
     WITH_CSTR(desc) {
-        /* Load key */
+        /* Load cert */
         cert = load_cert(cb, format, J2S(file), J2S(desc));
         if (cert == 0) {
             int reason = ERR_GET_REASON(ERR_peek_error());
@@ -111,7 +147,7 @@ ACR_SSL_EXPORT(jlong, SSLCertificate, lo
             cb.password = J2S(password);
             cb.password_len = strlen(J2S(password));
         }
-        /* Load key */
+        /* Load cert */
         cert = load_cert(&cb, format, J2S(file), 0);
         if (cert == 0) {
             int reason = ERR_GET_REASON(ERR_peek_error());
@@ -126,7 +162,50 @@ ACR_SSL_EXPORT(jlong, SSLCertificate, lo
     return P2J(ssl_obj_new(env, ACR_SSL_OBJ_X509, cert));
 }
 
-ACR_SSL_EXPORT(void, SSLCertificate, free0)(JNI_STDARGS, jlong key)
+ACR_SSL_EXPORT(jlong, SSLCertificate, load2)(JNI_STDARGS, jstring desc,
+                                             jint format,
+                                             jlong pcb,
+                                             jbyteArray buf,
+                                             jint off, jint len)
+{
+    ssl_pass_cb_t *cb = J2P(pcb, ssl_pass_cb_t *);
+    X509 *cert = 0;
+
+    WITH_CSTR(desc) {
+        if (cb != 0)
+            cb->desc = J2S(desc);
+        /* Load cert */
+        cert = load_cert_from_bytes(env, cb, format, buf, off, len);
+    } DONE_WITH_STR(desc);
+
+    return P2J(ssl_obj_new(env, ACR_SSL_OBJ_X509, cert));
+}
+
+ACR_SSL_EXPORT(jlong, SSLCertificate, load3)(JNI_STDARGS, jstring desc,
+                                             jint format,
+                                             jstring password,
+                                             jbyteArray buf,
+                                             jint off, jint len)
+{
+    ssl_pass_cb_t cb = { 0, -1, 0, 0 };
+    X509 *cert = 0;
+
+    WITH_CSTR(desc) {
+    WITH_CSTR(password) {
+        if (J2S(password) != 0) {
+            cb.password = J2S(password);
+            cb.password_len = strlen(J2S(password));
+        }
+        cb.desc = J2S(desc);
+        /* Load cert */
+        cert = load_cert_from_bytes(env, &cb, format, buf, off, len);
+    } DONE_WITH_STR(password);
+    } DONE_WITH_STR(desc);
+
+    return P2J(ssl_obj_new(env, ACR_SSL_OBJ_X509, cert));
+}
+
+ACR_SSL_EXPORT(void, SSLCertificate, free0)(JNI_STDARGS, jlong cert)
 {
-    ssl_obj_release(J2P(key, void *));
+    ssl_obj_release(J2P(cert, void *));
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/modules/openssl/ctx.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/modules/openssl/ctx.c?rev=1180788&r1=1180787&r2=1180788&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/modules/openssl/ctx.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/modules/openssl/ctx.c Mon Oct 10 06:16:12
2011
@@ -71,6 +71,81 @@ static int generate_session_id(const SSL
         return 1;
 }
 
+struct iiovec {
+    char    *iov_base;
+    int      iov_len;
+};
+
+#define X509_L_MEM_LOAD         9
+#define X509_LOOKUP_load_mem(x, iov, type) \
+    X509_LOOKUP_ctrl((x), X509_L_MEM_LOAD, (iov), (long)(type), 0)
+
+static int by_mem_ctrl(X509_LOOKUP *ctx, int cmd, const char *buf,
+                       long type, char **ret)
+{
+    STACK_OF(X509_INFO) *inf;
+    BIO                 *bio = 0;
+    const struct iiovec *iov = (const struct iiovec *)buf;
+    int i, cnt = 0;
+
+    if (cmd != X509_L_MEM_LOAD || type != X509_FILETYPE_PEM)
+        goto done;
+    if ((bio = BIO_new_mem_buf(iov->iov_base, iov->iov_len)) == 0)
+        goto done;
+    if ((inf = PEM_X509_INFO_read_bio(bio, 0, 0, 0)) == 0)
+        goto done;
+
+    for (i = 0; i < sk_X509_INFO_num(inf); i++) {
+        X509_INFO *x = sk_X509_INFO_value(inf, i);
+        if(x->x509 != 0) {
+            X509_STORE_add_cert(ctx->store_ctx, x->x509);
+            cnt++;
+        }
+        if(x->crl  != 0) {
+            X509_STORE_add_crl(ctx->store_ctx, x->crl);
+            cnt++;
+        }
+    }
+    sk_X509_INFO_pop_free(inf, X509_INFO_free);
+done:
+    if (bio != 0)
+        BIO_free(bio);
+    if (cnt != 0)
+        X509err(X509_F_X509_LOAD_CERT_CRL_FILE, ERR_R_PEM_LIB);
+    return cnt;
+}
+
+static X509_LOOKUP_METHOD x509_mem_lookup = {
+    "Load memory into cache",
+    0,              /* new */
+    0,              /* free */
+    0,              /* init */
+    0,              /* shutdown */
+    by_mem_ctrl,    /* ctrl */
+    0,              /* get_by_subject */
+    0,              /* get_by_issuer_serial */
+    0,              /* get_by_fingerprint */
+    0,              /* get_by_alias */
+};
+
+static X509_LOOKUP_METHOD *x509_lookup_mem(void)
+{
+    return &x509_mem_lookup;
+}
+
+int ssl_ctx_load_verify_memory(SSL_CTX *ctx, char *buf, int len)
+{
+    X509_LOOKUP  *lu;
+    struct iiovec iov = { buf, len };
+    int           rc;
+
+    if ((lu = X509_STORE_add_lookup(ctx->cert_store, x509_lookup_mem())) == 0)
+        return 0;
+    rc = by_mem_ctrl(lu, X509_L_MEM_LOAD, (const char *)&iov,
+                     X509_FILETYPE_PEM, 0);    
+    return rc == 0 ? 0 : 1;
+}
+
 ACR_SSL_EXPORT(jlong, SSLContext, new0)(JNI_STDARGS, jint protocol, jint mode)
 {
     unsigned char    context_id[32];

Modified: commons/sandbox/runtime/trunk/src/main/native/modules/openssl/key.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/modules/openssl/key.c?rev=1180788&r1=1180787&r2=1180788&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/modules/openssl/key.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/modules/openssl/key.c Mon Oct 10 06:16:12
2011
@@ -26,22 +26,13 @@
 #error "Cannot compile this file without HAVE_OPENSSL defined"
 #endif
 
-static EVP_PKEY *load_key(ssl_pass_cb_t *password_callback, int format,
-                          const char *file, const char *desc)
+static EVP_PKEY *load_key_from_bio(ssl_pass_cb_t *password_callback,
+                                   int format, BIO *bio)
 {
-    BIO      *bio = 0;
     EVP_PKEY *key = 0;
 
-    if ((bio = BIO_new(BIO_s_file())) == 0)
+    if (bio == 0)
         return 0;
-    if (BIO_read_filename(bio, file) <= 0)
-        goto finished;
-    if (password_callback != 0) {
-        if (desc != 0)
-            password_callback->desc = desc;
-        else
-            password_callback->desc = file;
-    }
     if (format == SSL_KEY_FORMAT_UNDEF) {
         key = PEM_read_bio_PrivateKey(bio, 0,
                                       ssl_password_callback,
@@ -68,11 +59,58 @@ static EVP_PKEY *load_key(ssl_pass_cb_t 
     else {
         /* TODO: Setup unsupported error */
     }
-finished:
+    return key;
+}
+
+static EVP_PKEY *load_key(ssl_pass_cb_t *password_callback, int format,
+                          const char *file, const char *desc)
+{
+    BIO      *bio;
+    EVP_PKEY *key;
+
+    if ((bio = BIO_new(BIO_s_file())) == 0)
+        return 0;
+    if (BIO_read_filename(bio, file) <= 0) {
+        BIO_free(bio);
+        return 0;
+    }
+    if (password_callback != 0) {
+        if (desc != 0)
+            password_callback->desc = desc;
+        else
+            password_callback->desc = file;
+    }
+    key = load_key_from_bio(password_callback, format, bio);
     BIO_free(bio);
     return key;
 }
 
+static EVP_PKEY *load_key_from_bytes(JNI_STDENV, ssl_pass_cb_t *cb, int format,
+                                     jbyteArray buf, jint off, jint len)
+{
+    EVP_PKEY *key = 0;
+    BIO      *bio = 0;
+    char     *ptr;
+
+    if ((ptr = (*env)->GetPrimitiveArrayCritical(env, buf, 0)) == 0)
+        return 0;
+    if ((bio = BIO_new_mem_buf(ptr + off, len)) != 0) {
+        key = load_key_from_bio(cb, format, bio);
+        if (key == 0) {
+            int reason = ERR_GET_REASON(ERR_peek_error());
+            if (reason == EVP_R_BAD_DECRYPT)
+                ssl_throw_errno(env, ACR_EX_ESSLBADDEC);
+            else
+                ssl_throw_errno(env, ACR_EX_ESSLBADKEY);
+        }
+    }
+    (*env)->ReleasePrimitiveArrayCritical(env, buf, ptr, 0);
+    if (bio != 0)
+        BIO_free(bio);
+    return key;
+}
+
+
 ACR_SSL_EXPORT(jlong, SSLKey, load0)(JNI_STDARGS, jstring file,
                                      jstring desc,
                                      jint format,
@@ -167,6 +205,49 @@ ACR_SSL_EXPORT(jlong, SSLKey, load2)(JNI
 #endif
 }
 
+ACR_SSL_EXPORT(jlong, SSLKey, load3)(JNI_STDARGS, jstring desc,
+                                     jint format,
+                                     jlong pcb,
+                                     jbyteArray buf,
+                                     jint off, jint len)
+{
+    ssl_pass_cb_t *cb = J2P(pcb, ssl_pass_cb_t *);
+    EVP_PKEY *key = 0;
+
+    WITH_CSTR(desc) {
+        if (cb != 0)
+            cb->desc = J2S(desc);
+        /* Load key */
+        key = load_key_from_bytes(env, cb, format, buf, off, len);
+    } DONE_WITH_STR(desc);
+
+    return P2J(ssl_obj_new(env, ACR_SSL_OBJ_EVP_PKEY, key));
+}
+
+ACR_SSL_EXPORT(jlong, SSLKey, load4)(JNI_STDARGS, jstring desc,
+                                     jint format,
+                                     jstring password,
+                                     jbyteArray buf,
+                                     jint off, jint len)
+{
+    ssl_pass_cb_t cb = { 0, -1, 0, 0 };
+    EVP_PKEY *key = 0;
+
+    WITH_CSTR(desc) {
+    WITH_CSTR(password) {
+        if (J2S(password) != 0) {
+            cb.password = J2S(password);
+            cb.password_len = strlen(J2S(password));
+        }
+        cb.desc = J2S(desc);
+        /* Load key */
+        key = load_key_from_bytes(env, &cb, format, buf, off, len);
+    } DONE_WITH_STR(password);
+    } DONE_WITH_STR(desc);
+
+    return P2J(ssl_obj_new(env, ACR_SSL_OBJ_EVP_PKEY, key));
+}
+
 ACR_SSL_EXPORT(void, SSLKey, free0)(JNI_STDARGS, jlong key)
 {
     ssl_obj_release(J2P(key, void *));

Added: commons/sandbox/runtime/trunk/src/main/native/os/linux/aio.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/linux/aio.c?rev=1180788&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/linux/aio.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/linux/aio.c Mon Oct 10 06:16:12 2011
@@ -0,0 +1,145 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "acr/jniapi.h"
+#include "acr/string.h"
+#include "arch_opts.h"
+
+#if HAVE_LIBAIO
+#include <libaio.h>
+
+#if !HAVE_LIBAIO_STATIC
+
+#define LIBAIO_FPLOAD(fN)                                       \
+    fname  = #fN;                                               \
+    AIOapi.fp##fN = dlsym(libaiodso, fname);                    \
+    if (AIOapi.fp##fN == 0) goto failed
+
+
+#define LIBAIO_NAME(fN) AIOapi.fp##fN
+#define LIBAIO_CALL(fN) (*LIBAIO_NAME(fN))
+
+struct AIOAPIst {
+    /* library wrappers */
+    int                 (*fpio_queue_init)(int maxevents, io_context_t *ctxp);
+    int                 (*fpio_queue_release)(io_context_t ctx);
+    int                 (*fpio_queue_run)(io_context_t ctx);
+    /* Actual syscalls */
+    int                 (*fpio_setup)(int maxevents, io_context_t *ctxp);
+    int                 (*fpio_destroy)(io_context_t ctx);
+    int                 (*fpio_submit)(io_context_t ctx, long nr, struct iocb *ios[]);
+    int                 (*fpio_cancel)(io_context_t ctx, struct iocb *iocb, struct io_event
*evt);
+    int                 (*fpio_getevents)(io_context_t ctx_id, long min_nr, long nr, struct
io_event *events, struct timespec *timeout);
+
+    void                (*fpNULL)(void);    
+};
+
+static struct AIOAPIst AIOapi;
+static void           *libaiodso = 0;
+
+ACR_OS_EXPORT(jboolean, linux, AsyncIO, load0)(JNI_STDARGS, jstring soname)
+{
+    const char *fname = "";
+
+    if (libaiodso != 0)
+        return  JNI_TRUE;
+    /* Must be synchronized! */
+    memset(&AIOapi, 0, sizeof(AIOapi));
+    WITH_CSTR(soname) {
+        if ((libaiodso = dlopen(J2S(soname), RTLD_NOW | RTLD_GLOBAL)) == 0)
+            ACR_THROW_SYS_ERRNO();
+    } DONE_WITH_STR(soname);
+    if (libaiodso == 0)
+        return  JNI_FALSE;
+    LIBAIO_FPLOAD(io_queue_init);
+    LIBAIO_FPLOAD(io_queue_release);
+    LIBAIO_FPLOAD(io_queue_run);
+    /* Actual syscalls */
+    LIBAIO_FPLOAD(io_setup);
+    LIBAIO_FPLOAD(io_destroy);
+    LIBAIO_FPLOAD(io_submit);
+    LIBAIO_FPLOAD(io_cancel);
+    LIBAIO_FPLOAD(io_getevents);
+    
+    return JNI_TRUE;
+failed:
+    dlclose(libaiodso);
+    libaiodso = 0;
+    AcrThrowEx(env, ACR_EX_ENOENT, "Cannot find libaio::%s()", fname);
+    return JNI_TRUE;
+}
+
+int io_queue_init(int maxevents, io_context_t *ctxp)
+{
+    return LIBAIO_CALL(io_queue_init)(maxevents, ctxp);
+}
+
+int io_queue_release(io_context_t ctx)
+{
+    return LIBAIO_CALL(io_queue_release)(ctx);
+}
+
+int io_queue_run(io_context_t ctx)
+{
+    return LIBAIO_CALL(io_queue_run)(ctx);
+}
+
+int io_setup(int maxevents, io_context_t *ctxp)
+{
+    return LIBAIO_CALL(io_setup)(maxevents, ctxp);
+}
+
+int io_destroy(io_context_t ctx)
+{
+    return LIBAIO_CALL(io_destroy)(ctx);
+}
+
+int io_submit(io_context_t ctx, long nr, struct iocb *ios[])
+{
+    return LIBAIO_CALL(io_submit)(ctx, nr, ios);
+}
+
+int io_cancel(io_context_t ctx, struct iocb *iocb, struct io_event *evt)
+{
+    return LIBAIO_CALL(io_cancel)(ctx, iocb, evt);
+}
+
+int io_getevents(io_context_t ctx_id, long min_nr, long nr, struct io_event *events, struct
timespec *timeout)
+{
+    return LIBAIO_CALL(io_getevents)(ctx_id, min_nr, nr, events, timeout);
+}
+
+#else
+ACR_OS_EXPORT(jboolean, linux, AsyncIO, load0)(JNI_STDARGS)
+{
+    return JNI_TRUE;
+}
+
+#endif /* HAVE_LIBAIO_STATIC */
+
+ACR_OS_EXPORT(jboolean, linux, AsyncIO, enabled0)(JNI_STDARGS)
+{
+    return JNI_TRUE;
+}
+
+
+#else
+ACR_OS_EXPORT(jboolean, linux, AsyncIO, enabled0)(JNI_STDARGS)
+{
+    return JNI_FALSE;
+}
+
+#endif

Propchange: commons/sandbox/runtime/trunk/src/main/native/os/linux/aio.c
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/native/os/linux/misc.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/linux/misc.c?rev=1180788&r1=1180787&r2=1180788&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/linux/misc.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/linux/misc.c Mon Oct 10 06:16:12 2011
@@ -30,7 +30,7 @@ int IsSelinuxEnabled()
     static void                *sel = 0;
 
     if (sef == 0) {
-        sel = dlopen("libselinux" PACKAGE_DLLEXT, RTLD_LAZY);
+        sel = dlopen("libselinux.so", RTLD_LAZY);
         if (sel != 0)
             sef = (is_selinux_enabled_t)dlsym(sel, "is_selinux_enabled");
         if (sef == 0)
@@ -39,7 +39,7 @@ int IsSelinuxEnabled()
     return (*sef)();
 }
 
-ACR_OS_EXPORT(jboolean, linux, Selinux, enabled0)(JNI_STDARGS)
+ACR_OS_EXPORT(jboolean, linux, SELinux, enabled0)(JNI_STDARGS)
 {
     return V2Z(IsSelinuxEnabled());
 }

Modified: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestMain.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestMain.java?rev=1180788&r1=1180787&r2=1180788&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestMain.java (original)
+++ commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestMain.java Mon
Oct 10 06:16:12 2011
@@ -15,6 +15,8 @@
  */
 
 package org.apache.commons.runtime;
+import org.apache.commons.runtime.platform.linux.SELinux;
+import org.apache.commons.runtime.platform.linux.AsyncIO;
 
 import org.testng.annotations.*;
 import org.testng.Assert;
@@ -37,12 +39,24 @@ public class TestMain extends Assert
                          Os.getNumCpu() + " cpu's");
         System.out.print(". OpenSSL=" + Native.HAS_OPENSSL);
         System.out.print(", Debug=" + Native.HAS_MAINTAINER_MODE);
+    }
+
+    @Test(groups = { "linux" })
+    public void testOsFeatures()
+    {
+        System.out.print(", AsyncIO=" + AsyncIO.isEnabled());
+        System.out.print(", SELinux=" + SELinux.isEnabled());
+    }
+
+    @Test(groups = { "core" })
+    public void testVmArgs()
+    {
         System.out.println(".");
         System.out.flush();
         String[] args = Vm.arguments();
         assertNotNull(args[0]);
     }
-    
+
     @AfterSuite(groups = { "init" })
     public void shutDown()
     {



Mime
View raw message