C# HTTPS请求上的Mono SecureChannel失败
运行以下行:C# HTTPS请求上的Mono SecureChannel失败,c#,mono,C#,Mono,运行以下行: new HttpClient().GetAsync(url).GetAwaiter().GetResult(); // url being an https endpoint with a valid certificate when I browse to the image from a browser 我得到以下例外情况: Error: SecureChannelFailure (The authentication or decryption has failed.)
new HttpClient().GetAsync(url).GetAwaiter().GetResult(); // url being an https endpoint with a valid certificate when I browse to the image from a browser
我得到以下例外情况:
Error: SecureChannelFailure (The authentication or decryption has failed.)
Error: ConnectFailure (TLS Support not available.)
我尝试添加ServicePointManager
解决方案:
ServicePointManager.ServerCertificateValidationCallback += (a, b, c, d) => true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls;
单独、一起以及与此回调实现一起:
public static bool ValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
if (sslPolicyErrors == SslPolicyErrors.None)
return true;
var isOk = true;
for (int i = 0; i < chain.ChainStatus.Length; i++)
if (chain.ChainStatus[i].Status != X509ChainStatusFlags.RevocationStatusUnknown)
{
chain.ChainPolicy.RevocationFlag = X509RevocationFlag.EntireChain;
chain.ChainPolicy.RevocationMode = X509RevocationMode.Online;
chain.ChainPolicy.UrlRetrievalTimeout = new TimeSpan(0, 1, 0);
chain.ChainPolicy.VerificationFlags = X509VerificationFlags.AllFlags;
var chainIsValid = chain.Build((X509Certificate2)certificate);
if (!chainIsValid)
isOk = false;
}
return isOk;
}
我正在Linux上使用Mono 4.4.1,我还尝试导入运行以下操作的证书:
mozroots --import --sync --url "http://hg.mozilla.org/releases/mozilla-release/raw-file/default/security/nss/lib/ckfw/builtins/certdata.txt"
Mono4.4.1不包括BTL,请使用Mono5.x