Skip to content
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

CSharp Wrapper SNI Support #7610

Merged
merged 15 commits into from
Jun 5, 2024
Merged

Conversation

gasbytes
Copy link
Contributor

@gasbytes gasbytes commented Jun 3, 2024

Description

Fixes zd#17990

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

@gasbytes gasbytes marked this pull request as draft June 3, 2024 14:54
@gasbytes gasbytes assigned gasbytes and wolfSSL-Bot and unassigned wolfSSL-Bot and gasbytes Jun 3, 2024
@gasbytes gasbytes marked this pull request as ready for review June 3, 2024 15:41
@gasbytes gasbytes removed the request for review from wolfSSL-Bot June 3, 2024 15:47
@dgarske dgarske changed the title Sni wrappers CSharp Wrapper SNI Support Jun 3, 2024
wrapper/CSharp/wolfSSL_CSharp/wolfSSL.cs Show resolved Hide resolved
@@ -417,6 +459,8 @@ public void free()

public static readonly int SUCCESS = 1;
public static readonly int FAILURE = 0;
public static readonly int WOLFSSL_SNI_HOST_NAME = 0;
public static readonly int WOLFSSL_SNI_HOST_NAME_OUTER = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please remove WOLFSSL_SNI_HOST_NAME_OUTER here and also in ssl.h. I cannot find any place it is used and its a duplicate value in the enum, which is odd.

@dgarske dgarske self-requested a review June 3, 2024 19:24
@dgarske dgarske self-assigned this Jun 3, 2024
/// </summary>
private static bool haveSNI(string[] args)
{
if (args != null && args.Length == 2 && args[0] == "-S")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this working for you? mono wolfSSL.exe -S shows SNI IS: OFF

```

Build wolfSSL and install:
# Build wolfSSL and install
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make ### for right heading.

@@ -38,21 +40,21 @@ make check
sudo make install
```

Build and run the wrapper:
# Build and run the wrapper
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make ### for right heading.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also show building the client with mono and add SNI example / docs?


Run the example:
# Run the example
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make ### for right heading.

@dgarske dgarske removed their assignment Jun 3, 2024
@dgarske dgarske self-requested a review June 4, 2024 17:16
Copy link
Contributor

@dgarske dgarske left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work. Very close to complete!

@@ -3811,7 +3811,6 @@ WOLFSSL_API void* wolfSSL_CTX_GetHeap(WOLFSSL_CTX* ctx, WOLFSSL* ssl);
/* SNI types */
enum {
WOLFSSL_SNI_HOST_NAME = 0,
WOLFSSL_SNI_HOST_NAME_OUTER = 0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: This was an artifact from an early ECH that was later changed and this was left behind and should be removed.

@@ -20224,6 +20206,27 @@ void wolfSSL_THREADID_set_numeric(void* id, unsigned long val)
* HAVE_LIGHTY || WOLFSSL_HAPROXY || WOLFSSL_OPENSSH ||
* HAVE_SBLIM_SFCB)) */

#ifdef HAVE_SNI
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Moved these outside of the strict compatibility layer macros and made accessible to match the WOLFSSL_CTX member of HAVE_SNI only.


### Enabling SNI

To enable SNI, just pass the `-S` argument with the specified hostname:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The server.exe also needs run with -S to work. Please add that to the steps.

/// wolfSSL.
/// <param name="args">Parameters passed via command line</param>
/// </summary>
private static bool haveSNI(string[] args)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please have this function return int with the index for the i+1 instead of bool, so you don't have to hard code args[1].Trim(); below. Use -1 to indicate not found.

return;
}

if (haveSNI(args))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update to:

int sniArg = haveSNI(args);
if (sniArg >= 0) {
    string sniHostNameString = args[sniArg].Trim();

string fileCert = @"server-cert.pem";
string fileKey = @"server-key.pem";
string fileCert = @"../../certs/server-cert.pem";
string fileKey = @"../../certs/server-key.pem";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change has implications on the Windows VS build:

PS D:\work\sni-wrappers\wrapper\CSharp\DLL Debug\Win32> .\wolfSSL-TLS-Server.exe
Calling ctx Init from wolfSSL
Finished init of ctx .... now load in cert and key
Could not find cert or key file
freeing ctx handle

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might consider logic like wolfssl/test.h ChangeToWolfRoot or gate the path based on _WIN32...

@@ -87,6 +121,12 @@ public static void Main(string[] args)
return;
}

if (!File.Exists(dhparam.ToString())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this on Visual Studio 2022. Got this error:

The name 'dhparam' does not exist in the current context
wolfSSL-TLS-Server
C:\Users\David Garske\Documents\wolfssl\wrapper\CSharp\wolfSSL-TLS-Server\wolfSSL-TLS-Server.cs
124

Copy link
Contributor

@dgarske dgarske left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on Windows and Linux. Thanks Reda. @JacobBarthelmeh will you give it a final?

@JacobBarthelmeh JacobBarthelmeh merged commit 1852615 into wolfSSL:master Jun 5, 2024
109 checks passed
jefferyq2 pushed a commit to jefferyq2/wolfssl that referenced this pull request Jun 9, 2024
@gasbytes gasbytes deleted the sni-wrappers branch August 28, 2024 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants