Skip to content

Commit d545253

Browse files
authored
Merge pull request #7594 from JacobBarthelmeh/socat
Updating socat version support
2 parents 118d2cc + 9175355 commit d545253

10 files changed

Lines changed: 187 additions & 7 deletions

File tree

.github/workflows/socat.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: socat Tests
2+
3+
# START OF COMMON SECTION
4+
on:
5+
push:
6+
branches: [ 'master', 'main', 'release/**' ]
7+
pull_request:
8+
branches: [ '*' ]
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
# END OF COMMON SECTION
14+
15+
jobs:
16+
build_wolfssl:
17+
name: Build wolfSSL
18+
runs-on: ubuntu-latest
19+
timeout-minutes: 4
20+
steps:
21+
- name: Build wolfSSL
22+
uses: wolfSSL/actions-build-autotools-project@v1
23+
with:
24+
path: wolfssl
25+
configure: --enable-maxfragment --enable-opensslall --enable-opensslextra --enable-dtls --enable-oldtls --enable-tlsv10 --enable-ipv6 'CPPFLAGS=-DWOLFSSL_NO_DTLS_SIZE_CHECK -DOPENSSL_COMPATIBLE_DEFAULTS'
26+
install: true
27+
28+
- name: Upload built lib
29+
uses: actions/upload-artifact@v4
30+
with:
31+
name: wolf-install-socat
32+
path: build-dir
33+
retention-days: 3
34+
35+
36+
socat_check:
37+
strategy:
38+
fail-fast: false
39+
runs-on: ubuntu-latest
40+
# This should be a safe limit for the tests to run.
41+
timeout-minutes: 30
42+
needs: build_wolfssl
43+
steps:
44+
- name: Install prereqs
45+
run:
46+
sudo apt-get install build-essential autoconf libtool pkg-config clang libc++-dev
47+
48+
- name: Download lib
49+
uses: actions/download-artifact@v4
50+
with:
51+
name: wolf-install-socat
52+
path: build-dir
53+
54+
- name: Download socat
55+
run: curl -O http://www.dest-unreach.org/socat/download/socat-1.8.0.0.tar.gz && tar xvf socat-1.8.0.0.tar.gz
56+
57+
- name: Checkout OSP
58+
uses: actions/checkout@v4
59+
with:
60+
repository: wolfssl/osp
61+
path: osp
62+
63+
- name: Build socat
64+
working-directory: ./socat-1.8.0.0
65+
run: |
66+
patch -p1 < ../osp/socat/1.8.0.0/socat-1.8.0.0.patch
67+
autoreconf -vfi
68+
./configure --with-wolfssl=$GITHUB_WORKSPACE/build-dir
69+
make
70+
71+
- name: Run socat tests
72+
working-directory: ./socat-1.8.0.0
73+
run: |
74+
export LD_LIBRARY_PATH=$GITHUB_WORKSPACE/build-dir/lib:$LD_LIBRARY_PATH
75+
export SHELL=/bin/bash
76+
SOCAT=$GITHUB_WORKSPACE/socat-1.8.0.0/socat ./test.sh -t 0.5 --expect-fail 146,216,309,310,386,399,402,459,460,467,468,478,492,528,530

src/ssl.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14961,6 +14961,17 @@ int wolfSSL_COMP_add_compression_method(int method, void* data)
1496114961
}
1496214962
#endif
1496314963

