SslStream.AuthenticateAsClientAsync 方法
定义
对客户端-服务器连接中的客户端进行身份验证以作为异步操作。Authenticate the client side of a client-server connection as an asynchronous operation.
重载
| 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. 身份验证过程使用指定的证书集合和 SSL 协议。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. 身份验证过程使用指定的证书集合和系统默认的 SSL 协议。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. 身份验证过程使用 |
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. 身份验证过程使用指定的证书集合和 SSL 协议。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
参数
- clientCertificates
- X509CertificateCollection
包含客户端证书的 X509CertificateCollection。The X509CertificateCollection that contains client certificates.
- enabledSslProtocols
- SslProtocols
SslProtocols 值,该值表示进行身份验证所使用的协议。The SslProtocols value that represents protocols used for authentication.
- checkCertificateRevocation
- Boolean
一个 Boolean 值,该值指定身份验证期间是否检查证书吊销列表。A Boolean value that specifies whether the certificate revocation list is checked during authentication.
返回
表示异步操作的任务对象。The task object representing the asynchronous operation.
例外
身份验证失败,并使此对象处于不可用的状态。The authentication failed and left this object in an unusable state.
已进行了身份验证。Authentication has already occurred.
或-or- 之前已尝试使用此 SslStream 进行了服务器身份验证。Server authentication using this SslStream was tried previously.
或-or- 身份验证已在进行中。Authentication is already in progress.
此对象已关闭。This object has been closed.
注解
从 .NET Framework 4.7 开始,此方法使用 None 进行身份验证,这允许操作系统选择要使用的最佳协议,并将其用于阻止不安全的协议。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. 在 .NET Framework 4.6(以及安装了最新安全修补程序的 .NET Framework 4.5)中,允许的 TLS/SSL 协议版本为 1.2、1.1 和 1.0(除非通过编辑 Windows 注册表禁用强加密)。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).
当身份验证成功时,必须检查 IsEncrypted 和 IsSigned 属性,以确定所使用的安全服务 SslStream 。When authentication succeeds, you must check the IsEncrypted and IsSigned properties to determine what security services are used by the SslStream. 检查 IsMutuallyAuthenticated 属性以确定是否发生了相互身份验证。Check the IsMutuallyAuthenticated property to determine whether mutual authentication occurred.
如果身份验证失败,则会收到 AuthenticationException ,此 SslStream 操作不再可用。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.
备注
SSL 版本2协议不支持客户端证书。Client certificates are not supported in the SSL version 2 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. 身份验证过程使用指定的证书集合和系统默认的 SSL 协议。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
参数
- clientCertificates
- X509CertificateCollection
包含客户端证书的 X509CertificateCollection。The X509CertificateCollection that contains client certificates.
- checkCertificateRevocation
- Boolean
一个 Boolean 值,该值指定身份验证期间是否检查证书吊销列表。A Boolean value that specifies whether the certificate revocation list is checked during authentication.
返回
表示异步操作的任务对象。The task object representing the asynchronous operation.
例外
身份验证失败,并使此对象处于不可用的状态。The authentication failed and left this object in an unusable state.
已进行了身份验证。Authentication has already occurred.
或-or- 之前已尝试使用此 SslStream 进行了服务器身份验证。Server authentication using this SslStream was tried previously.
或-or- 身份验证已在进行中。Authentication is already in progress.
此对象已关闭。This object has been closed.
注解
从 .NET Framework 4.7 开始,此方法使用 None 进行身份验证,这允许操作系统选择要使用的最佳协议,并将其用于阻止不安全的协议。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. 在 .NET Framework 4.6(以及安装了最新安全修补程序的 .NET Framework 4.5)中,允许的 TLS/SSL 协议版本为 1.2、1.1 和 1.0(除非通过编辑 Windows 注册表禁用强加密)。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).
当身份验证成功时,必须检查 IsEncrypted 和 IsSigned 属性,以确定所使用的安全服务 SslStream 。When authentication succeeds, you must check the IsEncrypted and IsSigned properties to determine what security services are used by the SslStream. 检查 IsMutuallyAuthenticated 属性以确定是否发生了相互身份验证。Check the IsMutuallyAuthenticated property to determine whether mutual authentication occurred.
如果身份验证失败,则会收到 AuthenticationException ,此 SslStream 操作不再可用。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.
备注
SSL 版本2协议不支持客户端证书。Client certificates are not supported in the SSL version 2 protocol.
适用于
AuthenticateAsClientAsync(String)
由客户端调用,以对服务器或客户端服务器连接中的客户端(可选)进行身份验证,此为异步操作。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
参数
返回
表示异步操作的任务对象。The task object representing the asynchronous operation.
例外
targetHost 为 null。targetHost is null.
身份验证失败,并使此对象处于不可用的状态。The authentication failed and left this object in an unusable state.
已进行了身份验证。Authentication has already occurred.
或-or- 之前已尝试使用此 SslStream 进行了服务器身份验证。Server authentication using this SslStream was tried previously.
或-or- 身份验证已在进行中。Authentication is already in progress.
此对象已关闭。This object has been closed.
注解
从 .NET Framework 4.7 开始,此方法使用 None 进行身份验证,这允许操作系统选择要使用的最佳协议,并将其用于阻止不安全的协议。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. 在 .NET Framework 4.6(以及安装了最新安全修补程序的 .NET Framework 4.5)中,允许的 TLS/SSL 协议版本为 1.2、1.1 和 1.0(除非通过编辑 Windows 注册表禁用强加密)。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. 为指定的值 targetHost 必须与服务器证书上的名称匹配。The value specified for targetHost must match the name on the server's certificate.
当身份验证成功时,必须检查 IsEncrypted 和 IsSigned 属性,以确定所使用的安全服务 SslStream 。When authentication succeeds, you must check the IsEncrypted and IsSigned properties to determine what security services are used by the SslStream. 检查 IsMutuallyAuthenticated 属性以确定是否发生了相互身份验证。Check the IsMutuallyAuthenticated property to determine whether mutual authentication occurred.
如果身份验证失败,则会收到 AuthenticationException ,此 SslStream 操作不再可用。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.
适用于
AuthenticateAsClientAsync(SslClientAuthenticationOptions, CancellationToken)
由客户端调用,以对服务器或客户端服务器连接中的客户端(可选)进行身份验证,此为异步操作。Called by clients to authenticate the server and optionally the client in a client-server connection as an asynchronous operation. 身份验证过程使用 sslClientAuthenticationOptions 属性包中指定的信息。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
参数
- sslClientAuthenticationOptions
- SslClientAuthenticationOptions
SSL 连接的属性包。The property bag for the SSL connection.
- cancellationToken
- CancellationToken
要监视取消请求的标记。The token to monitor for cancellation requests.
返回
表示异步操作的任务对象。The task object representing the asynchronous operation.
例外
sslClientAuthenticationOptions 为 null。sslClientAuthenticationOptions is null.
身份验证失败,并使此对象处于不可用的状态。The authentication failed and left this object in an unusable state.
已进行了身份验证。Authentication has already occurred.
或-or- 之前已尝试使用此 SslStream 进行了服务器身份验证。Server authentication using this SslStream was tried previously.
或-or- 身份验证已在进行中。Authentication is already in progress.
此对象已关闭。This object has been closed.
注解
当身份验证成功时,必须检查 IsEncrypted 和 IsSigned 属性,以确定所使用的安全服务 SslStream 。When authentication succeeds, you must check the IsEncrypted and IsSigned properties to determine what security services are used by the SslStream. 检查 IsMutuallyAuthenticated 属性以确定是否发生了相互身份验证。Check the IsMutuallyAuthenticated property to determine whether mutual authentication occurred.
如果身份验证失败,则会收到 AuthenticationException ,此 SslStream 操作不再可用。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.