SslApplicationProtocol 構造体

定義

TLS アプリケーション プロトコルの値を表します。

public value class SslApplicationProtocol : IEquatable<System::Net::Security::SslApplicationProtocol>
public readonly struct SslApplicationProtocol : IEquatable<System.Net.Security.SslApplicationProtocol>
type SslApplicationProtocol = struct
Public Structure SslApplicationProtocol
Implements IEquatable(Of SslApplicationProtocol)
継承
SslApplicationProtocol
実装

次のコード例は、 でのアプリケーション レベルプロトコルのネゴシエーションを SslStream示しています。 サーバーは と protocol2のサポートをprotocol1アドバタイズします。 クライアントは と protocol3のサポートをprotocol2アドバタイズします。 一般的にサポートされるプロトコル (protocol2) は、ハンドシェイク中にネゴシエートされます。

async Task Server(NetworkStream stream, X509Certificate2 serverCertificate)
{
    using var server = new SslStream(stream);

    await server.AuthenticateAsServerAsync(new SslServerAuthenticationOptions
    {
        ServerCertificate = serverCertificate,
        ApplicationProtocols = new()
        {
            new("protocol1"),
            new("protocol2"),
        }
    });

    string protocol = Encoding.ASCII.GetString(server.NegotiatedApplicationProtocol.Protocol.Span);
    System.Console.WriteLine($"Server - negotiated protocol: {protocol}");
}

async Task Client(NetworkStream stream, string hostName)
{
    using var client = new SslStream(stream);

    await client.AuthenticateAsClientAsync(new SslClientAuthenticationOptions
    {
        // the host name must match the name on the certificate used on the server side
        TargetHost = hostName,
        ApplicationProtocols = new()
        {
            new("protocol2"),
            new("protocol3")
        }
    });

    string protocol = Encoding.ASCII.GetString(client.NegotiatedApplicationProtocol.Protocol.Span);
    System.Console.WriteLine($"Client - negotiated protocol: {protocol}");
}

// possible output:
//   Server - negotiated protocol: protocol2
//   Client - negotiated protocol: protocol2
Async Function Server(stream As NetworkStream, serverCertificate As X509Certificate2) As Task
    Using serverStream As SslStream = new SslStream(stream)
        Dim options as New SslServerAuthenticationOptions() With
        {
            .ServerCertificate = serverCertificate,
            .ApplicationProtocols = New List(Of SslApplicationProtocol) From
            {
                New SslApplicationProtocol("protocol1"),
                New SslApplicationProtocol("protocol2")
            }
        }
        Await serverStream.AuthenticateAsServerAsync(options)

        Dim protocol As String = Encoding.ASCII.GetString(
            serverStream.NegotiatedApplicationProtocol.Protocol.Span)
        System.Console.WriteLine($"Server - negotiated protocol: {protocol}")
    End Using
End Function

Async Function Client(stream As NetworkStream, hostName As String ) As Task
    Using clientStream As SslStream = new SslStream(stream)
        Dim options as New SslClientAuthenticationOptions() With
        {
            .TargetHost = hostName,
            .ApplicationProtocols = New List(Of SslApplicationProtocol) From
            {
                New SslApplicationProtocol("protocol2"),
                New SslApplicationProtocol("protocol3")
            }
        }
        Await clientStream.AuthenticateAsClientAsync(options)

        Dim protocol As String = Encoding.ASCII.GetString(
            clientStream.NegotiatedApplicationProtocol.Protocol.Span)
        System.Console.WriteLine($"Client - negotiated protocol: {protocol}")
    End Using
End Function

' possible output:
'   Server - negotiated protocol: protocol2
'   Client - negotiated protocol: protocol2

注釈

この型には、HTTP バージョンの定義済みの SslApplicationProtocol 値を持つ静的フィールドが含まれています。

ハンドシェイク中に、クライアントは使用可能な ALPN プロトコルの一覧を送信し、サーバーはその一覧から最適な一致を選択します。

サポートされているプロトコルの完全な一覧については、「 TLS Application-Layer プロトコル ネゴシエーション (ALPN) プロトコル ID」を参照してください。

コンストラクター

SslApplicationProtocol(Byte[])

SslApplicationProtocolの新しいインスタンスを初期化します。

SslApplicationProtocol(String)

SslApplicationProtocolの新しいインスタンスを初期化します。

フィールド

Http11

HTTP/1.1 TLS アプリケーション プロトコルを表す SslApplicationProtocol を取得します。

Http2

HTTP/2 TLS アプリケーション プロトコルを表す SslApplicationProtocol を取得します。

Http3

SslApplicationProtocol HTTP 3.0 のインスタンスを定義します。

プロパティ

Protocol

この SslApplicationProtocol によって表される現行の TLS アプリケーション プロトコルを取得します。

メソッド

Equals(Object)

SslApplicationProtocol と指定したオブジェクトを比較します。

Equals(SslApplicationProtocol)

SslApplicationProtocol と指定した SslApplicationProtocol インスタンスを比較します。

GetHashCode()

SslApplicationProtocol インスタンスのハッシュ コードを返します。

ToString()

ToString() メソッドをオーバーライドします。

演算子

Equality(SslApplicationProtocol, SslApplicationProtocol)

2 つの SslApplicationProtocol オブジェクトを比較する等値演算子。

Inequality(SslApplicationProtocol, SslApplicationProtocol)

2 つの SslApplicationProtocol オブジェクトを比較する非等値演算子。

適用対象