14964+
#ifndef NO_WOLFSSL_STUB
14965+
const char* wolfSSL_COMP_get_name(const void* comp)
14966+
{
14967+
static const char ret[] = "not supported";
14968+
14969+
(void)comp;
14970+
WOLFSSL_STUB("wolfSSL_COMP_get_name");
14971+
return ret;
14972+
}
14973+
#endif
14974+
1496414975
/* wolfSSL_set_dynlock_create_callback
1496514976
* CRYPTO_set_dynlock_create_callback has been deprecated since openSSL 1.0.1.
1496614977
* This function exists for compatibility purposes because wolfSSL satisfies

src/ssl_sess.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,20 @@ long wolfSSL_CTX_set_session_cache_mode(WOLFSSL_CTX* ctx, long mode)
747747
}
748748

749749
#ifdef OPENSSL_EXTRA
750+
#ifdef HAVE_MAX_FRAGMENT
751+
/* return the max fragment size set when handshake was negotiated */
752+
unsigned char wolfSSL_SESSION_get_max_fragment_length(WOLFSSL_SESSION* session)
753+
{
754+
session = ClientSessionToSession(session);
755+
if (session == NULL) {
756+
return 0;
757+
}
758+
759+
return session->mfl;
760+
}
761+
#endif
762+
763+
750764
/* Get the session cache mode for CTX
751765
*
752766
* ctx WOLFSSL_CTX struct to get cache mode from

src/tls.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2997,6 +2997,9 @@ static int TLSX_MFL_Parse(WOLFSSL* ssl, const byte* input, word16 length,
29972997
WOLFSSL_ERROR_VERBOSE(UNKNOWN_MAX_FRAG_LEN_E);
29982998
return UNKNOWN_MAX_FRAG_LEN_E;
29992999
}
3000+
if (ssl->session != NULL) {
3001+
ssl->session->mfl = *input;
3002+
}
30003003

30013004
#ifndef NO_WOLFSSL_SERVER
30023005
if (isRequest) {

src/x509.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13051,13 +13051,16 @@ static int wolfSSL_EscapeString_RFC2253(char* in, word32 inSz,
1305113051
* RFC22523 currently implemented.
1305213052
* XN_FLAG_DN_REV - print name reversed. Automatically done by
1305313053
* XN_FLAG_RFC2253.
13054+
* XN_FLAG_SPC_EQ - spaces before and after '=' character
1305413055
*
1305513056
* Returns WOLFSSL_SUCCESS (1) on success, WOLFSSL_FAILURE (0) on failure.
1305613057
*/
1305713058
int wolfSSL_X509_NAME_print_ex(WOLFSSL_BIO* bio, WOLFSSL_X509_NAME* name,
1305813059
int indent, unsigned long flags)
1305913060
{
1306013061
int i, count = 0, nameStrSz = 0, escapeSz = 0;
13062+
int eqSpace = 0;
13063+
char eqStr[4];
1306113064
char* tmp = NULL;
1306213065
char* nameStr = NULL;
1306313066
const char *buf = NULL;
@@ -13070,6 +13073,15 @@ int wolfSSL_X509_NAME_print_ex(WOLFSSL_BIO* bio, WOLFSSL_X509_NAME* name,
1307013073
if ((name == NULL) || (name->sz == 0) || (bio == NULL))
1307113074
return WOLFSSL_FAILURE;
1307213075

13076+
XMEMSET(eqStr, 0, sizeof(eqStr));
13077+
if (flags & XN_FLAG_SPC_EQ) {
13078+
eqSpace = 2;
13079+
XSTRNCPY(eqStr, " = ", 4);
13080+
}
13081+
else {
13082+
XSTRNCPY(eqStr, "=", 4);
13083+
}
13084+
1307313085
for (i = 0; i < indent; i++) {
1307413086
if (wolfSSL_BIO_write(bio, " ", 1) != 1)
1307513087
return WOLFSSL_FAILURE;
@@ -13114,32 +13126,33 @@ int wolfSSL_X509_NAME_print_ex(WOLFSSL_BIO* bio, WOLFSSL_X509_NAME* name,
1311413126
if (len == 0 || buf == NULL)
1311513127
return WOLFSSL_FAILURE;
1311613128

13117-
tmpSz = nameStrSz + len + 4; /* + 4 for '=', comma space and '\0'*/
13129+
/* + 4 for '=', comma space and '\0'*/
13130+
tmpSz = nameStrSz + len + 4 + eqSpace;
1311813131
tmp = (char*)XMALLOC(tmpSz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
1311913132
if (tmp == NULL) {
1312013133
return WOLFSSL_FAILURE;
1312113134
}
1312213135

1312313136
if (i < count - 1) {
13124-
if (XSNPRINTF(tmp, (size_t)tmpSz, "%s=%s, ", buf, nameStr)
13137+
if (XSNPRINTF(tmp, (size_t)tmpSz, "%s%s%s, ", buf, eqStr, nameStr)
1312513138
>= tmpSz)
1312613139
{
1312713140
WOLFSSL_MSG("buffer overrun");
1312813141
XFREE(tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
1312913142
return WOLFSSL_FAILURE;
1313013143
}
1313113144

13132-
tmpSz = len + nameStrSz + 3; /* 3 for '=', comma space */
13145+
tmpSz = len + nameStrSz + 3 + eqSpace; /* 3 for '=', comma space */
1313313146
}
1313413147
else {
13135-
if (XSNPRINTF(tmp, (size_t)tmpSz, "%s=%s", buf, nameStr)
13148+
if (XSNPRINTF(tmp, (size_t)tmpSz, "%s%s%s", buf, eqStr, nameStr)
1313613149
>= tmpSz)
1313713150
{
1313813151
WOLFSSL_MSG("buffer overrun");
1313913152
XFREE(tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
1314013153
return WOLFSSL_FAILURE;
1314113154
}
13142-
tmpSz = len + nameStrSz + 1; /* 1 for '=' */
13155+
tmpSz = len + nameStrSz + 1 + eqSpace; /* 1 for '=' */
1314313156
if (bio->type != WOLFSSL_BIO_FILE && bio->type != WOLFSSL_BIO_MEMORY)
1314413157
++tmpSz; /* include the terminating null when not writing to a
1314513158
* file.

tests/api.c

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11311,6 +11311,31 @@ static int test_wolfSSL_UseMaxFragment(void)
1131111311

1131211312
wolfSSL_free(ssl);
1131311313
wolfSSL_CTX_free(ctx);
11314+
11315+
#if defined(OPENSSL_EXTRA) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
11316+
/* check negotiated max fragment size */
11317+
{
11318+
WOLFSSL *ssl_c = NULL;
11319+
WOLFSSL *ssl_s = NULL;
11320+
struct test_memio_ctx test_ctx;
11321+
WOLFSSL_CTX *ctx_c = NULL;
11322+
WOLFSSL_CTX *ctx_s = NULL;
11323+
11324+
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
11325+
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
11326+
wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
11327+
ExpectIntEQ(wolfSSL_UseMaxFragment(ssl_c, WOLFSSL_MFL_2_8),
11328+
WOLFSSL_SUCCESS);
11329+
ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
11330+
ExpectIntEQ(SSL_SESSION_get_max_fragment_length(
11331+
wolfSSL_get_session(ssl_c)), WOLFSSL_MFL_2_8);
11332+
11333+
wolfSSL_free(ssl_c);
11334+
wolfSSL_free(ssl_s);
11335+
wolfSSL_CTX_free(ctx_c);
11336+
wolfSSL_CTX_free(ctx_s);
11337+
}
11338+
#endif
1131411339
#endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
1131511340
#endif
1131611341
return EXPECT_RESULT();
@@ -35030,6 +35055,7 @@ static int test_wolfSSL_X509_NAME_print_ex(void)
3503035055
X509_NAME* name = NULL;
3503135056

3503235057
const char* expNormal = "C=US, CN=wolfssl.com";
35058+
const char* expEqSpace = "C = US, CN = wolfssl.com";
3503335059
const char* expReverse = "CN=wolfssl.com, C=US";
3503435060

3503535061
const char* expNotEscaped = "C= US,+\"\\ , CN=#wolfssl.com<>;";
@@ -35087,6 +35113,17 @@ static int test_wolfSSL_X509_NAME_print_ex(void)
3508735113
BIO_free(membio);
3508835114
membio = NULL;
3508935115

35116+
/* Test with XN_FLAG_ONELINE which should enable XN_FLAG_SPC_EQ for
35117+
spaces aroun '=' */
35118+
ExpectNotNull(membio = BIO_new(BIO_s_mem()));
35119+
ExpectIntEQ(X509_NAME_print_ex(membio, name, 0, XN_FLAG_ONELINE),
35120+
WOLFSSL_SUCCESS);
35121+
ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
35122+
ExpectIntEQ(memSz, XSTRLEN(expEqSpace));
35123+
ExpectIntEQ(XSTRNCMP((char*)mem, expEqSpace, XSTRLEN(expEqSpace)), 0);
35124+
BIO_free(membio);
35125+
membio = NULL;
35126+
3509035127
/* Test flags: XN_FLAG_RFC2253 - should be reversed */
3509135128
ExpectNotNull(membio = BIO_new(BIO_s_mem()));
3509235129
ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
@@ -49863,6 +49900,7 @@ static int test_wolfSSL_CTX_sess_set_remove_cb(void)
4986349900
/* Both should have been allocated */
4986449901
ExpectIntEQ(clientSessRemCountMalloc, 1);
4986549902
ExpectIntEQ(serverSessRemCountMalloc, 1);
49903+
4986649904
/* This should not be called yet. Session wasn't evicted from cache yet. */
4986749905
ExpectIntEQ(clientSessRemCountFree, 0);
4986849906
#if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \
@@ -49889,7 +49927,6 @@ static int test_wolfSSL_CTX_sess_set_remove_cb(void)
4988949927
ExpectIntEQ(SSL_CTX_remove_session(serverSessCtx, serverSess), 0);
4989049928
ExpectNull(SSL_SESSION_get_ex_data(serverSess, serverSessRemIdx));
4989149929
ExpectIntEQ(serverSessRemCountFree, 1);
49892-
4989349930
/* Need to free the references that we kept */
4989449931
SSL_CTX_free(serverSessCtx);
4989549932
SSL_SESSION_free(serverSess);
@@ -65220,8 +65257,15 @@ static int test_stubs_are_stubs(void)
6522065257
CHECKZERO_RET(wolfSSL_CTX_sess_misses, ctx, ctxN);
6522165258
CHECKZERO_RET(wolfSSL_CTX_sess_timeouts, ctx, ctxN);
6522265259

65260+
/* when implemented this should take WOLFSSL object insted, right now
65261+
* always returns 0 */
65262+
ExpectIntEQ(SSL_get_current_expansion(NULL), 0);
65263+
6522365264
wolfSSL_CTX_free(ctx);
6522465265
ctx = NULL;
65266+
65267+
ExpectStrEQ(SSL_COMP_get_name(NULL), "not supported");
65268+
ExpectIntEQ(SSL_get_current_expansion(), 0);
6522565269
#endif /* OPENSSL_EXTRA && !NO_WOLFSSL_STUB && (!NO_WOLFSSL_CLIENT ||
6522665270
* !NO_WOLFSSL_SERVER) */
6522765271
return EXPECT_RESULT();
@@ -69055,6 +69099,7 @@ static int test_wolfSSL_dtls_stateless_maxfrag(void)
6905569099
/* CH without cookie shouldn't change state */
6905669100
ExpectIntEQ(ssl_s->max_fragment, max_fragment);
6905769101
ExpectIntNE(test_ctx.c_len, 0);
69102+
6905869103
/* consume HRR from buffer */
6905969104
test_ctx.c_len = 0;
6906069105
ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);

wolfssl/internal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4474,6 +4474,10 @@ struct WOLFSSL_SESSION {
44744474
#endif
44754475
#ifdef HAVE_EX_DATA
44764476
WOLFSSL_CRYPTO_EX_DATA ex_data;
4477+
#endif
4478+
#ifdef HAVE_MAX_FRAGMENT
4479+
byte mfl; /* max fragment length negotiated i.e.
4480+
* WOLFSSL_MFL_2_8 (6) */
44774481
#endif
44784482
byte isSetup:1;
44794483
};

wolfssl/openssl/ssl.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,8 @@ typedef STACK_OF(ACCESS_DESCRIPTION) AUTHORITY_INFO_ACCESS;
367367
#define SSL_SESSION_dup wolfSSL_SESSION_dup
368368
#define SSL_SESSION_free wolfSSL_SESSION_free
369369
#define SSL_SESSION_set_cipher wolfSSL_SESSION_set_cipher
370+
#define SSL_SESSION_get_max_fragment_length \
371+
wolfSSL_SESSION_get_max_fragment_length
370372
#define SSL_is_init_finished wolfSSL_is_init_finished
371373

372374
#define SSL_SESSION_set1_id wolfSSL_SESSION_set1_id
@@ -834,6 +836,10 @@ wolfSSL_X509_STORE_set_verify_cb((WOLFSSL_X509_STORE *)(s), (WOLFSSL_X509_STORE_
834836
#define COMP_rle wolfSSL_COMP_rle
835837
#define SSL_COMP_add_compression_method wolfSSL_COMP_add_compression_method
836838

839+
#define SSL_get_current_compression(ssl) 0
840+
#define SSL_get_current_expansion(ssl) 0
841+
#define SSL_COMP_get_name wolfSSL_COMP_get_name
842+
837843
#define SSL_get_ex_new_index wolfSSL_get_ex_new_index
838844
#define RSA_get_ex_new_index wolfSSL_get_ex_new_index
839845

@@ -1227,6 +1233,7 @@ typedef WOLFSSL_SRTP_PROTECTION_PROFILE SRTP_PROTECTION_PROFILE;
12271233

12281234
#define TLSEXT_STATUSTYPE_ocsp 1
12291235

1236+
#define TLSEXT_max_fragment_length_DISABLED WOLFSSL_MFL_DISABLED
12301237
#define TLSEXT_max_fragment_length_512 WOLFSSL_MFL_2_9
12311238
#define TLSEXT_max_fragment_length_1024 WOLFSSL_MFL_2_10
12321239
#define TLSEXT_max_fragment_length_2048 WOLFSSL_MFL_2_11

wolfssl/openssl/x509.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
#define X509_FLAG_NO_IDS (1UL << 12)
5151

5252
#define XN_FLAG_FN_SN 0
53-
#define XN_FLAG_ONELINE 0
5453
#define XN_FLAG_COMPAT 0
5554
#define XN_FLAG_RFC2253 1
5655
#define XN_FLAG_SEP_COMMA_PLUS (1 << 16)
@@ -68,6 +67,7 @@
6867
#define XN_FLAG_FN_ALIGN (1 << 25)
6968

7069
#define XN_FLAG_MULTILINE 0xFFFF
70+
#define XN_FLAG_ONELINE (XN_FLAG_SEP_CPLUS_SPC | XN_FLAG_SPC_EQ | XN_FLAG_FN_SN)
7171

7272
/*
7373
* All of these aren't actually used in wolfSSL. Some are included to

wolfssl/ssl.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,6 +1682,11 @@ WOLFSSL_API int wolfSSL_set_session_id_context(WOLFSSL* ssl, const unsigned cha
16821682
WOLFSSL_API void wolfSSL_set_connect_state(WOLFSSL* ssl);
16831683
WOLFSSL_API void wolfSSL_set_accept_state(WOLFSSL* ssl);
16841684
WOLFSSL_API int wolfSSL_session_reused(WOLFSSL* ssl);
1685+
#ifdef OPENSSL_EXTRA
1686+
/* using unsigned char instead of uint8_t here to avoid stdint include */
1687+
WOLFSSL_API unsigned char wolfSSL_SESSION_get_max_fragment_length(
1688+
WOLFSSL_SESSION* session);
1689+
#endif
16851690
WOLFSSL_API int wolfSSL_SESSION_up_ref(WOLFSSL_SESSION* session);
16861691
WOLFSSL_API WOLFSSL_SESSION* wolfSSL_SESSION_dup(WOLFSSL_SESSION* session);
16871692
WOLFSSL_API WOLFSSL_SESSION* wolfSSL_SESSION_new(void);
@@ -3917,6 +3922,7 @@ WOLFSSL_API int wolfSSL_ALPN_FreePeerProtocol(WOLFSSL* ssl, char **list);
39173922

39183923
/* Fragment lengths */
39193924
enum {
3925+
WOLFSSL_MFL_DISABLED = 0,
39203926
WOLFSSL_MFL_2_9 = 1, /* 512 bytes */
39213927
WOLFSSL_MFL_2_10 = 2, /* 1024 bytes */
39223928
WOLFSSL_MFL_2_11 = 3, /* 2048 bytes */
@@ -5201,6 +5207,7 @@ WOLFSSL_API int wolfSSL_i2a_ASN1_OBJECT(WOLFSSL_BIO *bp, WOLFSSL_ASN1_OBJECT *a)
52015207
WOLFSSL_API int wolfSSL_i2d_ASN1_OBJECT(WOLFSSL_ASN1_OBJECT *a, unsigned char **pp);
52025208
WOLFSSL_API void SSL_CTX_set_tmp_dh_callback(WOLFSSL_CTX *ctx, WOLFSSL_DH *(*dh) (WOLFSSL *ssl, int is_export, int keylength));
52035209
WOLFSSL_API WOLF_STACK_OF(SSL_COMP) *SSL_COMP_get_compression_methods(void);
5210+
WOLFSSL_API const char* wolfSSL_COMP_get_name(const void* comp);
52045211
WOLFSSL_API int wolfSSL_X509_STORE_load_locations(WOLFSSL_X509_STORE *str, const char *file, const char *dir);
52055212
WOLFSSL_API int wolfSSL_X509_STORE_add_crl(WOLFSSL_X509_STORE *ctx, WOLFSSL_X509_CRL *x);
52065213
WOLFSSL_API int wolfSSL_sk_SSL_CIPHER_num(const WOLF_STACK_OF(WOLFSSL_CIPHER)* p);

0 commit comments

Comments
 (0)