Επεξεργασία

Κοινή χρήση μέσω


SslStream.AuthenticateAsClientAsync Method

Definition

Authenticate the client side of a client-server connection as an asynchronous operation.

Overloads

AuthenticateAsClientAsync(String, X509CertificateCollection, SslProtocols, Boolean)

Called by clients to authenticate the server and optionally the client in a client-server connection as an asynchronous operation. The authentication process uses the specified certificate collection and SSL protocol.

AuthenticateAsClientAsync(String, X509CertificateCollection, Boolean)

Called by clients to authenticate the server and optionally the client in a client-server connection as an asynchronous operation. The authentication process uses the specified certificate collection and the system default SSL protocol.

AuthenticateAsClientAsync(String)

Called by clients to authenticate the server and optionally the client in a client-server connection as an asynchronous operation.

AuthenticateAsClientAsync(SslClientAuthenticationOptions, CancellationToken)

Called by clients to authenticate the server and optionally the client in a client-server connection as an asynchronous operation. The authentication process uses information specified in the sslClientAuthenticationOptions property bag.

AuthenticateAsClientAsync(String, X509CertificateCollection, SslProtocols, Boolean)

Source:
SslStream.cs
Source:
SslStream.cs
Source:
SslStream.cs

Called by clients to authenticate the server and optionally the client in a client-server connection as an asynchronous operation. The authentication process uses the specified certificate collection and SSL protocol.

public:
 virtual System::Threading::Tasks::Task ^ AuthenticateAsClientAsync(System::String ^ targetHost, System::Security::Cryptography::X509Certificates::X509CertificateCollection ^ clientCertificates, System::Security::Authentication::SslProtocols enabledSslProtocols, bool checkCertificateRevocation);
public virtual System.Threading.Tasks.Task AuthenticateAsClientAsync (string targetHost, System.Security.Cryptography.X509Certificates.X509CertificateCollection? clientCertificates, System.Security.Authentication.SslProtocols enabledSslProtocols, bool checkCertificateRevocation);
public virtual System.Threading.Tasks.Task AuthenticateAsClientAsync (string targetHost, System.Security.Cryptography.X509Certificates.X509CertificateCollection clientCertificates, System.Security.Authentication.SslProtocols enabledSslProtocols, bool checkCertificateRevocation);
abstract member AuthenticateAsClientAsync : string * System.Security.Cryptography.X509Certificates.X509CertificateCollection * System.Security.Authentication.SslProtocols * bool -> System.Threading.Tasks.Task
override this.AuthenticateAsClientAsync : string * System.Security.Cryptography.X509Certificates.X509CertificateCollection * System.Security.Authentication.SslProtocols * bool -> System.Threading.Tasks.Task
Public Overridable Function AuthenticateAsClientAsync (targetHost As String, clientCertificates As X509CertificateCollection, enabledSslProtocols As SslProtocols, checkCertificateRevocation As Boolean) As Task

Parameters

targetHost
String

The name of the server that will share this SslStream.

clientCertificates
X509CertificateCollection

The X509CertificateCollection that contains client certificates.

enabledSslProtocols
SslProtocols

The SslProtocols value that represents protocols used for authentication.

checkCertificateRevocation
Boolean

A Boolean value that specifies whether the certificate revocation list is checked during authentication.

Returns

The task object representing the asynchronous operation.

Exceptions

The authentication failed and left this object in an unusable state.

Authentication has already occurred.

-or-

Server authentication using this SslStream was tried previously.

-or-

Authentication is already in progress.

This object has been closed.

Remarks

Starting with .NET Framework 4.7, this method authenticates using None, which allows the operating system to choose the best protocol to use, and to block protocols that are not secure. In .NET Framework 4.6 (and .NET Framework 4.5 with the latest security patches installed), the allowed TLS/SSL protocols versions are 1.2, 1.1, and 1.0 (unless you disable strong cryptography by editing the Windows Registry).

