Skip to content
Merged
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
22 changes: 21 additions & 1 deletion tls-uses-pqc/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;

SetOpenSSLImportResolver();

// Create a self-signed certificate.
using var key = ECDsa.Create();
var certReq = new CertificateRequest("CN=localhost", key, HashAlgorithmName.SHA256);
Expand Down Expand Up @@ -55,6 +57,24 @@
return 1;

// Use OpenSSL interop to get the negotiated key exchange group (SslStream doesn't expose this information).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this comment be moved now?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Everything below the comment is for the interop.

static void SetOpenSSLImportResolver()
{
// Use the latest OpenSSL version on the system.
NativeLibrary.SetDllImportResolver(Assembly.GetExecutingAssembly(), (name, assembly, searchPath) =>
{
if (name == "libssl")
{
if (NativeLibrary.TryLoad("libssl.so.4", assembly, searchPath, out var h) ||
NativeLibrary.TryLoad("libssl.so.3", assembly, searchPath, out h))
{
return h;
}
throw new NotSupportedException($"Cannot resolve {name}.");
}
return IntPtr.Zero; // Use the default resolution logic.
});
}

static string? GetNegotiatedGroupName(SslStream sslStream)
{
var secCtxField = typeof(SslStream).GetField("_securityContext", BindingFlags.NonPublic | BindingFlags.Instance)!;
Expand All @@ -72,5 +92,5 @@
}
}

[DllImport("libssl.so.3")]
[DllImport("libssl")]
static extern IntPtr SSL_get0_group_name(IntPtr ssl);
Loading