证书身份验证失败,仅在.Net中出现SSL错误

时间:2016-11-03 17:04:13

标签: c# ssl httpwebrequest client-certificates

我尝试使用相互证书身份验证与外部网站进行通信,但是我正在接收"无法为具有权限的SSL / TLS建立安全通道"例外。我已将其缩小到以下代码段(删除了敏感内容):

func mattermostPrintChannels(client *mattermost.Client) {
    channelsResult, err := client.GetChannels("")
    if err != nil {
        fmt.Print("Couldn't get channels: ", err)
        return
    }
    channelList := channelsResult.Data.(*mattermost.ChannelList)
    fmt.Print("Channels:")
    for _, channel := range channelList.Channels {
        fmt.Printf("%s -> %s", channel.Id, channel.DisplayName)
    }
}

我已正确设置证书等,此代码可以成功找到它们,证书.HasPrivateKey = true,但失败了。 SoapUI愉快地与TLS连接。当我访问网站时,Chrome报告没有证书错误。但是,上面的代码总是抛出异常。我已经尝试了所有3个TLS版本但没有成功。使用ServicePointManager跳过服务器证书验证没有任何区别。

奇怪的是,如果我指定SSL3

channelList:  :  ([]interface {}) (len=1 cap=1) {
 (*model.ChannelList)(<nil>)
}

然后该过程成功完成,但我自然不想使用SSL3。该应用程序是在Server 2012上运行的.Net 4.6。

1 个答案:

答案 0 :(得分:0)

经过几个月甚至更长时间的挖掘和挖掘,我最终尝试使用SSLStream建立连接,得到一个不同的异常,并找到这个答案:A call to SSPI failed, see inner exception - The Local Security Authority cannot be contacted

建议您添加以下注册表项: [HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ SecurityProviders \ SCHANNEL \ KeyExchangeAlgorithms \ Diffie-Hellman]“ClientMinKeyBitLength”= dword:00000200

这会将Diffie-Hellman的最小密钥长度切换为512位。在Windows Update中将此最小值提高到1024位以尝试缓解logjam攻击,因此请注意设置此值,因为它是系统范围的,并且可能会打开针对您系统的攻击媒介。