When authentication succeeds, you must check the IsEncrypted and IsSigned properties to determine what security services are used by the SslStream. Check the IsMutuallyAuthenticated property to determine whether mutual authentication occurred.

If the authentication fails, you receive a AuthenticationException, and this SslStream is no longer useable. You should close this object and remove all references to it so that it can be collected by the garbage collector.

Note

Client certificates are not supported in the SSL version 2 protocol.

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by AuthenticateAsClient(String, X509CertificateCollection, SslProtocols, Boolean).

Applies to

AuthenticateAsClientAsync(String, X509CertificateCollection, Boolean)

Source:
SslStream.cs
Source:
SslStream.cs
Source:
SslStream.cs

Called by clients to authenticate the server and optionally the client in a client-server connection as an asynchronous operation. The authentication process uses the specified certificate collection and the system default SSL protocol.

public:
 virtual System::Threading::Tasks::Task ^ AuthenticateAsClientAsync(System::String ^ targetHost, System::Security::Cryptography::X509Certificates::X509CertificateCollection ^ clientCertificates, bool checkCertificateRevocation);
public virtual System.Threading.Tasks.Task AuthenticateAsClientAsync (string targetHost, System.Security.Cryptography.X509Certificates.X509CertificateCollection? clientCertificates, bool checkCertificateRevocation);
public virtual System.Threading.Tasks.Task AuthenticateAsClientAsync (string targetHost, System.Security.Cryptography.X509Certificates.X509CertificateCollection clientCertificates, bool checkCertificateRevocation);
abstract member AuthenticateAsClientAsync : string * System.Security.Cryptography.X509Certificates.X509CertificateCollection * bool -> System.Threading.Tasks.Task
override this.AuthenticateAsClientAsync : string * System.Security.Cryptography.X509Certificates.X509CertificateCollection * bool -> System.Threading.Tasks.Task
Public Overridable Function AuthenticateAsClientAsync (targetHost As String, clientCertificates As X509CertificateCollection, checkCertificateRevocation As Boolean) As Task

Parameters

targetHost
String

The name of the server that will share this SslStream.

clientCertificates
X509CertificateCollection

The X509CertificateCollection that contains client certificates.

checkCertificateRevocation
Boolean

A Boolean value that specifies whether the certificate revocation list is checked during authentication.

Returns

The task object representing the asynchronous operation.

Exceptions

The authentication failed and left this object in an unusable state.

Authentication has already occurred.

-or-

Server authentication using this SslStream was tried previously.

-or-

Authentication is already in progress.

This object has been closed.

Remarks

Starting with .NET Framework 4.7, this method authenticates using None, which allows the operating system to choose the best protocol to use, and to block protocols that are not secure. In .NET Framework 4.6 (and .NET Framework 4.5 with the latest security patches installed), the allowed TLS/SSL protocols versions are 1.2, 1.1, and 1.0 (unless you disable strong cryptography by editing the Windows Registry).

When authentication succeeds, you must check the IsEncrypted and IsSigned properties to determine what security services are used by the SslStream. Check the IsMutuallyAuthenticated property to determine whether mutual authentication occurred.

If the authentication fails, you receive a AuthenticationException, and this SslStream is no longer useable. You should close this object and remove all references to it so that it can be collected by the garbage collector.

Note

Client certificates are not supported in the SSL version 2 protocol.

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by AuthenticateAsClient(String, X509CertificateCollection, Boolean).

Applies to

AuthenticateAsClientAsync(String)

Source:
SslStream.cs
Source:
SslStream.cs
Source:
SslStream.cs

Called by clients to authenticate the server and optionally the client in a client-server connection as an asynchronous operation.

public:
 virtual System::Threading::Tasks::Task ^ AuthenticateAsClientAsync(System::String ^ targetHost);
public virtual System.Threading.Tasks.Task AuthenticateAsClientAsync (string targetHost);
abstract member AuthenticateAsClientAsync : string -> System.Threading.Tasks.Task
override this.AuthenticateAsClientAsync : string -> System.Threading.Tasks.Task
Public Overridable Function AuthenticateAsClientAsync (targetHost As String) As Task

Parameters

targetHost
String

The name of the server that shares this SslStream.

Returns

The task object representing the asynchronous operation.

Exceptions

targetHost is null.

The authentication failed and left this object in an unusable state.

Authentication has already occurred.

-or-

Server authentication using this SslStream was tried previously.

-or-

Authentication is already in progress.

This object has been closed.

Remarks

Starting with .NET Framework 4.7, this method authenticates using None, which allows the operating system to choose the best protocol to use, and to block protocols that are not secure. In .NET Framework 4.6 (and .NET Framework 4.5 with the latest security patches installed), the allowed TLS/SSL protocols versions are 1.2, 1.1, and 1.0 (unless you disable strong cryptography by editing the Windows Registry). No client certificates are used in the authentication. The certificate revocation list is not checked during authentication. The value specified for targetHost must match the name on the server's certificate.

When authentication succeeds, you must check the IsEncrypted and IsSigned properties to determine what security services are used by the SslStream. Check the IsMutuallyAuthenticated property to determine whether mutual authentication occurred.

If the authentication fails, you receive a AuthenticationException, and this SslStream is no longer useable. You should close this object and remove all references to it so that it can be collected by the garbage collector.

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by AuthenticateAsClient(String).

Applies to

AuthenticateAsClientAsync(SslClientAuthenticationOptions, CancellationToken)

Source:
SslStream.cs
Source:
SslStream.cs
Source:
SslStream.cs

Called by clients to authenticate the server and optionally the client in a client-server connection as an asynchronous operation. The authentication process uses information specified in the sslClientAuthenticationOptions property bag.

public:
 System::Threading::Tasks::Task ^ AuthenticateAsClientAsync(System::Net::Security::SslClientAuthenticationOptions ^ sslClientAuthenticationOptions, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task AuthenticateAsClientAsync (System.Net.Security.SslClientAuthenticationOptions sslClientAuthenticationOptions, System.Threading.CancellationToken cancellationToken = default);
public System.Threading.Tasks.Task AuthenticateAsClientAsync (System.Net.Security.SslClientAuthenticationOptions sslClientAuthenticationOptions, System.Threading.CancellationToken cancellationToken);
member this.AuthenticateAsClientAsync : System.Net.Security.SslClientAuthenticationOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Function AuthenticateAsClientAsync (sslClientAuthenticationOptions As SslClientAuthenticationOptions, Optional cancellationToken As CancellationToken = Nothing) As Task
Public Function AuthenticateAsClientAsync (sslClientAuthenticationOptions As SslClientAuthenticationOptions, cancellationToken As CancellationToken) As Task

Parameters

sslClientAuthenticationOptions
SslClientAuthenticationOptions

The property bag for the SSL connection.

cancellationToken
CancellationToken

The token to monitor for cancellation requests.

Returns

The task object representing the asynchronous operation.

Exceptions

sslClientAuthenticationOptions is null.

The authentication failed and left this object in an unusable state.

Authentication has already occurred.

-or-

Server authentication using this SslStream was tried previously.

-or-

Authentication is already in progress.

This object has been closed.

The cancellation token was canceled. This exception is stored into the returned task.

Remarks

When authentication succeeds, you must check the IsEncrypted and IsSigned properties to determine what security services are used by the SslStream. Check the IsMutuallyAuthenticated property to determine whether mutual authentication occurred.

If the authentication fails, you receive a AuthenticationException, and this SslStream is no longer useable. You should close this object and remove all references to it so that it can be collected by the garbage collector.

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by AuthenticateAsClient(SslClientAuthenticationOptions).

Applies to