Skip to content

Commit 2299282

Browse files
authored
Merge pull request #6235 from kareem-wolfssl/hitch
Hitch
2 parents e4c9a73 + 8906ee9 commit 2299282

14 files changed

Lines changed: 471 additions & 31 deletions

File tree

.github/workflows/hitch.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: hitch 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-hitch
17+
install: true
18+
19+
- name: Upload built lib
20+
uses: actions/upload-artifact@v3
21+
with:
22+
name: wolf-install-hitch
23+
path: build-dir
24+
retention-days: 1
25+
26+
hitch_check:
27+
strategy:
28+
fail-fast: false
29+
matrix:
30+
# List of releases to test
31+
include:
32+
- ref: 1.7.3
33+
ignore-tests: >-
34+
test13-r82.sh test15-proxy-v2-npn.sh test39-client-cert-proxy.sh
35+
name: ${{ matrix.ref }}
36+
runs-on: ubuntu-latest
37+
needs: build_wolfssl
38+
steps:
39+
- name: Download lib
40+
uses: actions/download-artifact@v3
41+
with:
42+
name: wolf-install-hitch
43+
path: build-dir
44+
45+
- name: Checkout OSP
46+
uses: actions/checkout@v3
47+
with:
48+
repository: wolfssl/osp
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 libev-dev libssl-dev automake python3-docutils flex bison pkg-config make
56+
57+
- name: Checkout hitch
58+
uses: actions/checkout@v3
59+
with:
60+
repository: varnish/hitch
61+
ref: 1.7.3
62+
path: hitch
63+
64+
# Do this before configuring so that it only detects the updated list of
65+
# tests
66+
- if: ${{ matrix.ignore-tests }}
67+
name: Remove tests that we want to ignore
68+
working-directory: ./hitch/src/tests
69+
run: |
70+
rm ${{ matrix.ignore-tests }}
71+
72+
- name: Configure and build hitch
73+
run: |
74+
cd $GITHUB_WORKSPACE/hitch/
75+
patch -p1 < $GITHUB_WORKSPACE/osp/hitch/hitch_1.7.3.patch
76+
autoreconf -ivf
77+
SSL_CFLAGS="-I$GITHUB_WORKSPACE/build-dir/include/ -I$GITHUB_WORKSPACE/build-dir/include/wolfssl" SSL_LIBS="-L$GITHUB_WORKSPACE/build-dir/lib -lwolfssl" ./configure --with-wolfssl=$GITHUB_WORKSPACE/build-dir/ --enable-silent-rules --enable-documentation --enable-warnings --with-lex --with-yacc --prefix=$GITHUB_WORKSPACE/build-dir
78+
make -j$(nproc)
79+
80+
- name: Confirm hitch built with wolfSSL
81+
working-directory: ./hitch
82+
run: |
83+
export LD_LIBRARY_PATH=$GITHUB_WORKSPACE/build-dir/lib:$LD_LIBRARY_PATH
84+
ldd src/hitch | grep wolfssl
85+
86+
- name: Run hitch tests, skipping ignored tests
87+
working-directory: ./hitch
88+
run: |
89+
export LD_LIBRARY_PATH=$GITHUB_WORKSPACE/build-dir/lib:$LD_LIBRARY_PATH
90+
make check

.github/workflows/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ jobs:
3030
uses: ./.github/workflows/nginx.yml
3131
zephyr:
3232
uses: ./.github/workflows/zephyr.yml
33+
hitch:
34+
uses: ./.github/workflows/hitch.yml
3335
# TODO: Currently this test fails. Enable it once it becomes passing.
3436
# haproxy:
3537
# uses: ./.github/workflows/haproxy.yml

