在对远程Web服务的Web服务请求期间,我收到以下错误:
无法为SSL/TLS安全通道建立信任关系.---> System.Security.Authentication.AuthenticationException:根据验证程序,远程证书无效.
反正有没有忽略这个错误,并继续?
似乎远程证书没有签名.
我连接的网站是www.czebox.cz- 所以随时访问该网站,并注意甚至浏览器抛出安全例外.
真的以为我修好了这个问题,但之前只是伪装了.
我使用HTTPS在IIS 7中托管了WCF服务.当我在Internet Explorer中浏览到此站点时,它就像一个魅力,这是因为我已将证书添加到本地根证书颁发机构商店.
我正在一台机器上开发,所以客户端和服务器是同一台机器.该证书直接从IIS 7管理管理单元自签名.
我现在不断得到这个错误......
无法为具有权限的SSL/TLS安全通道建立信任关系.
...从客户端控制台调用时.
我手动给自己的权限和网络服务证书,使用findprivatekey和使用cacls.exe.
我试图使用SOAPUI连接到服务,这是有效的,所以它必须是我的客户端应用程序中的一个问题,这是基于过去使用http的代码.
在哪里可以看到我似乎已经耗尽了为什么我无法连接的所有可能性?
我试图用这个代码从手持设备(Windows CE/Compact框架)调用REST方法:
public static HttpWebRequest SendHTTPRequestNoCredentials(string uri, HttpMethods method, string data, string contentType)
{
ExceptionLoggingService.Instance.WriteLog("Reached
fileXferREST.SendHTTPRequestNoCredentials");
WebRequest request = null;
try
{
request = WebRequest.Create(uri);
request.Method = Enum.ToObject(typeof(HttpMethods), method).ToString();
request.ContentType = contentType;
((HttpWebRequest)request).Accept = contentType;
((HttpWebRequest)request).KeepAlive = false;
((HttpWebRequest)request).ProtocolVersion = HttpVersion.Version10;
if (method != HttpMethods.GET && method != HttpMethods.DELETE)
{
byte[] arrData = Encoding.UTF8.GetBytes(data);
request.ContentLength = arrData.Length;
using (Stream oS = request.GetRequestStream())
{
oS.Write(arrData, 0, arrData.Length);
}
}
else
{
request.ContentLength = 0;
}
}
catch (Exception ex)
{
String …Run Code Online (Sandbox Code Playgroud) ssl compact-framework remote-host socketexception get-request
如何验证.NET中HTTPS/SSL证书的有效性?
理想情况下,我想建立一个到网站的HTTPS连接,然后找出是否以有效的方式完成(证书未过期,主机名匹配,证书链信任等),但内置HTTP客户端似乎忽略证书错误(而且我不确定是否需要物理下载网页来验证证书?).
我试过使用下面的代码(改编自评论中的答案),但ValidationCallback永远不会被调用:
static void Main(string[] args)
{
String url = "https://www.example.com";
HttpWebRequest request = WebRequest.CreateHttp(url);
request.GetResponse();
request.ServerCertificateValidationCallback += ServerCertificateValidationCallback;
Console.WriteLine("End");
Console.ReadKey();
}
private static bool ServerCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
if (sslPolicyErrors == SslPolicyErrors.None)
{
Console.WriteLine("Certificate OK");
return true;
}
else
{
Console.WriteLine("Certificate ERROR");
return false;
}
}
Run Code Online (Sandbox Code Playgroud) 我正在开发一个更大的 C# 套接字应用程序,它将通过 SSL 使用服务器和客户端身份验证。为了在我的本地机器上测试应用程序的其他部分,我需要禁用认证验证。我已经尝试按照其他几个地方的建议覆盖 ServerCertificateValidationNCallback,但我继续遇到异常。我正在使用使用 OpenSSL 创建的自签名证书进行测试。
我尝试过的带有解决方案的文章:
我得到的例外:
StackTrace: at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest …Run Code Online (Sandbox Code Playgroud) 我正在尝试向服务器发出请求,但是我的服务器是使用自定义 ssl 设置的,openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes但是如何设置为类似于 python 的错误验证 sslrequests.get(url,verify=false)
客户
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using (Stream stream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(stream))
{
html = reader.ReadToEnd();
Console.WriteLine(html);
}
}
}
Run Code Online (Sandbox Code Playgroud)