-
Notifications
You must be signed in to change notification settings - Fork 900
CSharp Wrapper Improvements #8946
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
a1bc0fb to
9c2ec0b
Compare
|
Jenkins retest this please. For missing results, SSL_read input error -308, error state on socket |
9c2ec0b to
6f7aee2
Compare
|
🛟 Devin Lifeguard found 1 likely issues in this PR
@gojimmypi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances the C# wolfSSL wrapper with dynamic DLL loading, improved path detection, verbose logging, and TLS alert history retrieval; adds a new Visual Studio solution for concurrent client/server projects; and applies MSVC compatibility fixes across native code.
- Added
SetVerbosity,LoadDLL, recursivesetPath, and alert history support inwolfSSL.cs - Introduced
WOLFSSL_ALERT,WOLFSSL_ALERT_HISTORY, andget_alert_historybinding - Created
wolfSSL_CSharp-Clients.slnand updated documentation for cross-platform builds - Replaced
#warningwith#pragma messagefor MSVC in multiple native source headers
Reviewed Changes
Copilot reviewed 27 out of 27 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| wrapper/CSharp/wolfSSL_CSharp/wolfSSL.cs | Added verbose DLL loading, path search, alert history API |
| wrapper/CSharp/wolfSSL_CSharp/wolfCrypt.cs | Updated comments on CPU architecture matching |
| wrapper/CSharp/wolfSSL_CSharp-Clients.sln | New solution for concurrent client/server samples |
| wrapper/CSharp/README.md | Expanded build and troubleshooting instructions |
| wrapper/CSharp/include.am | Added new solution to distribution list |
| wolfssl/wolfio.h | Updated XINET_PTON macro for MSVC version casting |
| wolfssl/wolfcrypt/sp.h | Adjusted typedef condition for older MSVC |
| wolfssl/error-ssl.h | Wrapped wc_static_assert in MSVC warning suppression |
| wolfcrypt/src/.c, src/.c | Replaced #warning with #pragma message for MSVC builds |
Comments suppressed due to low confidence (1)
wrapper/CSharp/wolfSSL_CSharp/wolfSSL.cs:81
- Invalid C# preprocessor directive
#pragma "Only DEBUG and RELEASE supported". In C#, use#erroror#warningfor conditional compilation messages, or update to a supported directive to avoid build errors.
#pragma "Only DEBUG and RELEASE supported"
|
@dgarske @JacobBarthelmeh sorry for the delay, I ended up down a rabbit hole & should be done by the end of the day. I've implemented a new to |
|
@dgarske @JacobBarthelmeh This PR has changed substantially since submitted. I've left the new changes in a separate commit for now. I've addressed the compile issues for CE, but I have been still unable to figure out how to run native C wolfSSL in any of the CE emulators with the @dgarske please test on customer hardware. Thank you. |
|
🛟 Devin Lifeguard found 1 likely issues in this PR
@gojimmypi |
|
🛟 Devin Lifeguard found 2 likely issues in this PR
@gojimmypi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running tests on customer hardware now. Please remove the .c/.h use of WindowsCE... it never existed and don't add a new construct. If needed use compiler provided _WIN32_WCE
IDE/WIN/user_settings.h
Outdated
| #error This user_settings.h header is only designed for Windows | ||
| #endif | ||
|
|
||
| /* Optional WindowsCE, needed here for all CE configurations: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
wolfssl/wolfio.h
Outdated
| #define XINET_PTON(a,b,c) InetPton((a),(b),(c)) | ||
| #else | ||
| #define XINET_PTON(a,b,c) InetPton((a),(PCWSTR)(b),(c)) | ||
| #if (defined(_MSC_VER) && (_MSC_VER >= 1600)) || defined(WindowsCE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove || defined(WindowsCE) or use the existing _WIN32_WCE instead...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without WindowsCE, the _WIN32_WCE is not automatically assigned for me, and I see these compile-time warnings:
2>c:\workspace\wolfssl-gojimmypi\src\ssl.c(1928) : warning C4133: 'function' : incompatible types - from 'PCSTR' to 'PCWSTR'
2>c:\workspace\wolfssl-gojimmypi\src\ssl.c(22180) : warning C4133: 'function' : incompatible types - from 'const char *' to 'PCWSTR'
I've removed the WindowsCE and added explicit known CE macros:
#if (defined(_MSC_VER) && (_MSC_VER >= 1600)) || \
defined(_WIN32_WCE) || defined(WINCE) || defined(PocketPC)
#define XINET_PTON(a,b,c) InetPton((a),(PCWSTR)(b),(c))
#else
#define XINET_PTON(a,b,c) InetPton((a),(PCSTR)(b),(c))
#endif
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dgarske what do you think of revising the Windows API logic and first check for UNICODE like this:
#ifndef XINET_PTON
#if defined(__WATCOMC__)
#if defined(__OS2__) || defined(__NT__) && \
(NTDDI_VERSION >= NTDDI_VISTA)
#define XINET_PTON(a,b,c) inet_pton((a),(b),(c))
#else
#define XINET_PTON(a,b,c) *(unsigned *)(c) = inet_addr((b))
#endif
#elif defined(USE_WINDOWS_API) /* Windows-friendly definition */
#if defined(UNICODE)
/* Use Win API Pointer to a constant wide-character string */
#define XINET_PTON(a,b,c) InetPton((a),(PCWSTR)(b),(c))
#elif defined(__MINGW64__) && !defined(UNICODE)
#define XINET_PTON(a,b,c) InetPton((a),(b),(c))
#else
#if (defined(_MSC_VER) && (_MSC_VER >= 1600)) || defined(_WIN32_WCE)
#define XINET_PTON(a,b,c) InetPton((a),(PCWSTR)(b),(c))
#else
#define XINET_PTON(a,b,c) InetPton((a),(PCSTR)(b),(c))
#endif
#endif
#else
#define XINET_PTON(a,b,c) inet_pton((a),(b),(c))
#endif
#endif
| } | ||
| } | ||
| } | ||
| /* wolfCrypt-Test.cs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file shows a full replace. Guessing a CRLF issue. Please try and avoid that change if possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the prior file was LF only. Windows / Visual Studio default is CRLF.
I'll revert for this PR, but I recommend we change line endings at some future time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you saying this file specifically is different? If so go ahead and keep it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. All of the other examples are CRLF. I'll change the wolfCrypt-Test.cs from LF to CRLF.
| { | ||
| if (addr.AddressFamily == AddressFamily.InterNetwork) | ||
| { | ||
| tcp.Connect(new IPEndPoint(addr, SERVER_PORT)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this new logic needed? Where is the break;?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been still trying to get my CE emulator to work and use the wolfssl-tls-client example.
Why is this new logic needed?
Because this:
tcp.Connect(SERVER_NAME, SERVER_PORT);
on WindowsCE gives this error (connect takes only 1 param on CE, 2 on others):
Error 1 No overload for method 'Connect' takes '2' arguments C:\workspace\wolfssl-gojimmypi\wrapper\CSharp\wolfSSL-TLS-Client\wolfSSL-TLS-Client.cs 281 13 wolfSSL-TLS_CE_2008
Where is the break;?
added
| Console.WriteLine("SSL cipher suite is " + wolfssl.get_current_cipher(ssl)); | ||
|
|
||
| /* Optional code & level history */ | ||
| show_alert_history(ssl); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This belongs at the end before cleanup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved
| } | ||
| #endif | ||
|
|
||
| public static void show_alert_history_code(WOLFSSL_ALERT h, string m) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make show_alert_history and show_alert_history_code private.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
|
||
| namespace wolfSSL.CSharp | ||
| { | ||
| /******************************** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't these be part of the public class wolfssl? I'd prefer use wolfssl.WOLFSSL_ALERT, etc in the calling code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't these be part of the public class wolfssl?
Yes, it was at one point, but there was a scoping problem. I'll see if I can move it back or document why not.
| public static void show_alert_history_code(WOLFSSL_ALERT h, string m) | ||
| { | ||
| /* VS initializes .code and .level to zero; wolfSSL sets to -1 until there's a valid value. */ | ||
| if ((h.code > 0) || (h.level > 0)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please cleanup example. You have if ((h.code > 0) || (h.level > 0)) twice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, changed.
|
Jenkins retest this please For ERROR: Unable to tear down: java.io.IOException: Unexpected EOF; Python Remote call to wolf-linux-cloud-node no workspace for PRB-python-port #8458 |
wolfssl/wolfio.h
Outdated
|
|
||
| /* CE Not always reliably detected. Define our own _WIN32_WCE as needed. */ | ||
| #if defined(_WIN32_WCE) || defined(WINCE) || defined(PocketPC) | ||
| #if !_WIN32_WCE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change this to #if !defined(_WIN32_WCE). Why add another macro WINCE or PocketPC here? Are those supposed to supplied by the compiler or optionally by the user?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will change this to only _WIN32_WCE. Neither that, nor WINCE have ever been auto-defined for me. I added them for likely completeness, although never actually tested.
edit: I'll remove this entire section and use only _WIN32_WCE for XINET_PTON detection of PCWSTR in this file.
#elif defined(USE_WINDOWS_API) /* Windows-friendly definition */
#if defined(__MINGW64__) && !defined(UNICODE)
#define XINET_PTON(a,b,c) InetPton((a),(b),(c))
#else
#if (defined(_MSC_VER) && (_MSC_VER >= 1600)) || defined(_WIN32_WCE)
#define XINET_PTON(a,b,c) InetPton((a),(PCWSTR)(b),(c))
#else
#define XINET_PTON(a,b,c) InetPton((a),(PCSTR)(b),(c))
#endif
#endif
The PocketPC was auto-added at new project time here. I manually added the WindowsCE.
wolfssl/wolfio.h
Outdated
| #else | ||
| #define XINET_PTON(a,b,c) InetPton((a),(PCWSTR)(b),(c)) | ||
| #if (defined(_MSC_VER) && (_MSC_VER >= 1600)) || \ | ||
| defined(_WIN32_WCE) || defined(WINCE) || defined(PocketPC) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just use _WIN32_WCE. You don't need WINCE or PocketPC
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll use only _WIN32_WCE. It may need to be manually defined for some projects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, your logic a few lines up makes sure _WIN32_WCE is defined... So you can remove this duplicate logic.
| [DllImport(wolfssl_dll)] | ||
| private extern static IntPtr wc_GetErrorString(int error); | ||
| public delegate void loggingCb(int lvl, string msg); | ||
| /* No Windows CE decorator for logging call-back */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could break some users. I would prefer the logging continue to be duplicated. Technically its in wolfCrypt not wolfSSL. I don't want a refactor on this. Please duplicate the logging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Do you have an example of what might be problematic & why the duplication is preferred?
I'd like to include a comment to avoid a future de-dupe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WolfCrypt only users who are already calling wolfcrypt.setLogging
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. Interesting.
What do you think of moving it all from wolfSSL to wolfcrypt, no duplicating, but including API references to maintain current functionality?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That’s fine. As long as we keep the existing API’s. I do not want to break compatibility
|
@dgarske you removed the We may also consider moving some of the C# examples to https://github.com/wolfSSL/wolfssl-examples |
3086d2d to
5819622
Compare
ea54abc to
ed90c17
Compare

Description
Summary: CSharp Wrapper Improvements
This PR enhances the C# wrapper and improves cross-platform compatibility, developer experience, and debugging support when using wolfSSL with .NET applications.
CSharp Wrapper Enhancements
New Structs and Functions
WOLFSSL_ALERTandWOLFSSL_ALERT_HISTORYstructs to expose alert-level history to .NET apps.get_alert_history()in C# to retrieve and display alert codes/levels from the nativewolfSSLcontext.Improved Path Detection
certsfolder in parent directories to better support different working directories across Windows and Linux.Sample Application Improvements
wolfSSL-TLS-ClientwolfSSL-TLS-PSK-ClientwolfSSL-TLS-ServerSERVER_NAME,SERVER_PORT, and cipher suite selection.wolfSSL_CSharp-Clients.slnto support concurrent client/server projects.Documentation Updates
README.mdwith:pwsh.exenot recognizedAnyCPUvs.x64)Compatibility Improvements
#warningwith#pragma messagewhen compiling with MSVC (_MSC_VER) to prevent build interruptions.C5287) aroundwc_static_assert.XINET_PTONmacro to cast toPCWSTRorPCSTRbased on Visual Studio version for better Windows API compliance.Dynamic DLL Loading
wolfssl.LoadDLL()to locate and loadwolfssl.dllat runtime.Debug,Debug\\x64) when not found in the working directory.SetVerbosity(true)for diagnostic output about the load process, DLL size, and timestamp.Improved Path Resolution
setPath()now recursively searches parent directories for acertsfolder.Verbose Debug Mode
Alert History & Diagnostics
get_alert_history().Other Fixes
keyTypeTemp,keySizeTemp) to eliminate compiler warnings.MSVC Compatibility Enhancements
#warningwith#pragma message(...)for MSVC (_MSC_VER) to suppress noisy or incompatible warnings during build:Fixes zd# n/a
Testing
How did you test?
Manually tested in VS2022, VS2008
Checklist