如何在不安装证书的情况下在SharpSvn中使用自定义证书颁发机构

时间:2012-07-25 14:38:07

标签: c# ssl sharpsvn certificate-authority

我正在尝试使用SharpSvn访问subversion存储库。存储库只能通过https使用,并且机器使用自己的私有证书颁发机构(不要担心这里的安全性,我相信权限)。

我拥有证书颁发机构的公共根证书,但由于用户访问权限,我无法将证书安装到证书库中。

如果我直接使用subversion,我可以添加:

servers:global:ssl-authority-files=/path/to/cacert.crt
servers:groups:myhost=myhostsdns.com

作为命令行对象或配置文件。

如何在SharpSvn中设置这些选项,以便我可以使用cacert.crt文件,这样当我尝试访问我的存储库时,我没有得到“证书验证失败”,我不必忽略错误?

非常感谢

2 个答案:

答案 0 :(得分:1)

只有在你提出问题后你才意识到这个答案后才会如此?

我通过在SvnClient对象上设置配置选项来解决这个问题:

SvnClient _svnClient = new SvnClient();
_svnClient.Configuration.SetOption("servers", "global", "ssl-authority-files", "/path/to/cacert.crt");
_svnClient.Configuration.SetOption("servers", "groups", "myhost", "myhostsdns.com");

道歉自助,希望它能帮助下一个人。

答案 1 :(得分:0)

扩大Bert Huijben的评论(上图):

client.Authentication.SslServerTrustHandlers += new EventHandler<SharpSvn.Security.SvnSslServerTrustEventArgs>(Authentication_SslServerTrustHandlers);
void Authentication_SslServerTrustHandlers(object sender, SharpSvn.Security.SvnSslServerTrustEventArgs e)
{
    // Look at the rest of the arguments of E, whether you wish to accept

    // If accept:
    e.AcceptedFailures = e.Failures;
    e.Save = true; // Save acceptance to authentication store
}
相关问题