Mono HTTPS异常-身份验证或解密失败
本文关键字:解密 失败 身份验证 HTTPS 异常 Mono | 更新日期: 2023-09-27 18:11:29
当尝试通过HTTPS发布一些数据时,我间歇性地得到此异常。运行在mono 2.10.1(现在更改为2.10.9)。我不知道为什么会发生这种情况,它似乎与请求大小(约2.5MB)无关,因为其他类似大小的请求正在工作。
// these arguments are not null, as I can see them in a log.
var response1 = web1.UploadData(address, "POST", buffer);
堆栈跟踪mono 2.10.1:
System.Net.WebException: An error occurred performing a WebClient request. ---> System.IO.IOException: IO exception during Write. ---> System.NullReferenceException: Object reference not set to an instance of an object
at Mono.Security.Protocol.Tls.SslStreamBase.InternalBeginWrite (Mono.Security.Protocol.Tls.InternalAsyncResult asyncResult) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at Mono.Security.Protocol.Tls.SslStreamBase.InternalBeginWrite (Mono.Security.Protocol.Tls.InternalAsyncResult asyncResult) [0x00000] in <filename unknown>:0
at Mono.Security.Protocol.Tls.SslStreamBase.BeginWrite (System.Byte[] buffer, Int32 offset, Int32 count, System.AsyncCallback callback, System.Object state) [0x00000] in <filename unknown>:0
at System.Net.WebConnection.BeginWrite (System.Net.HttpWebRequest request, System.Byte[] buffer, Int32 offset, Int32 size, System.AsyncCallback cb, System.Object state) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at System.Net.WebClient.UploadData (System.Uri address, System.String method, System.Byte[] data) [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.Net.WebClient:UploadData (System.Uri,string,byte[])
与mono 2.10.9我得到一个不同的错误:
System.Net.WebException: Error getting response stream (ReadDone1): ReceiveFailure ---> Mono.Security.Protocol.Tls.TlsException: The authentication or decryption has failed.
at Mono.Security.Protocol.Tls.RecordProtocol.ProcessAlert (AlertLevel alertLevel, AlertDescription alertDesc) [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 System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
at System.Net.HttpWebRequest.GetResponse () [0x00000] in <filename unknown>:0
at System.Net.WebClient.GetWebResponse (System.Net.WebRequest request) [0x00000] in <filename unknown>:0
at System.Net.WebClient.ReadAll (System.Net.WebRequest request, System.Object userToken) [0x00000] in <filename unknown>:0
at System.Net.WebClient.UploadDataCore (System.Uri address, System.String method, System.Byte[] data, System.Object userToken) [0x00000] in <filename unknown>:0
at System.Net.WebClient.UploadData (System.Uri address, System.String method, System.Byte[] data) [0x00000] in <filename unknown>:0
这似乎是网络层应该处理的间歇性网络问题。在随后的尝试中,这个问题就消失了。
证书无效。我找到的唯一方法是捕获异常并重试请求,创建一个新的WebClient对象(因为一些header被清除)。
我基本上把代码放在一个循环中,它试图多次上传数据。
int maxAttempts = 5;
for (int attempt = 1; attempt <= maxAttempts; attempt++) {
try {
if (attempt > 1) {
// Wait a few seconds
Thread.Sleep(new TimeSpan(0, 0, 10));
Logger.Output(string.Format("Retrying request, try: {0}", attempt));
}
using (var webClient = new WebClient()) {
webClient.Headers.Add("Content-Type", string.Format("multipart/form-data; boundary={0}", boundary));
Logger.Output(webClient.Headers.ToString());
var response1 = webClient.UploadData(address, "POST", buffer);
}
Logger.Output("Table {0} added successfully", table);
break;
} catch (WebException e) {
// More logging here
if (attempt == maxAttempts) {
throw; // Re-throw it, clearly something is wrong if it fails x times.
}
}
}
The authentication or decryption has failed.
可能是mono的bug,使用curl应该可以工作。