Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions .github/workflows/visual-studio.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Build for .NET 3.5

# START OF COMMON SECTION
on:
push:
branches: [ 'master', 'main', 'release/**' ]
pull_request:
branches: [ '*' ]
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
# END OF COMMON SECTION

jobs:
build:
if: github.repository_owner == 'wolfssl'
runs-on: windows-2019 # .NET 3.5 is available here

steps:
# Checkout PR branch (supports both forks and local PRs)
- name: Checkout Repository (PR branch or push branch)
uses: actions/checkout@v3
with:
repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
ref: ${{ github.event.pull_request.head.ref || github.ref_name }}

# Checkout wolfSSL (PR branch if from fork, master if push)
- name: Checkout wolfSSL (PR branch or master)
uses: actions/checkout@v3
with:
repository: ${{ github.event.pull_request.head.repo.full_name || 'wolfssl/wolfssl' }} # Pull from fork if PR exists
ref: ${{ github.event.pull_request.head.ref || 'master' }} # Use PR branch if available, otherwise master
path: wolfssl # Clone wolfSSL into "wolfssl" subdirectory

- name: Setup MSBuild
uses: microsoft/setup-msbuild@v1

# wolfSSL core
- name: Build wolfSSL (DLL Debug, x64)
working-directory: wolfssl
run: |
msbuild wolfssl.vcxproj /p:Configuration="DLL Debug" /p:Platform=x64 /p:PlatformToolset=v142 /m /verbosity:normal
shell: cmd

# C# Wrapper
- name: Build wolfSSL_CSharp
working-directory: wrapper/CSharp/wolfSSL_CSharp
run: msbuild wolfSSL_CSharp.csproj /p:TargetFrameworkVersion=v3.5

# wolfCrypt-Test
- name: Build wolfCrypt-Test
working-directory: wrapper/CSharp/wolfCrypt-Test
run: msbuild wolfCrypt-Test.csproj /p:TargetFrameworkVersion=v3.5

# DTLS
- name: Build wolfSSL-DTLS-Server
working-directory: wrapper/CSharp/wolfSSL-DTLS-Server
run: msbuild wolfSSL-DTLS-Server.csproj /p:TargetFrameworkVersion=v3.5

# DTLS-PSK
- name: Build wolfSSL-DTLS-PSK-Server
working-directory: wrapper/CSharp/wolfSSL-DTLS-PSK-Server
run: msbuild wolfSSL-DTLS-PSK-Server.csproj /p:TargetFrameworkVersion=v3.5

# TLS
- name: Build wolfSSL-TLS-Client
working-directory: wrapper/CSharp/wolfSSL-TLS-Client
run: msbuild wolfSSL-TLS-Client.csproj /p:TargetFrameworkVersion=v3.5

- name: Build wolfSSL-TLS-Server
working-directory: wrapper/CSharp/wolfSSL-TLS-Server
run: msbuild wolfSSL-TLS-Server.csproj /p:TargetFrameworkVersion=v3.5

- name: Build wolfSSL-TLS-ServerThreaded
working-directory: wrapper/CSharp/wolfSSL-TLS-ServerThreaded
run: msbuild wolfSSL-TLS-ServerThreaded.csproj /p:TargetFrameworkVersion=v3.5

# TLS PSK
- name: Build wolfSSL-TLS-PSK-Client
working-directory: wrapper/CSharp/wolfSSL-TLS-PSK-Client
run: msbuild wolfSSL-TLS-PSK-Client.csproj /p:TargetFrameworkVersion=v3.5

- name: Build wolfSSL-TLS-PSK-Server
working-directory: wrapper/CSharp/wolfSSL-TLS-PSK-Server
run: msbuild wolfSSL-TLS-PSK-Server.csproj /p:TargetFrameworkVersion=v3.5

# Example-IOCallbacks
- name: Build wolfSSL-Example-IOCallbacks
working-directory: wrapper/CSharp/wolfSSL-Example-IOCallbacks
run: msbuild wolfSSL-Example-IOCallbacks.csproj /p:TargetFrameworkVersion=v3.5
2 changes: 2 additions & 0 deletions .wolfssl_known_macro_extras
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ DILITHIUM_MUL_Q_SLOW
DILITHIUM_MUL_SLOW
DILITHIUM_USE_HINT_CT
DTLS_RECEIVEFROM_NO_TIMEOUT_ON_INVALID_PEER
Debug
ECCSI_ORDER_MORE_BITS_THAN_PRIME
ECC_DUMP_OID
ECDHE_SIZE
Expand Down Expand Up @@ -418,6 +419,7 @@ RTC_ALARMSUBSECONDMASK_ALL
RTE_CMSIS_RTOS_RTX
RTOS_MODULE_NET_AVAIL
RTPLATFORM
Release
SA_INTERRUPT
SCEKEY_INSTALLED
SHA256_MANY_REGISTERS
Expand Down
3 changes: 1 addition & 2 deletions wolfssl/sniffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@
#include <wolfssl/wolfcrypt/wolfevent.h>
#endif


#ifdef _WIN32
#ifdef SSL_SNIFFER_EXPORTS
#define SSL_SNIFFER_API __declspec(dllexport)
#else
#define SSL_SNIFFER_API __declspec(dllimport)
#define SSL_SNIFFER_API
#endif
#else
#define SSL_SNIFFER_API
Expand Down
1 change: 0 additions & 1 deletion wolfssl/wolfcrypt/curve25519.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ curve25519_key* wc_curve25519_new(void* heap, int devId, int *result_code);
WOLFSSL_API
int wc_curve25519_delete(curve25519_key* key, curve25519_key** key_p);
#endif
WOLFSSL_API

/* raw key helpers */
WOLFSSL_API
Expand Down
1 change: 0 additions & 1 deletion wolfssl/wolfcrypt/ed25519.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ ed25519_key* wc_ed25519_new(void* heap, int devId, int *result_code);
WOLFSSL_API
int wc_ed25519_delete(ed25519_key* key, ed25519_key** key_p);
#endif
WOLFSSL_API

#ifdef HAVE_ED25519_KEY_IMPORT
WOLFSSL_API
Expand Down
218 changes: 209 additions & 9 deletions wrapper/CSharp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,219 @@ need to open a new solution `wolfSSL_CSharp.sln` located in `wrapper\CSharp\wolf
Select the CPU type, configuration, and target file.
select `Build` and either `Rebuild Solution` or `Build Solution`.

### Visual Studio Build Configurations

In addition to the Configuration and Platform build options, Visual Studio has a `Platform Toolset` option in the (C not C#) `wolfssl` project file.
This can be found in the (Right-click on wolfssl project) `Property pages - General`.

A missing Platform Toolset is assumed to be Visual Studio 2010. Click the drop-down to see options available.

```text
<PropertyGroup Condition ...
<PlatformToolset>v143</PlatformToolset>
```

| Visual Studio Version | Internal Version | Platform Toolset |
|-----------------------|------------------|------------------|
| Visual Studio 2010 | 10.0 | v100 |
| Visual Studio 2012 | 11.0 | v110 |
| Visual Studio 2013 | 12.0 | v120 |
| Visual Studio 2015 | 14.0 | v140 |
| Visual Studio 2017 | 15.0 | v141 |
| Visual Studio 2019 | 16.0 | v142 |
| Visual Studio 2022 | 17.0 | v143 |

The `wolfssl` C project can also have the Toolset modified by right-clicking on the project and selecting "Retarget Projects".

Retargeting typically only offers to upgrade to the latest Platform Toolset, so the `wolfssl.vcxproj` file
will need to be manually edited if older versions are required.

### Debugging Native Code

Right-click on the `wolfSSL_CSharp` project, select `Properties` and
navigate to the `Debug` panel.

Be sure to check the box under `Debugger engines`: [x] `Enable native code debugging`.

This will allow single-step debugging into the native wolfSSL C library.

Do this also for the startup project being debugged.

If the error `Interop debugging is not supported` is encountered,
check which version of the .NET framework is being used.
Only 4.x or later supports native code debugging from a C# app.

See also:

https://learn.microsoft.com/en-us/visualstudio/debugger/debugging-native-code

### Calling Convention

The wolfSSL functions are wrapped like this:

```
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
private extern static int wolfSSL_Init();
```

Where `wolfssl_dll` is a constant compile-time string that points to the `wolfssl.dll` file.

### Troubleshooting Windows DLL

The `wolfssl.dll` file is created with the `DLL Debug` and `DLL Release` configurations
and is typically compiled to:

```
C:\workspace\wolfssl-%USERNAME$\wrapper\CSharp\Debug\x64\wolfssl.dll
```

From a developer command prompt:

```
dumpbin /EXPORTS C:\workspace\wolfssl-$USER\wrapper\CSharp\Debug\x64\wolfssl.dll
```

There should be a long list of functions. If not, be sure to build with `WOLFSSL_DLL` (should be automatically included with DLL Debug/Release configurations).

See the project file `PreprocessorDefinitions` section:

```
<PreprocessorDefinitions>BUILDING_WOLFSSL;WOLFSSL_DLL;WOLFSSL_USER_SETTINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
```

If wolfSSL was _not_ compiled with `WOLFSSL_DLL` the `Unable to find an entry point` will be encountered:

```
wolfssl init error System.EntryPointNotFoundException: Unable to find an entry point named 'wolfSSL_Init' in DLL 'wolfssl.dll'.
at wolfSSL.CSharp.wolfssl.wolfSSL_Init()
at wolfSSL.CSharp.wolfssl.Init() in C:\workspace\wolfssl-%USERNAME%\wrapper\CSharp\wolfSSL_CSharp\wolfSSL.cs:line nnn
Calling ctx Init from wolfSSL
```

Note the `WOLFSSL_DLL` is used in the wolfssl `wolfssl/wolfssl/wolfcrypt/visibility.h` and defines the `WOLFSSL_API` like this:

```
#define WOLFSSL_API __declspec(dllexport)
```

Only the wolfSSL function declarations decorated with this tag will be visible ion the DLL.

#### Finding the wolfssl.dll

The most common problem encountered on Windows is the DLL location.

If not developing wolfSSL for Windows, one option is to copy the `wolfssl.dll` to `C:\Windows\System32\`.

Another option is to add to the system environment path or your user environment path:

```
set PATH=%PATH%;C:\path\to\your\wolfssl.dll
```

#### Check Architecture (x86 vs x64)

Your C# application must match the architecture of wolfssl.dll:

- If your C# app is x64, wolfssl.dll must be 64-bit.
- If your C# app is x86, wolfssl.dll must be 32-bit.

#### Ensure wolfssl.dll is Unblocked

If you downloaded wolfssl.dll from the Internet, Windows may block it.

Right-click wolfssl.dll, go to Properties, and check Unblock under Security.


## Linux (Ubuntu) using WSL

The Microsoft Windows Subsystem for Linux cam be used for wolfSSL.

```bash
sudo
sudo apt-get update
sudo apt-get upgrade
sudo apt install -y build-essential autoconf automake libtool pkg-config

export WORKSPACE="/mnt/c/workspace"
export WOLFSSL_ROOT="$WORKSPACE/wolfssl-$USER"

cd "WOLFSSL_ROOT"
```

When using a git repository, run `autogen.sh`:

```
cd "$WOLFSSL_ROOT"
./autogen.sh
```

### Build wolfSSL and install it system-wide

To have a single instance of wolfSSL:

```
./configure
make
make check # (optional, but highly recommended)
sudo make install
```

### Build wolfSSL and install to arbitrary directory

To have an isolated instance of wolfSSL, in this case `$HOME/wolfssl-install-psk`:

```bash
make clean
make distclean

rm -rf "$HOME/wolfssl-install-psk"

./configure --enable-all --disable-crypttests \
--disable-examples \
--enable-opensslall --enable-opensslextra \
--enable-tls13 --enable-dtls13 --enable-dtls --enable-psk \
CFLAGS="-DWOLFSSL_STATIC_PSK" --enable-shared \
--prefix="$HOME/wolfssl-install-psk"

make -j$(nproc)
make install
```



### Compile specific example in WSL

```bash
# Optionally fetch additional examples
git clone https://github.com/wolfSSL/wolfssl-examples.git "$WORKSPACE/wolfssl-examples-$USER"
cd "$WORKSPACE/wolfssl-examples-$USER"

THIS_EXAMPLE="client-dtls-psk"

export WOLFSSL_DIR="$HOME/wolfssl-install-psk"
export CFLAGS="-I$WOLFSSL_DIR/include"
export LDFLAGS="-L$WOLFSSL_DIR/lib"

export LD_LIBRARY_PATH="$HOME/wolfssl-install-psk/lib:$LD_LIBRARY_PATH"

gcc -o "$THIS_EXAMPLE" "$THIS_EXAMPLE".c \
-I$HOME/wolfssl-install-psk/include \
-L$HOME/wolfssl-install-psk/lib -Wl,-rpath=$HOME/wolfssl-install-psk/lib -lwolfssl -lm
```

## Linux (Ubuntu) using mono

Prerequisites for linux:

```
```bash
apt-get update
apt-get upgrade
apt-get install mono-complete
```

### Build wolfSSL and install
### Build wolfSSL and install system-wide

```
```bash
./autogen.sh
./configure --enable-keygen --enable-eccencrypt --enable-ed25519 --enable-curve25519 --enable-aesgcm
make
Expand All @@ -52,9 +252,9 @@ sudo make install

From the `wrapper/CSharp` directory (`cd wrapper/CSharp`):

Compile wolfCrypt test:
Compile wolfCrypt test with mono:

```
```bash
mcs wolfCrypt-Test/wolfCrypt-Test.cs wolfSSL_CSharp/wolfCrypt.cs -OUT:wolfcrypttest.exe
mono wolfcrypttest.exe
```
Expand All @@ -63,15 +263,15 @@ mono wolfcrypttest.exe

From the `wrapper/CSharp` directory (`cd wrapper/CSharp`):

Compile server:
Compile server with mono:

```
```bash
mcs wolfSSL_CSharp/wolfSSL.cs wolfSSL_CSharp/X509.cs wolfSSL-TLS-Server/wolfSSL-TLS-Server.cs -OUT:server.exe
```

Compile client:
Compile client with mono:

```
```bash
mcs wolfSSL_CSharp/wolfSSL.cs wolfSSL_CSharp/X509.cs wolfSSL-TLS-Client/wolfSSL-TLS-Client.cs -OUT:client.exe
```

Expand Down
Loading
Loading