SslApplicationProtocol Struktura
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Představuje hodnotu aplikačního protokolu 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)
- Dědičnost
- Implementuje
Příklady
Následující příklad kódu ukazuje vyjednávání protokolu na úrovni aplikace v SslStream. Server inzeruje podporu pro protocol1 a protocol2. Klient inzeruje podporu pro protocol2 a protocol3. Běžně podporovaný protokol (protocol2) se vyjedná během metody handshake.
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
Poznámky
Tento typ obsahuje statická pole s předdefinovanými SslApplicationProtocol hodnotami pro verze HTTP.
Během metody handshake klient odešle seznam dostupných protokolů ALPN a server zvolí nejlepší shodu z tohoto seznamu.
Úplný seznam podporovaných protokolů najdete v tématu ID protokolu TLS Application-Layer Protocol Negotiation (ALPN).
Konstruktory
| Name | Description |
|---|---|
| SslApplicationProtocol(Byte[]) |
Inicializuje novou instanci SslApplicationProtocol. |
| SslApplicationProtocol(String) |
Inicializuje novou instanci SslApplicationProtocol. |
Pole
| Name | Description |
|---|---|
| Http11 |
Získá reprezentaci SslApplicationProtocol HTTP/1.1 TLS aplikační protokol. |
| Http2 |
Získá reprezentaci SslApplicationProtocol http/2 TLS aplikační protokol. |
Vlastnosti
| Name | Description |
|---|---|
| Protocol |
Získá aktuální aplikační protokol TLS reprezentovaný tímto SslApplicationProtocol. |
Metody
| Name | Description |
|---|---|
| Equals(Object) |
Porovná SslApplicationProtocol se zadaným objektem. |
| Equals(SslApplicationProtocol) |
Porovná zadanou SslApplicationProtocolSslApplicationProtocol instanci. |
| GetHashCode() |
Vrátí kód hash instance SslApplicationProtocol . |
| ToString() |
Přepíše metodu ToString() . |
Operátory
| Name | Description |
|---|---|
| Equality(SslApplicationProtocol, SslApplicationProtocol) |
Operátor rovnosti pro porovnání dvou SslApplicationProtocol objektů. |
| Inequality(SslApplicationProtocol, SslApplicationProtocol) |
Operátor nerovnosti pro porovnání dvou SslApplicationProtocol objektů. |