You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by rj...@apache.org on 2016/04/04 11:48:28 UTC

svn commit: r1737647 - in /tomcat/native/trunk/native: include/ssl_private.h src/ssl.c

Author: rjung
Date: Mon Apr  4 09:48:28 2016
New Revision: 1737647

URL: http://svn.apache.org/viewvc?rev=1737647&view=rev
Log:
Support for OpenSSL 1.1.0:
- BIO was made opaque post OpenSSL 1.1.0-pre4.

Modified:
    tomcat/native/trunk/native/include/ssl_private.h
    tomcat/native/trunk/native/src/ssl.c

Modified: tomcat/native/trunk/native/include/ssl_private.h
URL: http://svn.apache.org/viewvc/tomcat/native/trunk/native/include/ssl_private.h?rev=1737647&r1=1737646&r2=1737647&view=diff
==============================================================================
--- tomcat/native/trunk/native/include/ssl_private.h (original)
+++ tomcat/native/trunk/native/include/ssl_private.h Mon Apr  4 09:48:28 2016
@@ -213,6 +213,11 @@
 #define OPENSSL_malloc_init CRYPTO_malloc_init
 #define X509_REVOKED_get0_serialNumber(x) x->serialNumber
 #define OpenSSL_version_num SSLeay
+#define BIO_get_init(x)       (x->init)
+#define BIO_set_init(x,v)     (x->init=v)
+#define BIO_get_data(x)       (x->ptr)
+#define BIO_set_data(x,v)     (x->ptr=v)
+#define BIO_set_shutdown(x,v) (x->shutdown=v)
 #endif /* OPENSSL_VERSION_NUMBER < 0x10100000L */
 
 #define MAX_ALPN_NPN_PROTO_SIZE 65535

Modified: tomcat/native/trunk/native/src/ssl.c
URL: http://svn.apache.org/viewvc/tomcat/native/trunk/native/src/ssl.c?rev=1737647&r1=1737646&r2=1737647&view=diff
==============================================================================
--- tomcat/native/trunk/native/src/ssl.c (original)
+++ tomcat/native/trunk/native/src/ssl.c Mon Apr  4 09:48:28 2016
@@ -266,6 +266,11 @@ DH *SSL_get_dh_params(unsigned keylen)
     return NULL; /* impossible to reach. */
 }
 
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
+static void init_bio_methods(void);
+static void free_bio_methods(void);
+#endif
+
 TCN_IMPLEMENT_CALL(jint, SSL, version)(TCN_STDARGS)
 {
     UNREFERENCED_STDARGS;
@@ -296,6 +301,9 @@ static apr_status_t ssl_init_cleanup(voi
                          tcn_password_callback.cb.obj);
     }
 
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
+    free_bio_methods();
+#endif
     free_dh_params();
 
     /*
@@ -729,6 +737,9 @@ TCN_IMPLEMENT_CALL(jint, SSL, initialize
     SSL_init_app_data2_3_idx();
 
     init_dh_params();
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
+    init_bio_methods();
+#endif
 
     /*
      * Let us cleanup the ssl library when the library is unloaded
@@ -849,10 +860,11 @@ static apr_status_t generic_bio_cleanup(
 
 void SSL_BIO_close(BIO *bi)
 {
+    BIO_JAVA *j;
     if (bi == NULL)
         return;
-    if (bi->ptr != NULL && (bi->flags & SSL_BIO_FLAG_CALLBACK)) {
-        BIO_JAVA *j = (BIO_JAVA *)bi->ptr;
+    j = (BIO_JAVA *)BIO_get_data(bi);
+    if (j != NULL && BIO_test_flags(bi, SSL_BIO_FLAG_CALLBACK)) {
         j->refcount--;
         if (j->refcount == 0) {
             if (j->pool)
@@ -867,10 +879,11 @@ void SSL_BIO_close(BIO *bi)
 
 void SSL_BIO_doref(BIO *bi)
 {
+    BIO_JAVA *j;
     if (bi == NULL)
         return;
-    if (bi->ptr != NULL && (bi->flags & SSL_BIO_FLAG_CALLBACK)) {
-        BIO_JAVA *j = (BIO_JAVA *)bi->ptr;
+    j = (BIO_JAVA *)BIO_get_data(bi);
+    if (j != NULL && BIO_test_flags(bi, SSL_BIO_FLAG_CALLBACK)) {
         j->refcount++;
     }
 }
@@ -884,37 +897,44 @@ static int jbs_new(BIO *bi)
         return 0;
     j->pool      = NULL;
     j->refcount  = 1;
-    bi->shutdown = 1;
-    bi->init     = 0;
+    BIO_set_shutdown(bi, 1);
+    BIO_set_init(bi, 0);
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
+    /* No setter method for OpenSSL 1.1.0 available,
+     * but I can't find any functional use of the
+     * "num" field there either.
+     */
     bi->num      = -1;
