Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/cyssl to wolf #1

Merged
merged 4 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -393,25 +393,26 @@ AS_IF([test x"$with_matrixssl" != xno],

AM_CONDITIONAL(WITH_MATRIXSSL, [test x"$with_matrixssl" != xno])

AC_ARG_WITH([cyassl],
[AS_HELP_STRING([--with-cyassl], [enable support for cyassl])],[],[with_cyassl=no])

AS_IF([test x"$with_cyassl" != xno],
[AC_CHECK_LIB([cyassl], [wolfSSL_Init],
[AC_SUBST([LIBSSL], ["-lcyassl"])
AC_DEFINE([HAVE_CYASSL], [1],
[Define if you have cyassl])
AC_ARG_WITH([wolfssl],
[AS_HELP_STRING([--with-wolfssl], [enable support for wolfssl])],[],[with_wolfssl=no])

AS_IF([test x"$with_wolfssl" != xno],
[AC_CHECK_LIB([wolfssl], [wolfSSL_Init],
[AC_SUBST([LIBSSL], ["-lwolfssl"])
AC_DEFINE([HAVE_WOLFSSL], [1],
[Define if you have wolfssl])
],
[AC_MSG_FAILURE(
[--with-cyassl was given, but test for cyassl failed])],
[-lcyassl])])
[--with-wolfssl was given, but test for wolfssl failed. Ensure libwolfssl is installed and in the library path. Use --with-wolfssl=DIR if necessary.])],
[-lwolfssl])])

AS_IF([test x"$with_cyassl" != xno],
[AC_CHECK_HEADERS([cyassl/ssl.h ssh.h])])
AS_IF([test x"$with_wolfssl" != xno],
[AC_CHECK_HEADERS([wolfssl/options.h wolfssl/ssl.h])])

AM_CONDITIONAL(WITH_CYASSL, [test x"$with_cyassl" != xno])
AM_CONDITIONAL(WITH_WOLFSSL, [test x"$with_wolfssl" != xno])

AM_CONDITIONAL(WITH_SSL, [test x"$with_openssl" != xno || test x"$with_matrixssl" != xno || test x"$with_wolfssl" != xno])

AM_CONDITIONAL(WITH_SSL, [test x"$with_openssl" != xno || test x"$with_matrixssl" != xno || test x"$with_cyassl" != xno])

AC_ARG_WITH([matrixssl-cli],
[AS_HELP_STRING([--with-matrixssl-cli], [enable matrixssl client use])],[],[with_matrixssl_cli=no])
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ libchilli_la_LIBADD += ${LIBSSL}
LDADD += ${LIBSSL}
endif

if WITH_CYASSL
if WITH_WOLFSSL
libchilli_la_LIBADD += ${LIBSSL}
LDADD += ${LIBSSL}
endif
Expand Down
40 changes: 30 additions & 10 deletions src/chksum.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ int chksum6(struct pkt_ip6hdr_t *iph) {
hdr.zero[0]=hdr.zero[1]=hdr.zero[2]=0;
hdr.next_header = iph->next_header;
icmp->check = 0;
sum = in_cksum((uint16_t *)&hdr, sizeof(hdr));
sum += in_cksum((uint16_t *)icmp, ntohs(iph->data_len));
uint16_t hdr_buf[sizeof(hdr) / 2];
memcpy(hdr_buf, &hdr, sizeof(hdr));
sum = in_cksum(hdr_buf, sizeof(hdr));
uint16_t icmp_buf[ntohs(iph->data_len) / 2];
memcpy(icmp_buf, icmp, ntohs(iph->data_len));
sum += in_cksum(icmp_buf, ntohs(iph->data_len));
icmp->check = cksum_wrap(sum);
break;
}
Expand All @@ -74,8 +78,12 @@ int chksum6(struct pkt_ip6hdr_t *iph) {
hdr.zero[0]=hdr.zero[1]=hdr.zero[2]=0;
hdr.next_header = iph->next_header;
udphdr->check = 0;
sum = in_cksum((uint16_t *)&hdr, sizeof(hdr));
sum += in_cksum((uint16_t *)udphdr, udplen);
uint16_t hdr_buf[sizeof(hdr) / 2];
memcpy(hdr_buf, &hdr, sizeof(hdr));
sum = in_cksum(hdr_buf, sizeof(hdr));
uint16_t udphdr_buf[udplen / 2];
memcpy(udphdr_buf, udphdr, udplen);
sum += in_cksum(udphdr_buf, udplen);
udphdr->check = cksum_wrap(sum);
}
break;
Expand All @@ -91,8 +99,12 @@ int chksum6(struct pkt_ip6hdr_t *iph) {
hdr.zero[0]=hdr.zero[1]=hdr.zero[2]=0;
hdr.next_header = iph->next_header;
tcphdr->check = 0;
sum = in_cksum((uint16_t *)&hdr, sizeof(hdr));
sum += in_cksum((uint16_t *)tcphdr, tcplen);
uint16_t hdr_buf[sizeof(hdr) / 2];
memcpy(hdr_buf, &hdr, sizeof(hdr));
sum = in_cksum(hdr_buf, sizeof(hdr));
uint16_t tcphdr_buf[tcplen / 2];
memcpy(tcphdr_buf, tcphdr, tcplen);
sum += in_cksum(tcphdr_buf, tcplen);
tcphdr->check = cksum_wrap(sum);
}
break;
Expand Down Expand Up @@ -138,7 +150,9 @@ int chksum(struct pkt_iphdr_t *iph) {
tcph->check = 0;
sum = in_cksum(((uint16_t *)iph)+6/*saddr*/, 8);
sum += ntohs(IPPROTO_TCP + len);
sum += in_cksum((uint16_t *)tcph, len);
uint16_t tcph_buf[len / 2];
memcpy(tcph_buf, tcph, len);
sum += in_cksum(tcph_buf, len);
tcph->check = cksum_wrap(sum);
}
break;
Expand All @@ -155,7 +169,9 @@ int chksum(struct pkt_iphdr_t *iph) {
udph->check = 0;
sum = in_cksum(((uint16_t *)iph)+6/*saddr*/, 8);
sum += ntohs(IPPROTO_UDP + udplen);
sum += in_cksum((uint16_t *)udph, udplen);
uint16_t udph_buf[udplen / 2];
memcpy(udph_buf, udph, udplen);
sum += in_cksum(udph_buf, udplen);
udph->check = cksum_wrap(sum);
}
break;
Expand All @@ -166,14 +182,18 @@ int chksum(struct pkt_iphdr_t *iph) {
(struct pkt_icmphdr_t *)(((void *)iph) + hlen);
len -= hlen;
icmph->check = 0;
sum = in_cksum((uint16_t *)icmph, len);
uint16_t icmph_buf[len / 2];
memcpy(icmph_buf, icmph, len);
sum = in_cksum(icmph_buf, len);
icmph->check = cksum_wrap(sum);
}
break;
}

