Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 11218754A for ; Fri, 16 Sep 2011 19:36:29 +0000 (UTC) Received: (qmail 26621 invoked by uid 500); 16 Sep 2011 19:36:28 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 26568 invoked by uid 500); 16 Sep 2011 19:36:28 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 26561 invoked by uid 99); 16 Sep 2011 19:36:28 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 Sep 2011 19:36:28 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 Sep 2011 19:36:24 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 465212388994 for ; Fri, 16 Sep 2011 19:36:03 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1171745 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/ssl/ native/ native/include/acr/ native/modules/openssl/ Date: Fri, 16 Sep 2011 19:36:02 -0000 To: commits@commons.apache.org From: mturk@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20110916193603.465212388994@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mturk Date: Fri Sep 16 19:36:01 2011 New Revision: 1171745 URL: http://svn.apache.org/viewvc?rev=1171745&view=rev Log: Add top level server class Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLServer.java (with props) commons/sandbox/runtime/trunk/src/main/native/modules/openssl/server.c (with props) Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLBio.java commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in commons/sandbox/runtime/trunk/src/main/native/include/acr/ssl.h commons/sandbox/runtime/trunk/src/main/native/modules/openssl/cert.c commons/sandbox/runtime/trunk/src/main/native/modules/openssl/key.c commons/sandbox/runtime/trunk/src/main/native/modules/openssl/util.c Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLBio.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLBio.java?rev=1171745&r1=1171744&r2=1171745&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLBio.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLBio.java Fri Sep 16 19:36:01 2011 @@ -27,9 +27,9 @@ public abstract class SSLBio extends Nat // Hide NativePointer private final long pointer = 0L; - public static native void init0(); - public static native long new0(SSLBio thiz); - public static native void close0(long bio); + private static native void init0(); + private static native long new0(SSLBio thiz); + private static native void close0(long bio); static { init0(); Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLServer.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLServer.java?rev=1171745&view=auto ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLServer.java (added) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLServer.java Fri Sep 16 19:36:01 2011 @@ -0,0 +1,83 @@ +/* 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.ssl; + +import org.apache.commons.runtime.InvalidArgumentException; +import org.apache.commons.runtime.OperationNotImplementedException; +import org.apache.commons.runtime.Status; +import org.apache.commons.runtime.SystemException; + +import java.io.Closeable; +import java.io.File; +import java.io.IOException; +import java.nio.ByteBuffer; + +/** + * Represents SSL server instance. + */ +public final class SSLServer extends NativePointer implements Closeable +{ + + // Hide NativePointer + private final long pointer = 0L; + private final String name; + private static native long new0(String name); + private static native void close0(long srv); + + private SSLServer() + { + name = null; + } + + /** + * Creates a new server instance. + * + * @param name server name + */ + public SSLServer(String name) + { + this.name = name; + super.pointer = new0(this.name); + } + + /** + * Free the allocated resource by the Operating system. + *

+ * Note that {@code Object.finalize()} method will call + * this function. However if the native code can block for + * long time explicit {@code close()} should be called. + *

