summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2013-10-30 13:53:45 +0100
committerFelix Fietkau <nbd@openwrt.org>2013-10-30 13:55:47 +0100
commit1dc753d6438121ef4cc57b185ea340c082d362c6 (patch)
tree129432e9d49e011ab25291dd98bdc72fd25028a2
parente8ec1e56c3ec71b0eeeeac8842b6519548f3c695 (diff)
downloadustream-ssl-1dc753d6438121ef4cc57b185ea340c082d362c6.tar.gz
Add version detection of CyaSSL and make the cyassl backend compatible with both legacy and current CyaSSL versions
-rw-r--r--CMakeLists.txt7
-rw-r--r--ustream-io-cyassl.c57
2 files changed, 52 insertions, 12 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f6009e7..a918e16 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,5 +1,7 @@
cmake_minimum_required(VERSION 2.6)
+INCLUDE(CheckIncludeFiles)
+
PROJECT(ustream-ssl C)
ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -g3 -Wmissing-declarations)
@@ -15,6 +17,11 @@ IF(POLARSSL)
SET(SSL_SRC ustream-polarssl.c)
SET(SSL_LIB polarssl m)
ELSEIF(CYASSL)
+ CHECK_INCLUDE_FILES (cyassl/version.h HAVE_CYASSL_VERSION_H)
+ SET(CMAKE_EXTRA_INCLUDE_FILES cyassl/ssl.h)
+ IF (HAVE_CYASSL_VERSION_H)
+ ADD_DEFINITIONS(-DHAVE_CYASSL_VERSION_H)
+ ENDIF()
SET(SSL_SRC ustream-io-cyassl.c ustream-openssl.c)
SET(SSL_LIB cyassl m)
ELSE()
diff --git a/ustream-io-cyassl.c b/ustream-io-cyassl.c
index 0d9633a..ea2efa9 100644
--- a/ustream-io-cyassl.c
+++ b/ustream-io-cyassl.c
@@ -23,14 +23,11 @@
#include "ustream-ssl.h"
#include "ustream-internal.h"
-/* not defined in the header file */
-typedef int (*CallbackIORecv)(char *buf, int sz, void *ctx);
-typedef int (*CallbackIOSend)(char *buf, int sz, void *ctx);
-
-void SetCallbackIORecv_Ctx(SSL_CTX*, CallbackIORecv);
-void SetCallbackIOSend_Ctx(SSL_CTX*, CallbackIOSend);
-void SetCallbackIO_ReadCtx(SSL* ssl, void *rctx);
-void SetCallbackIO_WriteCtx(SSL* ssl, void *wctx);
+#ifdef HAVE_CYASSL_VERSION_H
+#include <cyassl/version.h>
+#else
+#define LIBCYASSL_VERSION_HEX 0
+#endif
static int s_ustream_read(char *buf, int len, void *ctx)
{
@@ -64,10 +61,46 @@ static int s_ustream_write(char *buf, int len, void *ctx)
return ustream_write(s, buf, len, false);
}
+#if (LIBCYASSL_VERSION_HEX > 0)
+static int io_recv_cb(SSL* ssl, char *buf, int sz, void *ctx)
+{
+ return s_ustream_read(buf, sz, ctx);
+}
+
+static int io_send_cb(SSL* ssl, char *buf, int sz, void *ctx)
+{
+ return s_ustream_write(buf, sz, ctx);
+}
+#else
+/* not defined in the header file */
+typedef int (*CallbackIORecv)(char *buf, int sz, void *ctx);
+typedef int (*CallbackIOSend)(char *buf, int sz, void *ctx);
+
+void SetCallbackIORecv_Ctx(SSL_CTX*, CallbackIORecv);
+void SetCallbackIOSend_Ctx(SSL_CTX*, CallbackIOSend);
+void SetCallbackIO_ReadCtx(SSL* ssl, void *rctx);
+void SetCallbackIO_WriteCtx(SSL* ssl, void *wctx);
+
+#define CyaSSL_SetIOReadCtx SetCallbackIO_ReadCtx
+#define CyaSSL_SetIOWriteCtx SetCallbackIO_WriteCtx
+#define CyaSSL_SetIORecv SetCallbackIORecv_Ctx
+#define CyaSSL_SetIOSend SetCallbackIOSend_Ctx
+
+static int io_recv_cb(char *buf, int sz, void *ctx)
+{
+ return s_ustream_read(buf, sz, ctx);
+}
+
+static int io_send_cb(char *buf, int sz, void *ctx)
+{
+ return s_ustream_write(buf, sz, ctx);
+}
+#endif
+
__hidden void ustream_set_io(void *ctx, void *ssl, struct ustream *conn)
{
- SetCallbackIO_ReadCtx(ssl, conn);
- SetCallbackIO_WriteCtx(ssl, conn);
- SetCallbackIORecv_Ctx(ctx, s_ustream_read);
- SetCallbackIOSend_Ctx(ctx, s_ustream_write);
+ CyaSSL_SetIOReadCtx(ssl, conn);
+ CyaSSL_SetIOWriteCtx(ssl, conn);
+ CyaSSL_SetIORecv(ctx, io_recv_cb);
+ CyaSSL_SetIOSend(ctx, io_send_cb);
}