单声道https webrequest失败,并且“验证或解密失败” [英] Mono https webrequest fails with "The authentication or decryption has failed"
问题描述
我正在制作一个简单的REST客户端,以便在我的C#应用程序中使用。在Windows上的.net它适用于http://和https://连接。在Ubuntu 10.10的单声道2.6.7(也用2.8测试,结果相同)只有http://有效。 https:// connections在request.GetResponse()方法上抛出此异常:
未处理的异常:System.Net.WebException :获取响应流时出错(写入:身份验证或解密失败。):SendFailure ---> System.IO.IOException:身份验证或解密失败。 ---> Mono.Security.Protocol.Tls.TlsException:从服务器收到的证书无效。错误代码:0xffffffff800b010a
Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.validateCertificates(Mono.Security.X509.X509CertificateCollection证书)[0x00000] in< filename unknown> ;:0
at在Mono.Security.Protocol.Tls.Handshake.HandshakeMessage.Process()[0x00000 ]< filename unknown>:0
at(wrapper remoting-invoke-with-check)Mono.Security.Protocol.Tls.Handshake.HandshakeMessage:Process()
at Mono.Security.Protocol。 Tls.ClientRecordProtocol.ProcessHandshakeMessage(Mono.Security.Protocol.Tls.TlsStream handMsg)[0x00000] in< filename unknown>:0
at Mono.Security.Protocol.Tls.RecordProtocol.InternalReceiveRecordCallback(IAsyncResult asyncResult)[0x00000 ]< filename unknown>:0
---内部异常堆栈跟踪结束---
at Mono.Security.Protocol.Tls.SslS treamBase.AsyncHandshakeCallback(IAsyncResult asyncResult)[0x00000]在< filename unknown>中:0
---内部异常堆栈跟踪结束---
在System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) [0x00000] in< filename unknown>:0
at System.Net.HttpWebRequest.GetResponse()[0x00000] in< filename unknown> ;:0
我一直无法找到解决此问题的方法。任何人都知道为什么会发生这种情况以及如何解决它?
同样,这只在Mono中失败,.Net似乎没有任何建立连接的问题。
这里是调用代码:
public JToken DoRequest(string path,params string []参数){
if(!path.StartsWith(/)){
path =/+ path;
}
string fullUrl = url + path + ToQueryString(parameters);
if(DebugUrls)Console.WriteLine(Requesting:{0},fullUrl);
WebRequest request = HttpWebRequest.CreateDefault(new Uri(fullUrl));
using(WebResponse response = request.GetResponse())
using(Stream responseStream = response.GetResponseStream()){
return ReadResponse(responseStream);
}
}
Mono默认情况下不信任任何证书,导入Mozilla受信任的root权限,您可以在mozroots.exe所在的单声道安装文件夹中运行 mozroots --import --quiet
/ p>
I'm making a simple REST client to use in my C# applications. In .net on Windows It works great with http:// and https:// connections. In mono 2.6.7 (Also tested with 2.8 with the same results) on Ubuntu 10.10 only http:// works. https:// connections throw up this exception on the request.GetResponse() method:
Unhandled Exception: System.Net.WebException: Error getting response stream (Write: The authentication or decryption has failed.): SendFailure ---> System.IO.IOException: The authentication or decryption has failed. ---> Mono.Security.Protocol.Tls.TlsException: Invalid certificate received from server. Error code: 0xffffffff800b010a
at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.validateCertificates (Mono.Security.X509.X509CertificateCollection certificates) [0x00000] in <filename unknown>:0
at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.ProcessAsTls1 () [0x00000] in <filename unknown>:0
at Mono.Security.Protocol.Tls.Handshake.HandshakeMessage.Process () [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) Mono.Security.Protocol.Tls.Handshake.HandshakeMessage:Process ()
at Mono.Security.Protocol.Tls.ClientRecordProtocol.ProcessHandshakeMessage (Mono.Security.Protocol.Tls.TlsStream handMsg) [0x00000] in <filename unknown>:0
at Mono.Security.Protocol.Tls.RecordProtocol.InternalReceiveRecordCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
at System.Net.HttpWebRequest.GetResponse () [0x00000] in <filename unknown>:0
I haven't been able to find any way to fix this. Anyone have any idea why this is happening and how to fix it?
Again, this only fails in Mono, .Net doesn't seem to have any problem establishing a connection.
here's the calling code:
public JToken DoRequest(string path, params string[] parameters) {
if(!path.StartsWith("/")) {
path = "/" + path;
}
string fullUrl = url + path + ToQueryString(parameters);
if(DebugUrls) Console.WriteLine("Requesting: {0}", fullUrl);
WebRequest request = HttpWebRequest.CreateDefault(new Uri(fullUrl));
using(WebResponse response = request.GetResponse())
using(Stream responseStream = response.GetResponseStream()) {
return ReadResponse(responseStream);
}
}
Mono does not trust any certificate by default, to import the Mozilla trusted root authorities you can run mozroots --import --quiet
in the mono installation folder where mozroots.exe is located
这篇关于单声道https webrequest失败,并且“验证或解密失败”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!