+ * @see java.io.Closeable#close() + * @throws IOException if an I/O error occurs. + */ + public final void close() + throws IOException + { + close0(super.pointer); + super.pointer = 0L; + } + + /** + * Gets this server's name. + * @return server name + */ + public final String getName() + { + return name; + } +} + Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLServer.java ------------------------------------------------------------------------------ svn:eol-style = native 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=1171745&r1=1171744&r2=1171745&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in (original) +++ commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in Fri Sep 16 19:36:01 2011 @@ -157,6 +157,7 @@ SSLSOURCES=\ $(TOPDIR)/modules/openssl/key.c \ $(TOPDIR)/modules/openssl/password.c \ $(TOPDIR)/modules/openssl/rand.c \ + $(TOPDIR)/modules/openssl/server.c \ $(TOPDIR)/modules/openssl/util.c CXXSOURCES= 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=1171745&r1=1171744&r2=1171745&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 Fri Sep 16 19:36:01 2011 @@ -134,10 +134,25 @@ #define SSL_CRT_FORMAT_PKCS12 5 #define SSL_CRT_FORMAT_SMIME 6 #define SSL_CRT_FORMAT_ENGINE 7 + +#define SSL_KEY_FORMAT_UNDEF 0 +#define SSL_KEY_FORMAT_ASN1 1 +#define SSL_KEY_FORMAT_TEXT 2 +#define SSL_KEY_FORMAT_PEM 3 +#define SSL_KEY_FORMAT_NETSCAPE 4 +#define SSL_KEY_FORMAT_PKCS12 5 +#define SSL_KEY_FORMAT_SMIME 6 +#define SSL_KEY_FORMAT_ENGINE 7 /* XXX this stupid macro helps us to avoid * adding yet another param to load_*key() */ #define SSL_KEY_FORMAT_IISSGC 8 +#define SSL_KEY_FORMAT_PEMRSA 9 /* PEM RSAPubicKey format */ +#define SSL_KEY_FORMAT_ASN1RSA 10 /* DER RSAPubicKey format */ +#define SSL_KEY_FORMAT_MSBLOB 11 /* MS Key blob format */ +#define SSL_KEY_FORMAT_PVK 12 /* MS PVK file format */ + + /* * Define the SSL options @@ -167,22 +182,6 @@ #define SSL_MODE_SERVER 1 #define SSL_MODE_COMBINED 2 -#define SSL_FORMAT_UNDEF 0 -#define SSL_FORMAT_ASN1 1 -#define SSL_FORMAT_TEXT 2 -#define SSL_FORMAT_PEM 3 -#define SSL_FORMAT_NETSCAPE 4 -#define SSL_FORMAT_PKCS12 5 -#define SSL_FORMAT_SMIME 6 -#define SSL_FORMAT_ENGINE 7 -#define SSL_FORMAT_IISSGC 8 /* XXX this stupid macro helps us to avoid - * adding yet another param to load_*key() - */ -#define SSL_FORMAT_PEMRSA 9 /* PEM RSAPubicKey format */ -#define SSL_FORMAT_ASN1RSA 10 /* DER RSAPubicKey format */ -#define SSL_FORMAT_MSBLOB 11 /* MS Key blob format */ -#define SSL_FORMAT_PVK 12 /* MS PVK file format */ - #define SSL_BIO_FLAG_RDONLY 1 #define SSL_BIO_FLAG_CALLBACK 2 #define SSL_DEFAULT_CACHE_SIZE 256 @@ -292,12 +291,13 @@ typedef struct ssl_pass_cb_t { */ extern ssl_pass_cb_t *acr_ssl_password_cb; +typedef struct acr_ssl_server_t acr_ssl_server_t; /* Server context */ typedef struct acr_ssl_ctxt_t { SSL_CTX *ctx; BIO *bio_os; BIO *bio_is; - + acr_ssl_server_t *srv; unsigned char context_id[MD5_DIGEST_LENGTH]; int protocol; @@ -343,6 +343,12 @@ typedef struct acr_ssl_ctxt_t { } acr_ssl_ctxt_t; +struct acr_ssl_server_t { + char *name; + acr_ssl_ctxt_t *ctx; + acr_ssl_ctxt_t *ctx2; +}; + #define ssl_ctx_get_extra_certs(ctx) ((ctx)->extra_certs) #define ssl_ctx_set_extra_certs(ctx, value) \ do { \ @@ -373,6 +379,7 @@ struct ssl_sd_t { WCHAR *socketfname; #endif /*** SSL struct members ***/ + acr_ssl_server_t *srv; acr_ssl_ctxt_t *ctx; SSL *ssl; X509 *peer; @@ -409,6 +416,7 @@ int ssl_callback_ssl_verify(int, int ssl_rand_seed(const char *file); int ssl_load_pkcs12(BIO *, ssl_pass_cb_t *, EVP_PKEY **, X509 **, STACK_OF(X509) **); void ssl_throw_errno(JNI_STDENV, int cls); +void ssl_throw_errno_ex(JNI_STDENV, int cls, const char *fmt, ...); #endif #endif /* _ACR_SSL_H_ */ 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=1171745&r1=1171744&r2=1171745&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 Fri Sep 16 19:36:01 2011 @@ -44,15 +44,15 @@ static X509 *load_cert(ssl_pass_cb_t *pa else password_callback->desc = file; } - if (format == SSL_FORMAT_ASN1) { + if (format == SSL_CRT_FORMAT_ASN1) { cert = d2i_X509_bio(bio, 0); } - else if (format == SSL_FORMAT_PEM) { + else if (format == SSL_CRT_FORMAT_PEM) { cert = PEM_read_bio_X509_AUX(bio, 0, ssl_password_callback, password_callback); } - else if (format == SSL_FORMAT_PKCS12) { + else if (format == SSL_CRT_FORMAT_PKCS12) { if (!ssl_load_pkcs12(bio, 0, 0, &cert, 0)) cert = 0; } 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=1171745&r1=1171744&r2=1171745&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 Fri Sep 16 19:36:01 2011 @@ -44,15 +44,15 @@ static EVP_PKEY *load_key(ssl_pass_cb_t else password_callback->desc = file; } - if (format == SSL_FORMAT_ASN1) { + if (format == SSL_KEY_FORMAT_ASN1) { key = d2i_PrivateKey_bio(bio, 0); } - else if (format == SSL_FORMAT_PEM) { + else if (format == SSL_KEY_FORMAT_PEM) { key = PEM_read_bio_PrivateKey(bio, 0, ssl_password_callback, password_callback); } - else if (format == SSL_FORMAT_PKCS12) { + else if (format == SSL_KEY_FORMAT_PKCS12) { if (!ssl_load_pkcs12(bio, password_callback, &key, 0, 0)) key = 0; Added: commons/sandbox/runtime/trunk/src/main/native/modules/openssl/server.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/modules/openssl/server.c?rev=1171745&view=auto ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/modules/openssl/server.c (added) +++ commons/sandbox/runtime/trunk/src/main/native/modules/openssl/server.c Fri Sep 16 19:36:01 2011 @@ -0,0 +1,52 @@ +/* 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/clazz.h" +#include "acr/error.h" +#include "acr/misc.h" +#include "acr/string.h" +#include "acr/port.h" +#include "acr/ssl.h" +#include "arch_sync.h" + +#if !HAVE_OPENSSL +#error "Cannot compile this file without HAVE_OPENSSL defined" +#endif + +ACR_SSL_EXPORT(jlong, SSLServer, new0)(JNI_STDARGS, jstring name) +{ + acr_ssl_server_t *s; + + s = ACR_TALLOC(acr_ssl_server_t); + if (s == 0) + return 0; + + WITH_CSTR(name) { + s->name = AcrStrdup(env, J2S(name)); + } DONE_WITH_STR(name); + + return P2J(s); +} + +ACR_SSL_EXPORT(void, SSLServer, free0)(JNI_STDARGS, jlong srv) +{ + acr_ssl_server_t *s = J2P(srv, acr_ssl_server_t *); + if (s != 0) { + AcrFree(s->name); + /* SSLServer cleanup */ + AcrFree(s); + } +} Propchange: commons/sandbox/runtime/trunk/src/main/native/modules/openssl/server.c ------------------------------------------------------------------------------ svn:eol-style = native Modified: commons/sandbox/runtime/trunk/src/main/native/modules/openssl/util.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/modules/openssl/util.c?rev=1171745&r1=1171744&r2=1171745&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/modules/openssl/util.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/modules/openssl/util.c Fri Sep 16 19:36:01 2011 @@ -18,6 +18,7 @@ #include "acr/error.h" #include "acr/misc.h" #include "acr/dso.h" +#include "acr/port.h" #include "arch_sync.h" #include "acr/ssl.h" @@ -429,9 +430,25 @@ cleanup: } -void ssl_throw_errno(JNI_STDENV, int cls) +void ssl_throw_errno_ex(JNI_STDENV, int cls, const char *fmt, ...) { char msg[256]; + char buf[1024]; + char *ptr = msg; + ERR_error_string_n(ERR_get_error(), msg, sizeof(msg)); - AcrThrow(env, cls, msg); + if (fmt != 0) { + va_list ap; + va_start(ap, fmt); + vsnprintf(buf, sizeof(buf), fmt, ap); + va_end(ap); + strlcat(buf, msg, sizeof(buf)); + ptr = buf; + } + AcrThrow(env, cls, ptr); +} + +void ssl_throw_errno(JNI_STDENV, int cls) +{ + ssl_throw_errno_ex(env, cls, 0); }