iph->check = 0;
sum = in_cksum((uint16_t *)iph, hlen);
uint16_t iph_buf[hlen / 2];
memcpy(iph_buf, iph, hlen);
sum = in_cksum(iph_buf, hlen);
iph->check = cksum_wrap(sum);

return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/md5.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <string.h> /* for memcpy() */
#include "md5.h"

#if !defined(HAVE_OPENSSL) && !defined(HAVE_CYASSL)
#if !defined(HAVE_OPENSSL) && !defined(HAVE_WOLFSSL)

void byteReverse(unsigned char *buf, size_t longs);

Expand Down
4 changes: 2 additions & 2 deletions src/md5.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
#define MD5Update MD5_Update
#define MD5Final MD5_Final

#elif HAVE_CYASSL
#include <cyassl/openssl/md5.h>
#elif HAVE_WOLFSSL
#include <wolfssl/openssl/md5.h>

#define MD5Init MD5_Init
#define MD5Update MD5_Update
Expand Down
2 changes: 1 addition & 1 deletion src/ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static int openssl_init = 0;
static openssl_env * sslenv_svr = 0;
static openssl_env * sslenv_cli = 0;

#ifdef HAVE_CYASSL
#ifdef HAVE_WOLFSSL
#define HAVE_OPENSSL 1
#else
#define HAVE_OPENSSL_ENGINE 1
Expand Down
19 changes: 10 additions & 9 deletions src/ssl.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ typedef struct {
} openssl_env;
#endif

#if defined(HAVE_OPENSSL) || defined(HAVE_CYASSL)
#if defined(HAVE_OPENSSL) || defined(HAVE_WOLFSSL)

#ifdef HAVE_OPENSSL
#include <openssl/buffer.h>
Expand All @@ -42,20 +42,21 @@ typedef struct {
#include <openssl/pem.h>
#include <openssl/engine.h>
#include <openssl/err.h>
#elif HAVE_CYASSL
#elif HAVE_WOLFSSL
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

#define OPENSSL_NO_ENGINE
#include <cyassl/options.h>
#include <cyassl/ssl.h>
#include <cyassl/openssl/bio.h>
#include <cyassl/openssl/crypto.h>
#include <cyassl/openssl/x509.h>
#include <cyassl/openssl/ssl.h>
#include <cyassl/openssl/pem.h>
#include <wolfssl/options.h>
#include <wolfssl/ssl.h>
#include <wolfssl/openssl/bio.h>
#include <wolfssl/openssl/crypto.h>
#include <wolfssl/openssl/engine.h>
#include <wolfssl/openssl/x509.h>
#include <wolfssl/openssl/ssl.h>
#include <wolfssl/openssl/pem.h>
#endif

#define OPENSSL_TMPKEY_MAX 4
Expand Down
2 changes: 1 addition & 1 deletion src/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ void copy_mac6(uint8_t *, uint8_t *);
#define USING_IPC_UNIX
#endif

#if defined(HAVE_OPENSSL) || defined(HAVE_MATRIXSSL) || defined(HAVE_CYASSL)
#if defined(HAVE_OPENSSL) || defined(HAVE_MATRIXSSL) || defined(HAVE_WOLFSSL)
#define HAVE_SSL 1
#endif

Expand Down