-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Open
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.Net.Security
Milestone
Description
Background and motivation
Add an API that exposes the functionality outlined in RFC 5705: Keying Material Exporters.
This is useful as it will allow my company to drop an external library to use this functionality.
API Proposal
updated by @rzikm
namespace System.Net.Security;
public partial class SslStream {
public void ExportKeyingMaterial(string label, Span<byte>output);
public void ExportKeyingMaterial(string label, ReadOnlySpan<byte> context, Span<byte> output);
}API Usage
await using var sslStream = new SslStream(someStream, true);
// Initialize and finish SSL handshake
await sslStream.AuthenticateAsServerAsync(...);
// or as client
// await sslStream.AuthenticateAsClientAsync(...);
// Use the export keying material API
byte[] keyingMaterial = new byte[128];
sslStream.ExportKeyingMaterial("showcase key", keyingMaterial);
Console.WriteLine(Convert.ToHexString(keyingMaterial));Alternative proposal
Unless I am mistaken, the label string is supposed to be an ASCII string, so we can accept it as ROS
namespace System.Net.Security;
public partial class SslStream {
public void ExportKeyingMaterial(ReadOnlySpan<byte> label, Span<byte>output);
public void ExportKeyingMaterial(ReadOnlySpan<byte> label, ReadOnlySpan<byte> context, Span<byte> output);
}API Usage
since labels are usually literal constants in code, UTF-8 string literals can be used
byte[] keyingMaterial = new byte[128];
sslStream.ExportKeyingMaterial("showcase key"u8, keyingMaterial);
Console.WriteLine(Convert.ToHexString(keyingMaterial));Risks
Platform support:
- Windows - needs verification (should be implementable as per
https://learn.microsoft.com/en-us/windows/win32/api/schannel/ns-schannel-secpkgcontext_keyingmaterialinfo, https://learn.microsoft.com/en-us/windows/win32/secauthn/querycontextattributes--schannel, see SECPKG_ATTR_KEYING_MATERIAL) - Linux - implementable (https://docs.openssl.org/master/man3/SSL_export_keying_material/)
- OSX - Not implemented for Secure Transport (package used to back SslStream implementaion)
alanssitis
Metadata
Metadata
Assignees
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.Net.Security