@@ -28,19 +28,219 @@ need to open a new solution `wolfSSL_CSharp.sln` located in `wrapper\CSharp\wolf
28
28
Select the CPU type, configuration, and target file.
29
29
select ` Build ` and either ` Rebuild Solution ` or ` Build Solution ` .
30
30
31
+ ### Visual Studio Build Configurations
32
+
33
+ In addition to the Configuration and Platform build options, Visual Studio has a ` Platform Toolset ` option in the (C not C#) ` wolfssl ` project file.
34
+ This can be found in the (Right-click on wolfssl project) ` Property pages - General ` .
35
+
36
+ A missing Platform Toolset is assumed to be Visual Studio 2010. Click the drop-down to see options available.
37
+
38
+ ``` text
39
+ <PropertyGroup Condition ...
40
+ <PlatformToolset>v143</PlatformToolset>
41
+ ```
42
+
43
+ | Visual Studio Version | Internal Version | Platform Toolset |
44
+ | -----------------------| ------------------| ------------------|
45
+ | Visual Studio 2010 | 10.0 | v100 |
46
+ | Visual Studio 2012 | 11.0 | v110 |
47
+ | Visual Studio 2013 | 12.0 | v120 |
48
+ | Visual Studio 2015 | 14.0 | v140 |
49
+ | Visual Studio 2017 | 15.0 | v141 |
50
+ | Visual Studio 2019 | 16.0 | v142 |
51
+ | Visual Studio 2022 | 17.0 | v143 |
52
+
53
+ The ` wolfssl ` C project can also have the Toolset modified by right-clicking on the project and selecting "Retarget Projects".
54
+
55
+ Retargeting typically only offers to upgrade to the latest Platform Toolset, so the ` wolfssl.vcxproj ` file
56
+ will need to be manually edited if older versions are required.
57
+
58
+ ### Debugging Native Code
59
+
60
+ Right-click on the ` wolfSSL_CSharp ` project, select ` Properties ` and
61
+ navigate to the ` Debug ` panel.
62
+
63
+ Be sure to check the box under ` Debugger engines ` : [ x] ` Enable native code debugging ` .
64
+
65
+ This will allow single-step debugging into the native wolfSSL C library.
66
+
67
+ Do this also for the startup project being debugged.
68
+
69
+ If the error ` Interop debugging is not supported ` is encountered,
70
+ check which version of the .NET framework is being used.
71
+ Only 4.x or later supports native code debugging from a C# app.
72
+
73
+ See also:
74
+
75
+ https://learn.microsoft.com/en-us/visualstudio/debugger/debugging-native-code
76
+
77
+ ### Calling Convention
78
+
79
+ The wolfSSL functions are wrapped like this:
80
+
81
+ ```
82
+ [DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
83
+ private extern static int wolfSSL_Init();
84
+ ```
85
+
86
+ Where ` wolfssl_dll ` is a constant compile-time string that points to the ` wolfssl.dll ` file.
87
+
88
+ ### Troubleshooting Windows DLL
89
+
90
+ The ` wolfssl.dll ` file is created with the ` DLL Debug ` and ` DLL Release ` configurations
91
+ and is typically compiled to:
92
+
93
+ ```
94
+ C:\workspace\wolfssl-%USERNAME$\wrapper\CSharp\Debug\x64\wolfssl.dll
95
+ ```
96
+
97
+ From a developer command prompt:
98
+
99
+ ```
100
+ dumpbin /EXPORTS C:\workspace\wolfssl-$USER\wrapper\CSharp\Debug\x64\wolfssl.dll
101
+ ```
102
+
103
+ 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).
104
+
105
+ See the project file ` PreprocessorDefinitions ` section:
106
+
107
+ ```
108
+ <PreprocessorDefinitions>BUILDING_WOLFSSL;WOLFSSL_DLL;WOLFSSL_USER_SETTINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
109
+ ```
110
+
111
+ If wolfSSL was _ not_ compiled with ` WOLFSSL_DLL ` the ` Unable to find an entry point ` will be encountered:
112
+
113
+ ```
114
+ wolfssl init error System.EntryPointNotFoundException: Unable to find an entry point named 'wolfSSL_Init' in DLL 'wolfssl.dll'.
115
+ at wolfSSL.CSharp.wolfssl.wolfSSL_Init()
116
+ at wolfSSL.CSharp.wolfssl.Init() in C:\workspace\wolfssl-%USERNAME%\wrapper\CSharp\wolfSSL_CSharp\wolfSSL.cs:line nnn
117
+ Calling ctx Init from wolfSSL
118
+ ```
119
+
120
+ Note the ` WOLFSSL_DLL ` is used in the wolfssl ` wolfssl/wolfssl/wolfcrypt/visibility.h ` and defines the ` WOLFSSL_API ` like this:
121
+
122
+ ```
123
+ #define WOLFSSL_API __declspec(dllexport)
124
+ ```
125
+
126
+ Only the wolfSSL function declarations decorated with this tag will be visible ion the DLL.
127
+
128
+ #### Finding the wolfssl.dll
129
+
130
+ The most common problem encountered on Windows is the DLL location.
131
+
132
+ If not developing wolfSSL for Windows, one option is to copy the ` wolfssl.dll ` to ` C:\Windows\System32\ ` .
133
+
134
+ Another option is to add to the system environment path or your user environment path:
135
+
136
+ ```
137
+ set PATH=%PATH%;C:\path\to\your\wolfssl.dll
138
+ ```
139
+
140
+ #### Check Architecture (x86 vs x64)
141
+
142
+ Your C# application must match the architecture of wolfssl.dll:
143
+
144
+ - If your C# app is x64, wolfssl.dll must be 64-bit.
145
+ - If your C# app is x86, wolfssl.dll must be 32-bit.
146
+
147
+ #### Ensure wolfssl.dll is Unblocked
148
+
149
+ If you downloaded wolfssl.dll from the Internet, Windows may block it.
150
+
151
+ Right-click wolfssl.dll, go to Properties, and check Unblock under Security.
152
+
153
+
154
+ ## Linux (Ubuntu) using WSL
155
+
156
+ The Microsoft Windows Subsystem for Linux cam be used for wolfSSL.
157
+
158
+ ``` bash
159
+ sudo
160
+ sudo apt-get update
161
+ sudo apt-get upgrade
162
+ sudo apt install -y build-essential autoconf automake libtool pkg-config
163
+
164
+ export WORKSPACE=" /mnt/c/workspace"
165
+ export WOLFSSL_ROOT=" $WORKSPACE /wolfssl-$USER "
166
+
167
+ cd " WOLFSSL_ROOT"
168
+ ```
169
+
170
+ When using a git repository, run ` autogen.sh ` :
171
+
172
+ ```
173
+ cd "$WOLFSSL_ROOT"
174
+ ./autogen.sh
175
+ ```
176
+
177
+ ### Build wolfSSL and install it system-wide
178
+
179
+ To have a single instance of wolfSSL:
180
+
181
+ ```
182
+ ./configure
183
+ make
184
+ make check # (optional, but highly recommended)
185
+ sudo make install
186
+ ```
187
+
188
+ ### Build wolfSSL and install to arbitrary directory
189
+
190
+ To have an isolated instance of wolfSSL, in this case ` $HOME/wolfssl-install-psk ` :
191
+
192
+ ``` bash
193
+ make clean
194
+ make distclean
195
+
196
+ rm -rf " $HOME /wolfssl-install-psk"
197
+
198
+ ./configure --enable-all --disable-crypttests \
199
+ --disable-examples \
200
+ --enable-opensslall --enable-opensslextra \
201
+ --enable-tls13 --enable-dtls13 --enable-dtls --enable-psk \
202
+ CFLAGS=" -DWOLFSSL_STATIC_PSK" --enable-shared \
203
+ --prefix=" $HOME /wolfssl-install-psk"
204
+
205
+ make -j$( nproc)
206
+ make install
207
+ ```
208
+
209
+
210
+
211
+ ### Compile specific example in WSL
212
+
213
+ ``` bash
214
+ # Optionally fetch additional examples
215
+ git clone https://github.com/wolfSSL/wolfssl-examples.git " $WORKSPACE /wolfssl-examples-$USER "
216
+ cd " $WORKSPACE /wolfssl-examples-$USER "
217
+
218
+ THIS_EXAMPLE=" client-dtls-psk"
219
+
220
+ export WOLFSSL_DIR=" $HOME /wolfssl-install-psk"
221
+ export CFLAGS=" -I$WOLFSSL_DIR /include"
222
+ export LDFLAGS=" -L$WOLFSSL_DIR /lib"
223
+
224
+ export LD_LIBRARY_PATH=" $HOME /wolfssl-install-psk/lib:$LD_LIBRARY_PATH "
225
+
226
+ gcc -o " $THIS_EXAMPLE " " $THIS_EXAMPLE " .c \
227
+ -I$HOME /wolfssl-install-psk/include \
228
+ -L$HOME /wolfssl-install-psk/lib -Wl,-rpath=$HOME /wolfssl-install-psk/lib -lwolfssl -lm
229
+ ```
230
+
31
231
## Linux (Ubuntu) using mono
32
232
33
233
Prerequisites for linux:
34
234
35
- ```
235
+ ``` bash
36
236
apt-get update
37
237
apt-get upgrade
38
238
apt-get install mono-complete
39
239
```
40
240
41
- ### Build wolfSSL and install
241
+ ### Build wolfSSL and install system-wide
42
242
43
- ```
243
+ ``` bash
44
244
./autogen.sh
45
245
./configure --enable-keygen --enable-eccencrypt --enable-ed25519 --enable-curve25519 --enable-aesgcm
46
246
make
@@ -52,9 +252,9 @@ sudo make install
52
252
53
253
From the ` wrapper/CSharp ` directory (` cd wrapper/CSharp ` ):
54
254
55
- Compile wolfCrypt test:
255
+ Compile wolfCrypt test with mono :
56
256
57
- ```
257
+ ``` bash
58
258
mcs wolfCrypt-Test/wolfCrypt-Test.cs wolfSSL_CSharp/wolfCrypt.cs -OUT:wolfcrypttest.exe
59
259
mono wolfcrypttest.exe
60
260
```
@@ -63,15 +263,15 @@ mono wolfcrypttest.exe
63
263
64
264
From the ` wrapper/CSharp ` directory (` cd wrapper/CSharp ` ):
65
265
66
- Compile server:
266
+ Compile server with mono :
67
267
68
- ```
268
+ ``` bash
69
269
mcs wolfSSL_CSharp/wolfSSL.cs wolfSSL_CSharp/X509.cs wolfSSL-TLS-Server/wolfSSL-TLS-Server.cs -OUT:server.exe
70
270
```
71
271
72
- Compile client:
272
+ Compile client with mono :
73
273
74
- ```
274
+ ``` bash
75
275
mcs wolfSSL_CSharp/wolfSSL.cs wolfSSL_CSharp/X509.cs wolfSSL-TLS-Client/wolfSSL-TLS-Client.cs -OUT:client.exe
76
276
```
77
277
0 commit comments