[API Proposal]: Export Keying Material for TLS sessions

Open
#112,529 14 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
38/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
csharp

Research direction

Start with the SslStream entry point and RFC 5705, then review the Windows Schannel and Linux OpenSSL references named in the issue. Determine how the proposed overloads map to the listed platform support, including Secure Transport on macOS. Done means the API behavior and platform availability are implemented and validated consistently.

Written by the indexing model from the issue text.

Description

api-ready-for-review area-System.Net.Security
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:

Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/runtime

All issues in dotnet/runtime

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.