Skip to content

Commit

Permalink
Merge pull request #6430 from kareem-wolfssl/memcached
Browse files Browse the repository at this point in the history
Add memcached support.
  • Loading branch information
JacobBarthelmeh authored Nov 22, 2023
2 parents 7036c84 + e175410 commit 5b3f549
Show file tree
Hide file tree
Showing 12 changed files with 228 additions and 71 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ jobs:
uses: ./.github/workflows/krb5.yml
packaging:
uses: ./.github/workflows/packaging.yml
memcached:
uses: ./.github/workflows/memcached.yml
# TODO: Currently this test fails. Enable it once it becomes passing.
# haproxy:
# uses: ./.github/workflows/haproxy.yml
81 changes: 81 additions & 0 deletions .github/workflows/memcached.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: memcached Tests

on:
workflow_call:

jobs:
build_wolfssl:
name: Build wolfSSL
# Just to keep it the same as the testing target
runs-on: ubuntu-latest
steps:
- name: Build wolfSSL
uses: wolfSSL/actions-build-autotools-project@v1
with:
path: wolfssl
configure: --enable-memcached
install: true

- name: Upload built lib
uses: actions/upload-artifact@v3
with:
name: wolf-install-memcached
path: build-dir
retention-days: 1

memcached_check:
strategy:
fail-fast: false
matrix:
# List of releases to test
include:
- ref: 1.6.22
name: ${{ matrix.ref }}
runs-on: ubuntu-latest
needs: build_wolfssl
steps:
- name: Download lib
uses: actions/download-artifact@v3
with:
name: wolf-install-memcached
path: build-dir

- name: Checkout OSP
uses: actions/checkout@v3
with:
repository: wolfssl/osp
path: osp

- name: Install dependencies
run: |
export DEBIAN_FRONTEND=noninteractive
sudo apt-get update
sudo apt-get install -y libevent-dev libevent-2.1-7 automake pkg-config make libio-socket-ssl-perl
- name: Checkout memcached
uses: actions/checkout@v3
with:
repository: memcached/memcached
ref: 1.6.22
path: memcached

