Skip to content

Commit ca61034

Browse files
Add memcached support.
memcached support: add required functions/defines. Fix running unit test when defining DEBUG_WOLFSSL_VERBOSE without OPENSSL_EXTRA. Break out session_id_context APIs into separate option WOLFSSL_SESSION_ID_CTX, so they can be used without OPENSSL_EXTRA. Make wolfSSL_ERR_get_error and wolfSSL_CTX_set_mode available for memcached. Add --enable-memcached. Include required defines for memcached. Revert unit test fix, no longer needed. Add Github actions test for memcached. Stop defining DEBUG_WOLFSSL_VERBOSE for memcached. Add auto retry to writes. Memcached CI: correct libevent package name. Memcached CI: Add pkgconfig path for Github CI wolfSSL prefix. memcached: Fix WOLFSSL_OP_NO_RENEGOTIATION going outside of int bounds, add LD_LIBRARY_PATH for memcached CI test. memcached CI: Use correct path for wolfSSL memcached: Add required perl dependency for SSL tests memcached: Update to 1.6.22 memcached: actually test tls memcached: Update wolfSSL_SSL_in_before to be side agnostic.
1 parent e395aad commit ca61034

12 files changed

Lines changed: 230 additions & 71 deletions

File tree

.github/workflows/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ jobs:
4040
uses: ./.github/workflows/krb5.yml
4141
packaging:
4242
uses: ./.github/workflows/packaging.yml
43+
memcached:
44+
uses: ./.github/workflows/memcached.yml
4345
# TODO: Currently this test fails. Enable it once it becomes passing.
4446
# haproxy:
4547
# uses: ./.github/workflows/haproxy.yml

.github/workflows/memcached.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: memcached Tests
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
build_wolfssl:
8+
name: Build wolfSSL
9+
# Just to keep it the same as the testing target
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Build wolfSSL
13+
uses: wolfSSL/actions-build-autotools-project@v1
14+
with:
15+
path: wolfssl
16+
configure: --enable-memcached
17+
install: true
18+
19+
- name: Upload built lib
20+
uses: actions/upload-artifact@v3
21+
with:
22+
name: wolf-install-memcached
23+
path: build-dir
24+
retention-days: 1
25+
26+
memcached_check:
27+
strategy:
28+
fail-fast: false
29+
matrix:
30+
# List of releases to test
31+
include:
32+
- ref: 1.6.22
33+
name: ${{ matrix.ref }}
34+
runs-on: ubuntu-latest
35+
needs: build_wolfssl
36+
steps:
37+
- name: Download lib
38+
uses: actions/download-artifact@v3
39+
with:
40+
name: wolf-install-memcached
41+
path: build-dir
42+
43+
- name: Checkout OSP
44+
uses: actions/checkout@v3
45+
with:
46+
# TODO: Change to upstream wolfssl/osp once merged
47+
repository: kareem-wolfssl/osp
48+
ref: memcached
49+
path: osp
50+
51+
- name: Install dependencies
52+
run: |
53+
export DEBIAN_FRONTEND=noninteractive
54+
sudo apt-get update
55+
sudo apt-get install -y libevent-dev libevent-2.1-7 automake pkg-config make libio-socket-ssl-perl
56+
57+
- name: Checkout memcached
58+
uses: actions/checkout@v3
59+
with:
60+
repository: memcached/memcached
61+
ref: 1.6.22
62+
path: memcached
63+
64+
- name: Configure and build memcached
65+
run: |
66+
cd $GITHUB_WORKSPACE/memcached/
67+
patch -p1 < $GITHUB_WORKSPACE/osp/memcached/memcached_1.6.22.patch
68+
./autogen.sh
69+
export LD_LIBRARY_PATH=$GITHUB_WORKSPACE/build-dir/lib:$LD_LIBRARY_PATH
70+
PKG_CONFIG_PATH=$GITHUB_WORKSPACE/build-dir/lib/pkgconfig ./configure --enable-wolfssl
71+
make -j$(nproc)
72+
73+
- name: Confirm memcached built with wolfSSL
74+
working-directory: ./memcached
75+
run: |
76+
export LD_LIBRARY_PATH=$GITHUB_WORKSPACE/build-dir/lib:$LD_LIBRARY_PATH
77+
ldd memcached | grep wolfssl
78+
79+
- name: Run memcached tests
80+
working-directory: ./memcached
81+
run: |
82+
export LD_LIBRARY_PATH=$GITHUB_WORKSPACE/build-dir/lib:$LD_LIBRARY_PATH
83+
make -j$(nproc) test_tls

configure.ac

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,6 +1601,7 @@ AC_ARG_ENABLE([mcast],
16011601
# strongSwan (--enable-strongswan)
16021602
# OpenLDAP (--enable-openldap)
16031603
# hitch (--enable-hitch)
1604+
# memcached (--enable-memcached)
16041605

16051606
# Bind DNS compatibility Build
16061607
AC_ARG_ENABLE([bind],
@@ -1811,6 +1812,13 @@ AC_ARG_ENABLE([hitch],
18111812
[ ENABLED_HITCH=no ]
18121813
)
18131814

1815+
# memcached support
1816+
AC_ARG_ENABLE([memcached],
1817+
[AS_HELP_STRING([--enable-memcached],[Enable memcached support (default: disabled)])],
1818+
[ ENABLED_MEMCACHED=$enableval ],
1819+
[ ENABLED_MEMCACHED=no ]
1820+
)
1821+
18141822
# OpenSSL Coexist
18151823
AC_ARG_ENABLE([opensslcoexist],
18161824
[AS_HELP_STRING([--enable-opensslcoexist],[Enable coexistence of wolfssl/openssl (default: disabled)])],
@@ -6391,6 +6399,12 @@ then
63916399
AM_CFLAGS="$AM_CFLAGS -DOPENSSL_COMPATIBLE_DEFAULTS -DWOLFSSL_CIPHER_INTERNALNAME"
63926400
fi
63936401

6402+
if test "$ENABLED_MEMCACHED" = "yes"
6403+
then
6404+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_SESSION_ID_CTX"
6405+
AM_CFLAGS="$AM_CFLAGS -DHAVE_EXT_CACHE -DHAVE_MEMCACHED"
6406+
fi
6407+
63946408

63956409
if test "$ENABLED_NGINX" = "yes"|| test "x$ENABLED_HAPROXY" = "xyes" || test "x$ENABLED_LIGHTY" = "xyes"
63966410
then
@@ -9682,6 +9696,7 @@ echo " * chrony: $ENABLED_CHRONY"
96829696
echo " * strongSwan: $ENABLED_STRONGSWAN"
96839697
echo " * OpenLDAP: $ENABLED_OPENLDAP"
96849698
echo " * hitch: $ENABLED_HITCH"
9699+
echo " * memcached: $ENABLED_MEMCACHED"
96859700
echo " * ERROR_STRINGS: $ENABLED_ERROR_STRINGS"
96869701
echo " * DTLS: $ENABLED_DTLS"
96879702
echo " * DTLS v1.3: $ENABLED_DTLS13"

src/internal.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7321,10 +7321,12 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup)
73217321
ssl->alert_history.last_tx.code = -1;
73227322
ssl->alert_history.last_tx.level = -1;
73237323

7324-
#ifdef OPENSSL_EXTRA
7324+
#ifdef WOLFSSL_SESSION_ID_CTX
73257325
/* copy over application session context ID */
73267326
ssl->sessionCtxSz = ctx->sessionCtxSz;
73277327
XMEMCPY(ssl->sessionCtx, ctx->sessionCtx, ctx->sessionCtxSz);
7328+
#endif
7329+
#ifdef OPENSSL_EXTRA
73287330
ssl->cbioFlag = ctx->cbioFlag;
73297331

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

1036010362
int SendBuffered(WOLFSSL* ssl)
1036110363
{
10364+
int retryLimit = WOLFSSL_MODE_AUTO_RETRY_ATTEMPTS;
10365+
1036210366
if (ssl->CBIOSend == NULL && !WOLFSSL_IS_QUIC(ssl)) {
1036310367
WOLFSSL_MSG("Your IO Send callback is null, please set");
1036410368
return SOCKET_ERROR_E;
@@ -10379,15 +10383,22 @@ int SendBuffered(WOLFSSL* ssl)
1037910383
#endif
1038010384

1038110385
while (ssl->buffers.outputBuffer.length > 0) {
10382-
int sent = ssl->CBIOSend(ssl,
10383-
(char*)ssl->buffers.outputBuffer.buffer +
10384-
ssl->buffers.outputBuffer.idx,
10385-
(int)ssl->buffers.outputBuffer.length,
10386-
ssl->IOCB_WriteCtx);
10386+
int sent = 0;
10387+
retry:
10388+
sent = ssl->CBIOSend(ssl,
10389+
(char*)ssl->buffers.outputBuffer.buffer +
10390+
ssl->buffers.outputBuffer.idx,
10391+
(int)ssl->buffers.outputBuffer.length,
10392+
ssl->IOCB_WriteCtx);
1038710393
if (sent < 0) {
1038810394
switch (sent) {
1038910395

1039010396
case WOLFSSL_CBIO_ERR_WANT_WRITE: /* would block */
10397+
if (retryLimit > 0 && ssl->ctx->autoRetry &&
10398+
!ssl->options.handShakeDone && !ssl->options.dtls) {
10399+
retryLimit--;
10400+
goto retry;
10401+
}
1039110402
return WANT_WRITE;
1039210403

1039310404
case WOLFSSL_CBIO_ERR_CONN_RST: /* connection reset */

0 commit comments

Comments
 (0)