【问题标题】:Bouncy Castle - Obsolete LegacyTlsClient充气城堡 - 过时的 LegacyTlsClient
【发布时间】:2015-09-14 02:34:23
【问题描述】:

我想使用以下代码创建一个带有 Bouncy Castle 的 TlsClient

public SecureTcpClient(string host, int port)
    : this(host, port, new LegacyTlsClient(new AlwaysValidVerifyer()))
{

}

然而,这个类 LegacyTlsClient 已经过时了,但我对 Bouncy Castle 的了解不足以解决这个问题。应该使用哪个类来替换 LegacyTlsClient。

【问题讨论】:

  • 有一个 DefaultTlsClient 未被弃用,但看起来你必须实现它,因为它是抽象的。还有一个 PSKTlsClient 和一个 SRPTlsClient,它们也是抽象的。

标签: .net bouncycastle


【解决方案1】:

你应该直接使用 DefaultTlsClient 类,像这样:

class TlsClient : DefaultTlsClient {
    public override TlsAuthentication GetAuthentication() {
        return new CustomTlsAuthentication();
    }
}

class CustomTlsAuthentication : TlsAuthentication {
    public TlsCredentials GetClientCredentials(CertificateRequest certificateRequest) {
        // return client certificate here if necessary
        return null;
    }

    public void NotifyServerCertificate(Certificate serverCertificate) {
        // validate server certificate here
    }
}

【讨论】:

    猜你喜欢
    • 2013-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-19
    • 2019-12-29
    • 1970-01-01
    • 1970-01-01
    • 2011-03-13
    相关资源
    最近更新 更多