@@ -28,19 +28,191 @@ need to open a new solution `wolfSSL_CSharp.sln` located in `wrapper\CSharp\wolf
2828Select the CPU type, configuration, and target file.
2929select ` Build ` and either ` Rebuild Solution ` or ` Build Solution ` .
3030
31+ ### Debugging Native Code
32+
33+ Right-click on the ` wolfSSL_CSharp ` project, select ` Properties ` and
34+ navigate to the ` Debug ` panel.
35+
36+ Be sure to check the box under ` Debugger engines ` : [ x] ` Enable native code debugging ` .
37+
38+ This will allow single-step debugging into the native wolfSSL C library.
39+
40+ Do this also for the startup project being debugged.
41+
42+ If the error ` Interop debugging is not supported ` is encountered,
43+ check which version of the .NET framework is being used.
44+ Only 4.x or later supports native code debugging from a C# app.
45+
46+ See also:
47+
48+ https://learn.microsoft.com/en-us/visualstudio/debugger/debugging-native-code
49+
50+ ### Calling Convention
51+
52+ The wolfSSL functions are wrapped like this:
53+
54+ ```
55+ [DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
56+ private extern static int wolfSSL_Init();
57+ ```
58+
59+ Where ` wolfssl_dll ` is a constant compile-time string that points to the ` wolfssl.dll ` file.
60+
61+ ### Troubleshooting Windows DLL
62+
63+ The ` wolfssl.dll ` file is typically compiled to:
64+
65+ ```
66+ C:\workspace\wolfssl-%USERNAME$\wrapper\CSharp\Debug\x64\wolfssl.dll
67+ ```
68+
69+ From a developer command prompt:
70+
71+ ```
72+ dumpbin /EXPORTS C:\workspace\wolfssl-$USER\wrapper\CSharp\Debug\x64\wolfssl.dll
73+ ```
74+
75+ There should be a long list of functions. If not, be sure to build with ` WOLFSSL_DLL ` .
76+
77+ See the project file ` PreprocessorDefinitions ` section:
78+
79+ ```
80+ <PreprocessorDefinitions>BUILDING_WOLFSSL;WOLFSSL_DLL;WOLFSSL_USER_SETTINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
81+ ```
82+
83+ If wolfSSL was _ not_ compiled with ` WOLFSSL_DLL ` the ` Unable to find an entry point ` will be encountered:
84+
85+ ```
86+ wolfssl init error System.EntryPointNotFoundException: Unable to find an entry point named 'wolfSSL_Init' in DLL 'wolfssl.dll'.
87+ at wolfSSL.CSharp.wolfssl.wolfSSL_Init()
88+ at wolfSSL.CSharp.wolfssl.Init() in C:\workspace\wolfssl-%USERNAME%\wrapper\CSharp\wolfSSL_CSharp\wolfSSL.cs:line nnn
89+ Calling ctx Init from wolfSSL
90+ ```
91+
92+ Note the ` WOLFSSL_DLL ` is used in the wolfssl ` visibiility.h ` and defines the ` WOLFSSL_API ` like this:
93+
94+ ```
95+ #define WOLFSSL_API __declspec(dllexport)
96+ ```
97+
98+ Only the wolfSSL function declarations decorated with this tag will be visible ion the DLL.
99+
100+ #### Finding the wolfssl.dll
101+
102+ The most common problem encountered on Windows is the DLL location.
103+
104+ If not developing wolfSSL for Windows, one option is to copy the ` wolfssl.dll ` to ` C:\Windows\System32\ ` .
105+
106+ Another option is to add to the system environment path or your user environment path:
107+
108+ ```
109+ set PATH=%PATH%;C:\path\to\your\wolfssl.dll
110+ ```
111+
112+ #### Check Architecture (x86 vs x64)
113+
114+ Your C# application must match the architecture of wolfssl.dll:
115+
116+ - If your C# app is x64, wolfssl.dll must be 64-bit.
117+ - If your C# app is x86, wolfssl.dll must be 32-bit.
118+
119+ #### Ensure wolfssl.dll is Unblocked
120+
121+ If you downloaded wolfssl.dll from the Internet, Windows may block it.
122+
123+ Right-click wolfssl.dll, go to Properties, and check Unblock under Security.
124+
125+
126+ ## Linux (Ubuntu) using WSL
127+
128+ The Microsoft Windows Subsystem for Linux cam be used for wolfSSL.
129+
130+ ``` bash
131+ sudo
132+ sudo apt-get update
133+ sudo apt-get upgrade
134+ sudo apt install -y build-essential autoconf automake libtool pkg-config
135+
136+ export WORKSPACE=" /mnt/c/workspace"
137+ export WOLFSSL_ROOT=" $WORKSPACE /wolfssl-$USER "
138+
139+ cd " WOLFSSL_ROOT"
140+ ```
141+
142+ When using a git repository, run ` autogen.sh ` :
143+
144+ ```
145+ cd "$WOLFSSL_ROOT"
146+ ./autogen.sh
147+ ```
148+
149+ ### Build wolfSSL and install it system-wide
150+
151+ To have a single instance of wolfSSL:
152+
153+ ```
154+ ./configure
155+ make
156+ make check # (optional, but highly recommended)
157+ sudo make install
158+ ```
159+
160+ ### Build wolfSSL and install to arbitrary directory
161+
162+ To have a n isolated instance of wolfSSL, in this case ` $HOME/wolfssl-install-psk ` :
163+
164+ ``` bash
165+ make clean
166+ make distclean
167+
168+ rm -rf " $HOME /wolfssl-install-psk"
169+
170+ ./configure --enable-all --disable-crypttests \
171+ --disable-examples \
172+ --enable-opensslall --enable-opensslextra \
173+ --enable-tls13 --enable-dtls13 --enable-dtls --enable-psk \
174+ CFLAGS=" -DWOLFSSL_STATIC_PSK" --enable-shared \
175+ --prefix=" $HOME /wolfssl-install-psk"
176+
177+ make -j$( nproc)
178+ make install
179+ ```
180+
181+
182+
183+ ### Compile specific example in WSL
184+
185+ ``` bash
186+ # Optionally fetch additional examples
187+ git clone https://github.com/wolfSSL/wolfssl-examples.git " $WORKSPACE /wolfssl-examples-$USER "
188+ cd " $WORKSPACE /wolfssl-examples-$USER "
189+
190+ THIS_EXAMPLE=" client-dtls-psk"
191+
192+ export WOLFSSL_DIR=" $HOME /wolfssl-install-psk"
193+ export CFLAGS=" -I$WOLFSSL_DIR /include"
194+ export LDFLAGS=" -L$WOLFSSL_DIR /lib"
195+
196+ export LD_LIBRARY_PATH=" $HOME /wolfssl-install-psk/lib:$LD_LIBRARY_PATH "
197+
198+ gcc -o " $THIS_EXAMPLE " " $THIS_EXAMPLE " .c \
199+ -I$HOME /wolfssl-install-psk/include \
200+ -L$HOME /wolfssl-install-psk/lib -Wl,-rpath=$HOME /wolfssl-install-psk/lib -lwolfssl -lm
201+ ```
202+
31203## Linux (Ubuntu) using mono
32204
33205Prerequisites for linux:
34206
35- ```
207+ ``` bash
36208apt-get update
37209apt-get upgrade
38210apt-get install mono-complete
39211```
40212
41- ### Build wolfSSL and install
213+ ### Build wolfSSL and install system-wide
42214
43- ```
215+ ``` bash
44216./autogen.sh
45217./configure --enable-keygen --enable-eccencrypt --enable-ed25519 --enable-curve25519 --enable-aesgcm
46218make
@@ -52,9 +224,9 @@ sudo make install
52224
53225From the ` wrapper/CSharp ` directory (` cd wrapper/CSharp ` ):
54226
55- Compile wolfCrypt test:
227+ Compile wolfCrypt test with mono :
56228
57- ```
229+ ``` bash
58230mcs wolfCrypt-Test/wolfCrypt-Test.cs wolfSSL_CSharp/wolfCrypt.cs -OUT:wolfcrypttest.exe
59231mono wolfcrypttest.exe
60232```
@@ -63,15 +235,15 @@ mono wolfcrypttest.exe
63235
64236From the ` wrapper/CSharp ` directory (` cd wrapper/CSharp ` ):
65237
66- Compile server:
238+ Compile server with mono :
67239
68- ```
240+ ``` bash
69241mcs wolfSSL_CSharp/wolfSSL.cs wolfSSL_CSharp/X509.cs wolfSSL-TLS-Server/wolfSSL-TLS-Server.cs -OUT:server.exe
70242```
71243
72- Compile client:
244+ Compile client with mono :
73245
74- ```
246+ ``` bash
75247mcs wolfSSL_CSharp/wolfSSL.cs wolfSSL_CSharp/X509.cs wolfSSL-TLS-Client/wolfSSL-TLS-Client.cs -OUT:client.exe
76248```
77249
0 commit comments