- name: Configure and build memcached
run: |
cd $GITHUB_WORKSPACE/memcached/
patch -p1 < $GITHUB_WORKSPACE/osp/memcached/memcached_1.6.22.patch
./autogen.sh
export LD_LIBRARY_PATH=$GITHUB_WORKSPACE/build-dir/lib:$LD_LIBRARY_PATH
PKG_CONFIG_PATH=$GITHUB_WORKSPACE/build-dir/lib/pkgconfig ./configure --enable-wolfssl
make -j$(nproc)
- name: Confirm memcached built with wolfSSL
working-directory: ./memcached
run: |
export LD_LIBRARY_PATH=$GITHUB_WORKSPACE/build-dir/lib:$LD_LIBRARY_PATH
ldd memcached | grep wolfssl
- name: Run memcached tests
working-directory: ./memcached
run: |
export LD_LIBRARY_PATH=$GITHUB_WORKSPACE/build-dir/lib:$LD_LIBRARY_PATH
make -j$(nproc) test_tls
15 changes: 15 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1601,6 +1601,7 @@ AC_ARG_ENABLE([mcast],
# strongSwan (--enable-strongswan)
# OpenLDAP (--enable-openldap)
# hitch (--enable-hitch)
# memcached (--enable-memcached)

# Bind DNS compatibility Build
AC_ARG_ENABLE([bind],
Expand Down Expand Up @@ -1811,6 +1812,13 @@ AC_ARG_ENABLE([hitch],
[ ENABLED_HITCH=no ]
)

# memcached support
AC_ARG_ENABLE([memcached],
[AS_HELP_STRING([--enable-memcached],[Enable memcached support (default: disabled)])],
[ ENABLED_MEMCACHED=$enableval ],
[ ENABLED_MEMCACHED=no ]
)

# OpenSSL Coexist
AC_ARG_ENABLE([opensslcoexist],
[AS_HELP_STRING([--enable-opensslcoexist],[Enable coexistence of wolfssl/openssl (default: disabled)])],
Expand Down Expand Up @@ -6391,6 +6399,12 @@ then
AM_CFLAGS="$AM_CFLAGS -DOPENSSL_COMPATIBLE_DEFAULTS -DWOLFSSL_CIPHER_INTERNALNAME"
fi

if test "$ENABLED_MEMCACHED" = "yes"
then
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_SESSION_ID_CTX"
AM_CFLAGS="$AM_CFLAGS -DHAVE_EXT_CACHE -DHAVE_MEMCACHED"
fi


if test "$ENABLED_NGINX" = "yes"|| test "x$ENABLED_HAPROXY" = "xyes" || test "x$ENABLED_LIGHTY" = "xyes"
then
Expand Down Expand Up @@ -9682,6 +9696,7 @@ echo " * chrony: $ENABLED_CHRONY"
echo " * strongSwan: $ENABLED_STRONGSWAN"
echo " * OpenLDAP: $ENABLED_OPENLDAP"
echo " * hitch: $ENABLED_HITCH"
echo " * memcached: $ENABLED_MEMCACHED"
echo " * ERROR_STRINGS: $ENABLED_ERROR_STRINGS"
echo " * DTLS: $ENABLED_DTLS"
echo " * DTLS v1.3: $ENABLED_DTLS13"
Expand Down
23 changes: 17 additions & 6 deletions src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -7321,10 +7321,12 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup)
ssl->alert_history.last_tx.code = -1;
ssl->alert_history.last_tx.level = -1;

#ifdef OPENSSL_EXTRA
#ifdef WOLFSSL_SESSION_ID_CTX
/* copy over application session context ID */
ssl->sessionCtxSz = ctx->sessionCtxSz;
XMEMCPY(ssl->sessionCtx, ctx->sessionCtx, ctx->sessionCtxSz);
#endif
#ifdef OPENSSL_EXTRA
ssl->cbioFlag = ctx->cbioFlag;

ssl->protoMsgCb = ctx->protoMsgCb;
Expand Down Expand Up @@ -10359,6 +10361,8 @@ void ShrinkInputBuffer(WOLFSSL* ssl, int forcedFree)

int SendBuffered(WOLFSSL* ssl)
{
int retryLimit = WOLFSSL_MODE_AUTO_RETRY_ATTEMPTS;

if (ssl->CBIOSend == NULL && !WOLFSSL_IS_QUIC(ssl)) {
WOLFSSL_MSG("Your IO Send callback is null, please set");
return SOCKET_ERROR_E;
Expand All @@ -10379,15 +10383,22 @@ int SendBuffered(WOLFSSL* ssl)
#endif

while (ssl->buffers.outputBuffer.length > 0) {
int sent = ssl->CBIOSend(ssl,
(char*)ssl->buffers.outputBuffer.buffer +
ssl->buffers.outputBuffer.idx,
(int)ssl->buffers.outputBuffer.length,
ssl->IOCB_WriteCtx);
int sent = 0;
retry:
sent = ssl->CBIOSend(ssl,
(char*)ssl->buffers.outputBuffer.buffer +
ssl->buffers.outputBuffer.idx,
(int)ssl->buffers.outputBuffer.length,
ssl->IOCB_WriteCtx);
if (sent < 0) {
switch (sent) {

case WOLFSSL_CBIO_ERR_WANT_WRITE: /* would block */
if (retryLimit > 0 && ssl->ctx->autoRetry &&
!ssl->options.handShakeDone && !ssl->options.dtls) {
retryLimit--;
goto retry;
}
return WANT_WRITE;

case WOLFSSL_CBIO_ERR_CONN_RST: /* connection reset */
Expand Down
Loading

0 comments on commit 5b3f549

Please sign in to comment.