-    bi->ptr      = (char *)j;
+#endif
+    BIO_set_data(bi, (void *)j);
 
     return 1;
 }
 
 static int jbs_free(BIO *bi)
 {
+    BIO_JAVA *j;
     if (bi == NULL)
         return 0;
-    if (bi->ptr != NULL) {
-        BIO_JAVA *j = (BIO_JAVA *)bi->ptr;
-        if (bi->init) {
+    j = (BIO_JAVA *)BIO_get_data(bi);
+    if (j != NULL) {
+        if (BIO_get_init(bi)) {
             JNIEnv   *e = NULL;
-            bi->init = 0;
+            BIO_set_init(bi, 0);
             tcn_get_java_env(&e);
             TCN_UNLOAD_CLASS(e, j->cb.obj);
         }
-        OPENSSL_free(bi->ptr);
+        OPENSSL_free(j);
     }
-    bi->ptr = NULL;
+    BIO_set_data(bi, NULL);
     return 1;
 }
 
 static int jbs_write(BIO *b, const char *in, int inl)
 {
     jint ret = -1;
-    if (b->init && in != NULL) {
-        BIO_JAVA *j = (BIO_JAVA *)b->ptr;
+    if (BIO_get_init(b) && in != NULL) {
+        BIO_JAVA *j = (BIO_JAVA *)BIO_get_data(b);
         JNIEnv   *e = NULL;
         jbyteArray jb;
         tcn_get_java_env(&e);
@@ -939,8 +959,8 @@ static int jbs_write(BIO *b, const char
 static int jbs_read(BIO *b, char *out, int outl)
 {
     jint ret = 0;
-    if (b->init && out != NULL) {
-        BIO_JAVA *j = (BIO_JAVA *)b->ptr;
+    if (BIO_get_init(b) && out != NULL) {
+        BIO_JAVA *j = (BIO_JAVA *)BIO_get_data(b);
         JNIEnv   *e = NULL;
         jbyteArray jb;
         tcn_get_java_env(&e);
@@ -966,8 +986,8 @@ static int jbs_read(BIO *b, char *out, i
 static int jbs_puts(BIO *b, const char *in)
 {
     int ret = 0;
-    if (b->init && in != NULL) {
-        BIO_JAVA *j = (BIO_JAVA *)b->ptr;
+    if (BIO_get_init(b) && in != NULL) {
+        BIO_JAVA *j = (BIO_JAVA *)BIO_get_data(b);
         JNIEnv   *e = NULL;
         tcn_get_java_env(&e);
         ret = (*e)->CallIntMethod(e, j->cb.obj,
@@ -980,8 +1000,8 @@ static int jbs_puts(BIO *b, const char *
 static int jbs_gets(BIO *b, char *out, int outl)
 {
     int ret = 0;
-    if (b->init && out != NULL) {
-        BIO_JAVA *j = (BIO_JAVA *)b->ptr;
+    if (BIO_get_init(b) && out != NULL) {
+        BIO_JAVA *j = (BIO_JAVA *)BIO_get_data(b);
         JNIEnv   *e = NULL;
         jobject  o;
         tcn_get_java_env(&e);
@@ -1015,6 +1035,7 @@ static long jbs_ctrl(BIO *b, int cmd, lo
     return ret;
 }
 
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
 static BIO_METHOD jbs_methods = {
     BIO_TYPE_FILE,
     "Java Callback",
@@ -1027,10 +1048,34 @@ static BIO_METHOD jbs_methods = {
     jbs_free,
     NULL
 };
+#else
+static BIO_METHOD *jbs_methods = NULL;
+
+static void init_bio_methods(void)
+{
+    jbs_methods = BIO_meth_new(BIO_TYPE_FILE, "Java Callback");
+    BIO_meth_set_write(jbs_methods, &jbs_write);
+    BIO_meth_set_read(jbs_methods, &jbs_read);
+    BIO_meth_set_puts(jbs_methods, &jbs_puts);
+    BIO_meth_set_gets(jbs_methods, &jbs_gets);
+    BIO_meth_set_ctrl(jbs_methods, &jbs_ctrl);
+    BIO_meth_set_create(jbs_methods, &jbs_new);
+    BIO_meth_set_destroy(jbs_methods, &jbs_free);
+}
+
+static void free_bio_methods(void)
+{
+    BIO_meth_free(jbs_methods);
+}
+#endif
 
 static BIO_METHOD *BIO_jbs()
 {
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
     return(&jbs_methods);
+#else
+    return jbs_methods;
+#endif
 }
 
 TCN_IMPLEMENT_CALL(jlong, SSL, newBIO)(TCN_STDARGS, jlong pool,
@@ -1046,7 +1091,7 @@ TCN_IMPLEMENT_CALL(jlong, SSL, newBIO)(T
         tcn_ThrowException(e, "Create BIO failed");
         goto init_failed;
     }
-    j = (BIO_JAVA *)bio->ptr;
+    j = (BIO_JAVA *)BIO_get_data(bio);
     if (j == NULL) {
         tcn_ThrowException(e, "Create BIO failed");
         goto init_failed;
@@ -1066,8 +1111,8 @@ TCN_IMPLEMENT_CALL(jlong, SSL, newBIO)(T
     /* TODO: Check if method id's are valid */
     j->cb.obj    = (*e)->NewGlobalRef(e, callback);
 
-    bio->init  = 1;
-    bio->flags = SSL_BIO_FLAG_CALLBACK;
+    BIO_set_init(bio, 1);
+    BIO_set_flags(bio, SSL_BIO_FLAG_CALLBACK);
     return P2J(bio);
 init_failed:
     return 0;



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org