configure.ac

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,7 @@ AC_ARG_ENABLE([mcast],
13771377
# FFmpeg (--enable-ffmpeg) WOLFSSL_FFMPEG
13781378
# strongSwan (--enable-strongswan)
13791379
# OpenLDAP (--enable-openldap)
1380+
# hitch (--enable-hitch)
13801381

13811382
# Bind DNS compatibility Build
13821383
AC_ARG_ENABLE([bind],
@@ -1580,6 +1581,13 @@ AC_ARG_ENABLE([strongswan],
15801581
[ ENABLED_STRONGSWAN=no ]
15811582
)
15821583

1584+
# hitch support
1585+
AC_ARG_ENABLE([hitch],
1586+
[AS_HELP_STRING([--enable-hitch],[Enable hitch support (default: disabled)])],
1587+
[ ENABLED_HITCH=$enableval ],
1588+
[ ENABLED_HITCH=no ]
1589+
)
1590+
15831591
# OpenSSL Coexist
15841592
AC_ARG_ENABLE([opensslcoexist],
15851593
[AS_HELP_STRING([--enable-opensslcoexist],[Enable coexistence of wolfssl/openssl (default: disabled)])],
@@ -1691,7 +1699,7 @@ if test "$ENABLED_LIBWEBSOCKETS" = "yes" || test "$ENABLED_OPENVPN" = "yes" || \
16911699
test "$ENABLED_OPENRESTY" = "yes" || test "$ENABLED_RSYSLOG" = "yes" || \
16921700
test "$ENABLED_KRB" = "yes" || test "$ENABLED_CHRONY" = "yes" || \
16931701
test "$ENABLED_FFMPEG" = "yes" || test "$ENABLED_STRONGSWAN" = "yes" || \
1694-
test "$ENABLED_OPENLDAP" = "yes"
1702+
test "$ENABLED_OPENLDAP" = "yes" || test "$ENABLED_HITCH" = "yes"
16951703
then
16961704
ENABLED_OPENSSLALL="yes"
16971705
fi
@@ -3109,7 +3117,7 @@ AC_ARG_ENABLE([sessioncerts],
31093117

31103118
if test "x$ENABLED_NGINX" = "xyes" || test "x$ENABLED_OPENVPN" = "xyes" || \
31113119
test "x$ENABLED_LIGHTY" = "xyes" || test "x$ENABLED_NETSNMP" = "xyes" || \
3112-
test "x$ENABLED_STRONGSWAN" = "xyes"
3120+
test "x$ENABLED_STRONGSWAN" = "xyes" || test "x$ENABLED_HITCH" = "xyes"
31133121
then
31143122
ENABLED_SESSIONCERTS=yes
31153123
fi
@@ -3149,7 +3157,7 @@ AC_ARG_ENABLE([certgen],
31493157
if test "$ENABLED_OPENVPN" = "yes" || test "$ENABLED_OPENSSH" = "yes" || \
31503158
test "$ENABLED_BIND" = "yes" || test "$ENABLED_NTP" = "yes" || \
31513159
test "$ENABLED_CHRONY" = "yes" || test "$ENABLED_STRONGSWAN" = "yes" || \
3152-
test "$ENABLED_OPENLDAP" = "yes"
3160+
test "$ENABLED_OPENLDAP" = "yes" || test "$ENABLED_HITCH" = "yes"
31533161
then
31543162
ENABLED_CERTGEN=yes
31553163
fi
@@ -5961,6 +5969,45 @@ then
59615969
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_DES_ECB -DHAVE_EX_DATA -DWOLFSSL_KEY_GEN"
59625970
fi
59635971

5972+
if test "$ENABLED_HITCH" = "yes"
5973+
then
5974+
# Requires opensslextra make sure on
5975+
if test "x$ENABLED_OPENSSLEXTRA" = "xno" && test "x$ENABLED_OPENSSLCOEXIST" = "xno"
5976+
then
5977+
ENABLED_OPENSSLEXTRA="yes"
5978+
AM_CFLAGS="$AM_CFLAGS -DOPENSSL_EXTRA"
5979+
fi
5980+
5981+
# Requires OCSP make sure on
5982+
if test "x$ENABLED_OCSP" = "xno"
5983+
then
5984+
ENABLED_OCSP="yes"
5985+
fi
5986+
5987+
# Requires ALPN
5988+
if test "x$ENABLED_ALPN" = "xno"
5989+
then
5990+
ENABLED_ALPN="yes"
5991+
AM_CFLAGS="$AM_CFLAGS -DHAVE_TLS_EXTENSIONS -DHAVE_ALPN"
5992+
fi
5993+
5994+
if test "x$ENABLED_KEYGEN" = "xno"
5995+
then
5996+
ENABLED_KEYGEN="yes"
5997+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_KEY_GEN"
5998+
fi
5999+
6000+
# Requires sessioncerts make sure on
6001+
if test "x$ENABLED_SESSIONCERTS" = "xno"
6002+
then
6003+
ENABLED_SESSIONCERTS="yes"
6004+
AM_CFLAGS="$AM_CFLAGS -DSESSION_CERTS"
6005+
fi
6006+
6007+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_HITCH -DHAVE_EX_DATA -DWOLFSSL_SIGNER_DER_CERT"
6008+
AM_CFLAGS="$AM_CFLAGS -DOPENSSL_COMPATIBLE_DEFAULTS -DWOLFSSL_CIPHER_INTERNALNAME"
6009+
fi
6010+
59646011

59656012
if test "$ENABLED_NGINX" = "yes"|| test "x$ENABLED_HAPROXY" = "xyes" || test "x$ENABLED_LIGHTY" = "xyes"
59666013
then
@@ -8003,7 +8050,7 @@ if test "$ENABLED_OPENSSH" = "yes" || test "$ENABLED_NGINX" = "yes" || \
80038050
test "$ENABLED_LIBWEBSOCKETS" = "yes" || \
80048051
test "x$ENABLED_LIGHTY" = "xyes" || test "$ENABLED_LIBSSH2" = "yes" || \
80058052
test "x$ENABLED_NTP" = "xyes" || test "$ENABLED_RSYSLOG" = "yes" || \
8006-
test "$ENABLED_OPENLDAP" = "yes"
8053+
test "$ENABLED_OPENLDAP" = "yes" || test "$ENABLED_HITCH" = "yes"
80078054
then
80088055
ENABLED_OPENSSLEXTRA="yes"
80098056
fi
@@ -9189,6 +9236,7 @@ echo " * SIGNAL: $ENABLED_SIGNAL"
91899236
echo " * chrony: $ENABLED_CHRONY"
91909237
echo " * strongSwan: $ENABLED_STRONGSWAN"
91919238
echo " * OpenLDAP: $ENABLED_OPENLDAP"
9239+
echo " * hitch: $ENABLED_HITCH"
91929240
echo " * ERROR_STRINGS: $ENABLED_ERROR_STRINGS"
91939241
echo " * DTLS: $ENABLED_DTLS"
91949242
echo " * DTLS v1.3: $ENABLED_DTLS13"

src/bio.c

Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,32 @@ long wolfSSL_BIO_get_mem_ptr(WOLFSSL_BIO *bio, WOLFSSL_BUF_MEM **ptr)
11551155
return ret;
11561156
}
11571157

1158+
#ifdef OPENSSL_ALL
1159+
int wolfSSL_BIO_set_mem_buf(WOLFSSL_BIO* bio, WOLFSSL_BUF_MEM* bufMem,
1160+
int closeFlag)
1161+
{
1162+
if (!bio || !bufMem ||
1163+
(closeFlag != BIO_NOCLOSE && closeFlag != BIO_CLOSE))
1164+
return BAD_FUNC_ARG;
1165+
1166+
if (bio->mem_buf)
1167+
if (closeFlag == BIO_CLOSE)
1168+
wolfSSL_BUF_MEM_free(bio->mem_buf);
1169+
1170+
bio->mem_buf = bufMem;
1171+
bio->shutdown = closeFlag;
1172+
1173+
bio->wrSz = (int)bio->mem_buf->length;
1174+
bio->wrSzReset = bio->wrSz;
1175+
bio->num = (int)bio->mem_buf->max;
1176+
bio->ptr = bio->mem_buf->data;
1177+
bio->wrIdx = 0;
1178+
bio->rdIdx = 0;
1179+
1180+
return WOLFSSL_SUCCESS;
1181+
}
1182+
#endif
1183+
11581184
WOLFSSL_API long wolfSSL_BIO_int_ctrl(WOLFSSL_BIO *bp, int cmd, long larg, int iarg)
11591185
{
11601186
(void) bp;
@@ -2334,14 +2360,13 @@ int wolfSSL_BIO_flush(WOLFSSL_BIO* bio)
23342360
return WOLFSSL_SUCCESS;
23352361
}
23362362

2337-
WOLFSSL_BIO* wolfSSL_BIO_new_ssl_connect(WOLFSSL_CTX* ctx)
2363+
WOLFSSL_BIO* wolfSSL_BIO_new_ssl(WOLFSSL_CTX* ctx, int client)
23382364
{
23392365
WOLFSSL* ssl = NULL;
23402366
WOLFSSL_BIO* sslBio = NULL;
2341-
WOLFSSL_BIO* connBio = NULL;
23422367
int err = 0;
23432368

2344-
WOLFSSL_ENTER("wolfSSL_BIO_new_ssl_connect");
2369+
WOLFSSL_ENTER("wolfSSL_BIO_new_ssl");
23452370

23462371
if (ctx == NULL) {
23472372
WOLFSSL_MSG("ctx is NULL.");
@@ -2362,11 +2387,46 @@ int wolfSSL_BIO_flush(WOLFSSL_BIO* bio)
23622387
err = 1;
23632388
}
23642389
}
2390+
if (err == 0) {
2391+
if (!client)
2392+
wolfSSL_set_accept_state(ssl);
2393+
else
2394+
wolfSSL_set_connect_state(ssl);
2395+
}
23652396
if (err == 0 && wolfSSL_BIO_set_ssl(sslBio, ssl, BIO_CLOSE) !=
23662397
WOLFSSL_SUCCESS) {
23672398
WOLFSSL_MSG("Failed to set SSL pointer in BIO.");
23682399
err = 1;
23692400
}
2401+
2402+
if (err) {
2403+
wolfSSL_free(ssl);
2404+
wolfSSL_BIO_free(sslBio);
2405+
}
2406+
2407+
return sslBio;
2408+
}
2409+
2410+
WOLFSSL_BIO* wolfSSL_BIO_new_ssl_connect(WOLFSSL_CTX* ctx)
2411+
{
2412+
WOLFSSL_BIO* sslBio = NULL;
2413+
WOLFSSL_BIO* connBio = NULL;
2414+
int err = 0;
2415+
2416+
WOLFSSL_ENTER("wolfSSL_BIO_new_ssl_connect");
2417+
2418+
if (ctx == NULL) {
2419+
WOLFSSL_MSG("ctx is NULL.");
2420+
err = 1;
2421+
}
2422+
2423+
if (err == 0) {
2424+
sslBio = wolfSSL_BIO_new_ssl(ctx, 1);
2425+
if (sslBio == NULL) {
2426+
WOLFSSL_MSG("Failed to create SSL BIO.");
2427+
err = 1;
2428+
}
2429+
}
23702430
if (err == 0) {
23712431
connBio = wolfSSL_BIO_new(wolfSSL_BIO_s_socket());
23722432
if (connBio == NULL) {
@@ -2379,7 +2439,6 @@ int wolfSSL_BIO_flush(WOLFSSL_BIO* bio)
23792439
}
23802440

23812441
if (err == 1) {
2382-
wolfSSL_free(ssl);
23832442
wolfSSL_BIO_free(sslBio);
23842443
sslBio = NULL;
23852444
wolfSSL_BIO_free(connBio);
@@ -3219,6 +3278,26 @@ int wolfSSL_BIO_should_retry(WOLFSSL_BIO *bio)
32193278
return ret;
32203279
}
32213280

3281+
int wolfSSL_BIO_should_read(WOLFSSL_BIO *bio)
3282+
{
3283+
int ret = 0;
3284+
if (bio != NULL) {
3285+
ret = (int)(bio->flags & WOLFSSL_BIO_FLAG_READ);
3286+
}
3287+
3288+
return ret;
3289+
}
3290+
3291+
int wolfSSL_BIO_should_write(WOLFSSL_BIO *bio)
3292+
{
3293+
int ret = 0;
3294+
if (bio != NULL) {
3295+
ret = (int)(bio->flags & WOLFSSL_BIO_FLAG_WRITE);
3296+
}
3297+
3298+
return ret;
3299+
}
3300+
32223301
#endif /* OPENSSL_ALL */
32233302

32243303
#endif /* WOLFSSL_BIO_INCLUDED */

0 commit comments

Comments
 (0)