Tag: ssl

WCF新手 – 如何安装和使用SSL证书?

对于之前完成它的人来说,这应该是一件轻而易举的事…… 我正在尝试使用NetTcpBinding设置自托管的WCF服务。 我从Thawte那里获得了一个试用版SSL证书,并在我的IIS商店中成功安装了这个证书,我认为我已经在服务中正确设置了它 – 至少我不会例外! 现在,我正在尝试连接客户端(这仍然在我的开发机器上),并且它给了我一个错误,“Message =”X.509证书CN = ssl.mydomain.com,OU =用于测试目的只要。 无保证。,OU = IT,O =我的公司,L =我的城镇,S =无,C = IL链建设失败。 使用的证书具有无法validation的信任链。 替换证书或更改certificateValidationMode。 已处理证书链,但终止于信任提供程序不信任的根证书。“ Ooookeeeey ……现在怎么样? 客户端代码(我想在代码中执行此操作,而不是app.config): var baseAddress = “localhost”; var factory = new DuplexChannelFactory(new InstanceContext(SiteServer.Instance)); factory.Endpoint.Address = new EndpointAddress(“net.tcp://{0}:8000/”.Fmt(baseAddress)); var binding = new NetTcpBinding(SecurityMode.Message); binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName; factory.Endpoint.Binding = binding; var u = factory.Credentials.UserName; u.UserName = […]

无法使用WebClient.DownloadFile方法从启用了TLS 1.1 / 1.2协议的计算机下载文件

我正在尝试使用Webclient.DownloadFile方法通过TLS 1.1 / 1.2协议实现一个简单的控制台应用程序来下载文件。 这是应用程序的代码: var downloadUrl = “https://serverURL.com/sample.mp3”; var filename = “sample.mp3”; var myWebClient = new WebClient(); myWebClient.DownloadFile(downloadUrl, filename); 每次运行它我都会收到以下错误消息: Unhandled Exception: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. —> System.ComponentModel.Win32Exception: The client and server cannot communicate, because they do not possessa common algorithm at System.Net.SSPIWrapper.AcquireCredentialsHandle(SSPIInterface SecModule, String […]

WebRequest不发送客户端证书

我正在为REST API编写客户端并对API进行身份validation我必须使用提供给我的证书。 这段代码如下: public string GetCustomer(int custId) { X509Certificate2 Cert = new X509Certificate2(); Cert.Import(@”C:\users\foo\desktop\api\pubAndPrivateCert.pkcs12″, “”, X509KeyStorageFlags.PersistKeySet); ServicePointManager.ServerCertificateValidationCallback += ValidateServerCertificate; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(“https://api.foo.net/api/customer/v1/” + custId); req.ClientCertificates.Add(Cert); req.UserAgent = “LOL API Client”; req.Accept = “application/json”; req.Method = WebRequestMethods.Http.Get; string result = null; using (HttpWebResponse resp = (HttpWebResponse)req.GetResponse()) { StreamReader reader = new StreamReader(resp.GetResponseStream()); result = reader.ReadToEnd(); […]

使用来自C#的POST通过https发布

在用这个问题浪费了两天之后(并试图让它发挥作用),我决定退后一步并提出一个更基本的问题,因为显然有一些我不知道或者我做错了。 要求很简单, 我需要在 C#上通过https发布HTTPpost(传递几个值) 。 该网站(如果给出适当的值)将返回一些简单的html和响应代码。 (我将在稍后展示)。 这真的很简单。 “webservice”有效。 我有一个PHP示例,可以正常工作并成功连接到它。 我也有一个Dephi“演示”应用程序(带有源代码)也可以使用。 最后,我有来自具有“服务”的公司的演示应用程序(二进制),当然也有效。 但我需要通过C#来做到这一点。 这听起来如此简单,它无法正常工作。 出于测试目的,我创建了一个简单的控制台应用程序和一个简单的连接方法。 我尝试了7种不同的方式来创建HTTP请求,或多或少相同的事情,不同的实现(使用WebClient,使用HttpWebRequest等)。 每个方法都有效, 除非 URI以“https”开头。 我得到一个webexception,说远程服务器返回404.我已经安装了Fiddler(由SO用户建议),并调查了一点流量。 404是因为我传递了错误,因为正如我后面提到的,’服务’有效。 我稍后会谈到提琴手的结果。 我必须POST数据的URL是: https : //servicios.mensario.com/enviomasivo/apip/ 这是POST数据:(值是假货) usuario = SomeUser是否&釜= SomePassword&nserie = 01234567890123456789&版本= 01010000&operacion = 220 服务器可能会返回两/三行响应(抱歉西class牙语,但该公司来自西class牙)。 以下是可能响应的示例: HTTP/1.1 200 OK Content-Type: text/plain 01010000 100 BIEN 998 这是另一个 HTTP/1.1 200 OK Content-Type: text/plain 01010000 20 […]

C#SSL服务器模式必须使用具有相应私钥的证书

我将学习如何在C#中处理作为服务器端的HTTPS流量,并且在第一步中我遇到了一些麻烦。 这是一些代码( http://pastebin.com/C4ZYrS8Q ): class Program { static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { if (sslPolicyErrors == SslPolicyErrors.None) return true; Console.WriteLine(“Certificate error: {0}”, sslPolicyErrors); return false; } static void Main() { var tcpListener = new TcpListener(IPAddress.Parse(“127.0.0.1”), 8080); tcpListener.Start(); var clientAccept = tcpListener.AcceptTcpClient(); Thread.Sleep(1000); if (clientAccept.Available > 0) { var sslStream = […]

如何在Https请求中添加RestSharp添加客户端证书? (C#)

如何在Https请求中添加RestSharp添加客户端证书? 我的代码不起作用。 public static IRestResponse AsyncHttpRequestLogIn(string path, string method, object obj) { var client = new RestClient(Constants.BASE_URL + path); // https:…. var request = method.Equals(“POST”) ? new RestRequest(Method.POST) : new RestRequest(Method.GET); request.RequestFormat = RestSharp.DataFormat.Json; // The path to the certificate. string certificate = “cer/cert.cer”; client.ClientCertificates.Add(new X509Certificate(certificate)); request.AddBody( obj ); IRestResponse response = client.Execute(request); return response; […]

当SMPT服务器具有有效证书时,“根据validation过程”获取“远程证书无效”

这似乎是一个常见的错误,但是当我找到一个解决方法(见下文)时,我无法确定我首先得到它的原因。 我正在将SMTPfunction写入我们的应用程序,并且我正在尝试将SSLfunction添加到我们已有的工作SMTP中。 我正在测试使用我们公司的MS Exchange服务器,特别是在其上启用的webmail选项。 我可以通过我的代码在内部发送电子邮件,不会对我的连接进行身份validation并匿名发送,但是由于我们公司的政策,这些电子邮件不会转发到外部电子邮件地址。 除此之外,我正在为我们的客户编程,他们并不都允许开放中继和/或匿名连接。 我相信Exchange服务器正在使用显式SSL / TLS。 我已尝试telnet到端口25上的服务器地址并获得文本响应,人类可读的响应,根据我之前的一些搜索,这意味着它使用显式SSL / TLS。 我有以下测试代码 SmtpClient SMTPClient = new SmtpClient(webmailaddress); SMTPClient.Port = 25; SMTPClient.UseDefaultCredentials = true; SMTPClient.EnableSsl = true; System.Net.Mail.MailMessage Message = new ` System.Net.Mail.MailMessage(emailFrom,emailTo,subject,body); SMTPClient.Send(Message); 在我寻找解决方案期间,我遇到了“远程证书根据validation程序无效”。 使用Gmail SMTP服务器 从中我得到以下代码…… ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate); public static bool ValidateServerCertificate(object sender,X509Certificate certificate,X509Chain chain,SslPolicyErrors sslPolicyErrors) { if (sslPolicyErrors == SslPolicyErrors.None) […]

我的自定义代理服务器上的SSL(https)错误

这是我的模式代码! 当我从Firefox发送http请求它工作正常! 但当我尝试https firefox回复时: 连接到mail.yahoo.com时发生错误。 SSL收到了内容类型未知的记录。 (错误代码:ssl_error_rx_unknown_record_type) 我调试它成功连接到https的代码并重新接收字节但是当它传递给套接字时它会拒绝: Tehre是8080的听众,我的代码是: ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications); System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3; CookieContainer cookie = new CookieContainer(); if (strClientConnection.Contains(“443”)) { strClientConnection = “https://” + strClientConnection.Replace(“:443″,””); }; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strClientConnection); request.CookieContainer = cookie; request.KeepAlive = true; request.Timeout = 120000; request.AllowAutoRedirect = true; request.ReadWriteTimeout = 120000; request.Method = “POST”; { using (HttpWebResponse […]

如何在自定义validation中调用默认的ServerCertificateValidationCallback?

我想修改.Net的默认ServerCertificateValidationCallback以validation我公司的一些证书是真的,但保留其他证书的默认validation。 我似乎无法这样做,因为默认的ServerCertificateValidationCallback值为null。 ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => validCertificatesSerialNumbers.Contains(certificate.GetSerialNumberString()) || defaultlCallback.Invoke(sender, certificate, chain, sslPolicyErrors) //How do I set defaultCallback? ; 谢谢

使用CA证书文件validation远程服务器X509Certificate

我使用OpenSSL生成了CA和多个证书(由CA签名),我有一个.NET / C#客户端和服务器都使用SslStream ,每个都有自己的证书/密钥,启用了相互身份validation并禁用了吊销。 我正在使用RemoteCertificateValidationCallback为SslStreamvalidation远程服务器的证书,我希望我只能在程序中加载CA的公共证书(作为文件)并使用它来validation远程证书,而不是在Windows中实际安装CA.证书商店。 问题是除非我将CA安装到商店中,否则X509Chain不会显示任何其他内容,当我打开其中一个证书的PEM版本时,Windows CryptoAPI shell也会显示。 我的问题是,当RemoteCertificateValidationCallback , X509Certificate和X509Chain似乎没有给我任何工作时,如何使用CA的公共证书文件而不使用Windows证书存储或WCF来validation我的特定CA是否签署了证书?