From 5c4801fca1d05e15fe5c4118ddcd723a7a48fdb0 Mon Sep 17 00:00:00 2001 From: JacobBarthelmeh Date: Mon, 25 Aug 2025 17:03:10 -0600 Subject: [PATCH 1/6] update mono build README instructions and add test case --- .github/workflows/mono.yml | 136 +++++++++++++++++++++++++++++++++++++ wrapper/CSharp/README.md | 7 +- 2 files changed, 140 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/mono.yml diff --git a/.github/workflows/mono.yml b/.github/workflows/mono.yml new file mode 100644 index 000000000..d9aa1ba8d --- /dev/null +++ b/.github/workflows/mono.yml @@ -0,0 +1,136 @@ +name: Linux Mono C# Build Test + +# START OF COMMON SECTION +on: + push: + branches: [ 'master', 'main', 'release/**' ] + pull_request: + branches: [ '*' ] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true +# END OF COMMON SECTION + +jobs: + build_wolfssl: + name: Build wolfSSL C# Wrapper + if: github.repository_owner == 'wolfssl' + runs-on: ubuntu-24.04 + timeout-minutes: 10 + steps: + + # Build wolfSSL using the user_settings.h from the C# wrapper directory + - name: Build wolfSSL + uses: wolfSSL/actions-build-autotools-project@v1 + with: + path: wolfssl + configure: --enable-usersettings CPPFLAGS=-I$GITHUB_WORKSPACE/wolfssl/wrapper/CSharp + install: true + + - name: Install mono-complete + run: | + sudo apt-get update + sudo apt-get install -y mono-complete + + - name: Build and run wolfCrypt test wrapper + working-directory: wolfssl/wrapper/CSharp + env: + LD_LIBRARY_PATH: $GITHUB_WORKSPACE/build-dir/lib + run: | + mcs wolfCrypt-Test/wolfCrypt-Test.cs wolfSSL_CSharp/wolfCrypt.cs wolfSSL_CSharp/wolfSSL.cs wolfSSL_CSharp/X509.cs -OUT:wolfcrypttest.exe + mono wolfcrypttest.exe + + - name: Build wolfSSL client/server test + working-directory: wolfssl/wrapper/CSharp + env: + LD_LIBRARY_PATH: $GITHUB_WORKSPACE/build-dir/lib + run: | + mcs wolfSSL_CSharp/wolfSSL.cs wolfSSL_CSharp/X509.cs wolfSSL-TLS-Server/wolfSSL-TLS-Server.cs -OUT:server.exe + mcs wolfSSL_CSharp/wolfCrypt.cs wolfSSL-TLS-Client/wolfSSL-TLS-Client.cs wolfSSL_CSharp/wolfSSL.cs wolfSSL_CSharp/X509.cs -OUT:client.exe + + - name: Test wolfSSL client/server communication + working-directory: wolfssl/wrapper/CSharp + env: + LD_LIBRARY_PATH: $GITHUB_WORKSPACE/build-dir/lib + run: | + # Start server in background and capture its PID + timeout 10s mono server.exe > server.log 2>&1 & + SERVER_PID=$! + + # Wait for server to start + sleep 2 + + # Run client and capture output + timeout 5s mono client.exe > client.log 2>&1 + CLIENT_EXIT_CODE=$? + + # Wait a moment for server to process + sleep 1 + + # Kill server + kill $SERVER_PID 2>/dev/null || true + + # Check if client completed successfully (exit code 0) + if [ $CLIENT_EXIT_CODE -eq 0 ]; then + echo "Client completed successfully" + else + echo "Client failed with exit code $CLIENT_EXIT_CODE" + cat client.log + exit 1 + fi + + # Check for success indicators in logs + if grep -q "SSL version is" client.log && grep -q "SSL cipher suite is" client.log; then + echo "TLS handshake successful - SSL version and cipher suite detected" + else + echo "TLS handshake failed - no SSL version/cipher detected" + echo "Client log:" + cat client.log + echo "Server log:" + cat server.log + exit 1 + fi + + - name: Test SNI functionality + working-directory: wolfssl/wrapper/CSharp + env: + LD_LIBRARY_PATH: $GITHUB_WORKSPACE/build-dir/lib + run: | + # Start server with SNI support in background + timeout 10s mono server.exe -S > server_sni.log 2>&1 & + SERVER_PID=$! + + # Wait for server to start + sleep 2 + + # Run client with SNI and capture output + timeout 5s mono client.exe -S localhost > client_sni.log 2>&1 + CLIENT_EXIT_CODE=$? + + # Wait a moment for server to process + sleep 1 + + # Kill server + kill $SERVER_PID 2>/dev/null || true + + # Check if client completed successfully + if [ $CLIENT_EXIT_CODE -eq 0 ]; then + echo "SNI client completed successfully" + else + echo "SNI client failed with exit code $CLIENT_EXIT_CODE" + cat client_sni.log + exit 1 + fi + + # Check for SNI success indicators + if grep -q "SSL version is" client_sni.log && grep -q "SSL cipher suite is" client_sni.log; then + echo "SNI TLS handshake successful" + else + echo "SNI TLS handshake failed" + echo "Client log:" + cat client_sni.log + echo "Server log:" + cat server_sni.log + exit 1 + fi diff --git a/wrapper/CSharp/README.md b/wrapper/CSharp/README.md index 537e6cc9b..ac15e0c33 100644 --- a/wrapper/CSharp/README.md +++ b/wrapper/CSharp/README.md @@ -42,7 +42,8 @@ apt-get install mono-complete ``` ./autogen.sh -./configure --enable-keygen --enable-eccencrypt --enable-ed25519 --enable-curve25519 --enable-aesgcm +cp wrapper/CSharp/user_settings.h . +./configure --enable-usersettings make make check sudo make install @@ -55,7 +56,7 @@ From the `wrapper/CSharp` directory (`cd wrapper/CSharp`): Compile wolfCrypt test: ``` -mcs wolfCrypt-Test/wolfCrypt-Test.cs wolfSSL_CSharp/wolfCrypt.cs -OUT:wolfcrypttest.exe +mcs wolfCrypt-Test/wolfCrypt-Test.cs wolfSSL_CSharp/wolfCrypt.cs wolfSSL_CSharp/wolfSSL.cs wolfSSL_CSharp/X509.cs -OUT:wolfcrypttest.exe mono wolfcrypttest.exe ``` @@ -72,7 +73,7 @@ mcs wolfSSL_CSharp/wolfSSL.cs wolfSSL_CSharp/X509.cs wolfSSL-TLS-Server/wolfSSL- Compile client: ``` -mcs wolfSSL_CSharp/wolfSSL.cs wolfSSL_CSharp/X509.cs wolfSSL-TLS-Client/wolfSSL-TLS-Client.cs -OUT:client.exe +mcs wolfSSL_CSharp/wolfCrypt.cs wolfSSL-TLS-Client/wolfSSL-TLS-Client.cs wolfSSL_CSharp/wolfSSL.cs wolfSSL_CSharp/X509.cs -OUT:client.exe ``` #### Run the example From 33030c286288b13728c493df49d3d7cde58e72cc Mon Sep 17 00:00:00 2001 From: JacobBarthelmeh Date: Tue, 7 Oct 2025 16:27:18 -0600 Subject: [PATCH 2/6] fix for macro guard in dtls test case --- tests/api/test_dtls.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/api/test_dtls.c b/tests/api/test_dtls.c index 04140d807..8edebe4ca 100644 --- a/tests/api/test_dtls.c +++ b/tests/api/test_dtls.c @@ -50,13 +50,15 @@ int test_dtls12_basic_connection_id(void) #ifdef HAVE_AESCCM "AES128-CCM8", #endif +#endif /* WOLFSSL_AES_128 && WOLFSSL_STATIC_RSA */ +#if defined(WOLFSSL_AES_128) "DHE-RSA-AES128-SHA256", "ECDHE-RSA-AES128-SHA256", #ifdef HAVE_AESGCM "DHE-RSA-AES128-GCM-SHA256", "ECDHE-RSA-AES128-GCM-SHA256", #endif -#endif /* WOLFSSL_AES_128 && WOLFSSL_STATIC_RSA */ +#endif /* WOLFSSL_AES_128 */ #endif /* NO_SHA256 */ #endif /* NO_RSA */ #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305) && !defined(HAVE_FIPS) From f5898d5f5d078d976e6c5088bc7640be2d63bb53 Mon Sep 17 00:00:00 2001 From: JacobBarthelmeh Date: Tue, 7 Oct 2025 16:31:43 -0600 Subject: [PATCH 3/6] no need to run make check with wolfSSL build, this test is checking C# wrapper tests --- .github/workflows/mono.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/mono.yml b/.github/workflows/mono.yml index d9aa1ba8d..03b3e8512 100644 --- a/.github/workflows/mono.yml +++ b/.github/workflows/mono.yml @@ -27,6 +27,7 @@ jobs: path: wolfssl configure: --enable-usersettings CPPFLAGS=-I$GITHUB_WORKSPACE/wolfssl/wrapper/CSharp install: true + check: false - name: Install mono-complete run: | From b179f0d2677d2f91662efc3d65f622a8273850e6 Mon Sep 17 00:00:00 2001 From: JacobBarthelmeh Date: Tue, 7 Oct 2025 16:38:18 -0600 Subject: [PATCH 4/6] copy over library since mono CI build is having trouble finding it --- .github/workflows/mono.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/mono.yml b/.github/workflows/mono.yml index 03b3e8512..fe9e7f5a4 100644 --- a/.github/workflows/mono.yml +++ b/.github/workflows/mono.yml @@ -34,10 +34,15 @@ jobs: sudo apt-get update sudo apt-get install -y mono-complete + - name: Copy wolfSSL.dll to C# wrapper directory + run: | + echo "Copying wolfSSL.dll to C# wrapper directory. $GITHUB_WORKSPACE/build-dir/lib contains:" + ls -la $GITHUB_WORKSPACE/build-dir/lib/* + cp $GITHUB_WORKSPACE/build-dir/lib/libwolfssl.so $GITHUB_WORKSPACE/wolfssl/wrapper/CSharp/wolfssl.dll + cp $GITHUB_WORKSPACE/build-dir/lib/libwolfssl.so $GITHUB_WORKSPACE/wolfssl/wrapper/CSharp/libwolfssl.so + - name: Build and run wolfCrypt test wrapper working-directory: wolfssl/wrapper/CSharp - env: - LD_LIBRARY_PATH: $GITHUB_WORKSPACE/build-dir/lib run: | mcs wolfCrypt-Test/wolfCrypt-Test.cs wolfSSL_CSharp/wolfCrypt.cs wolfSSL_CSharp/wolfSSL.cs wolfSSL_CSharp/X509.cs -OUT:wolfcrypttest.exe mono wolfcrypttest.exe From 459a4be3397c3a28b74116f7b2b9e2be77100f9f Mon Sep 17 00:00:00 2001 From: JacobBarthelmeh Date: Tue, 7 Oct 2025 16:43:30 -0600 Subject: [PATCH 5/6] add SNI support by default to user_settings.h with C# wrapper --- wrapper/CSharp/user_settings.h | 1 + 1 file changed, 1 insertion(+) diff --git a/wrapper/CSharp/user_settings.h b/wrapper/CSharp/user_settings.h index 21a72a69b..ce37a599d 100644 --- a/wrapper/CSharp/user_settings.h +++ b/wrapper/CSharp/user_settings.h @@ -45,6 +45,7 @@ #define WOLFSSL_KEY_GEN /* RSA key gen */ #define WOLFSSL_ASN_TEMPLATE /* default */ #define WOLFSSL_SHA3 +#define HAVE_SNI #if 0 #define OPENSSL_EXTRA From 7502cbaa3e5c28c7e61462f97ed52ab467dc074f Mon Sep 17 00:00:00 2001 From: JacobBarthelmeh Date: Fri, 10 Oct 2025 00:50:46 -0600 Subject: [PATCH 6/6] remove trailing white space in mono.yml --- .github/workflows/mono.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/mono.yml b/.github/workflows/mono.yml index fe9e7f5a4..5b76095d7 100644 --- a/.github/workflows/mono.yml +++ b/.github/workflows/mono.yml @@ -63,20 +63,20 @@ jobs: # Start server in background and capture its PID timeout 10s mono server.exe > server.log 2>&1 & SERVER_PID=$! - + # Wait for server to start sleep 2 - + # Run client and capture output timeout 5s mono client.exe > client.log 2>&1 CLIENT_EXIT_CODE=$? - + # Wait a moment for server to process sleep 1 - + # Kill server kill $SERVER_PID 2>/dev/null || true - + # Check if client completed successfully (exit code 0) if [ $CLIENT_EXIT_CODE -eq 0 ]; then echo "Client completed successfully" @@ -85,7 +85,7 @@ jobs: cat client.log exit 1 fi - + # Check for success indicators in logs if grep -q "SSL version is" client.log && grep -q "SSL cipher suite is" client.log; then echo "TLS handshake successful - SSL version and cipher suite detected" @@ -106,20 +106,20 @@ jobs: # Start server with SNI support in background timeout 10s mono server.exe -S > server_sni.log 2>&1 & SERVER_PID=$! - + # Wait for server to start sleep 2 - + # Run client with SNI and capture output timeout 5s mono client.exe -S localhost > client_sni.log 2>&1 CLIENT_EXIT_CODE=$? - + # Wait a moment for server to process sleep 1 - + # Kill server kill $SERVER_PID 2>/dev/null || true - + # Check if client completed successfully if [ $CLIENT_EXIT_CODE -eq 0 ]; then echo "SNI client completed successfully" @@ -128,7 +128,7 @@ jobs: cat client_sni.log exit 1 fi - + # Check for SNI success indicators if grep -q "SSL version is" client_sni.log && grep -q "SSL cipher suite is" client_sni.log; then echo "SNI TLS handshake successful"