Skip to content

[API Proposal]: Export Keying Material for TLS sessions #112529

@alanssitis

Description

@alanssitis

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions