Tag: ssl

相互SSL身份validation – sslstream中的本地证书在客户端上返回“null”而不是证书

我正在创建一个Windows服务,它将调用API。 对于此过程,我正在尝试建立Mutual(双向)SSL身份validation。 因为我是新手。 我试图实现一个简单的客户端和服务器项目,它将相互validation。 我创建了自签名证书,并在可信证书中添加。 我的客户 using System; using System.Configuration; using System.Net.Security; using System.Net.Sockets; using System.Security.Authentication; using System.Security.Cryptography.X509Certificates; using System.Text; namespace MutualSslDemo.Client { class Program { static void Main(string[] args) { // hostName var hostName = ConfigurationManager.AppSettings[“hostName”]; if (String.IsNullOrEmpty(hostName)) throw new ArgumentNullException(“hostName”, “Please specify a valid hostname to connect to.”); // port var port = […]

如何允许服务器接受SSL和纯文本(不安全)连接?

我正在尝试创建一个可以接受安全SSL和不安全的纯文本连接的服务器(为了向后兼容)。 我的代码几乎正常工作,除了从不安全客户端收到的第一个传输数据丢失了服务器上的前5个字节(字符)。 更具体地说,如果我在不安全的连接上传输30个字节,当服务器到达OnClientDataReceived()函数时,行“ int iRx = nwStream.EndRead(asyn); ”,则iRx = 25 。 从客户端发送的任何后续消息都包含所有发送的字节/字符。 我怀疑连接的初始假设是SSLStream可能正在剥离前5个字节,然后当它失败时,这5个字节已经从缓冲区中提取出来并且不再可用。 有没有人知道我可以采取另一种方法来编写代码,以便服务器能够自动切换? 我试图避免做以下事情: 要求客户端使用纯文本NetworkStream连接,然后请求升级到SSL流 在两个不同的端口上设置两个TcpListeners (一个用于安全,一个用于不安全) 这是我的代码: /// Each client that connects gets an instance of the ConnectedClient class. Class Pseudo_ConnectedClient { //Properties byte[] Buffer; //Holds temporary buffer of read bytes from BeginRead() TcpClient TCPClient; //Reference to the connected client Socket ClientSocket; //The […]

有没有办法使用FtpWebRequest使用C#中的客户端证书对FTP进行身份validation?

我正在尝试将文件上传到FTP服务器,我需要使用客户端证书进行身份validation,而不是用户名和密码。 var fullFtpPath = String.Concat(ftpItem.FtpAddress, “/”, record, “.txt”); FtpWebRequest request = (FtpWebRequest) WebRequest.Create(fullFtpPath); request.Credentials = new NetworkCredential(ftpItem.Username, ftpItem.Password); request.Method = WebRequestMethods.Ftp.UploadFile; request.UseBinary = true; request.UsePassive = ftpItem.UsePassive; request.EnableSsl = ftpItem.UseSSL; request.ContentLength = bytes.Length; using(Stream s = request.GetRequestStream()) { s.Write(bytes, 0, bytes.Length); } FtpWebResponse response = (FtpWebResponse) request.GetResponse(); Debug.WriteLine(“Upload File Complete, status {0}”, response.StatusDescription); db.LogExport(siteId, fullFtpPath, […]

使用SSL从C#应用程序调用WebService

在我的C#桌面应用程序中,我正在调用在php中开发的Web服务。 我可以拥有CA文件。 我不知道如何通过SSL调用Web服务并validation证书。 我需要通过服务器以及从服务器进行身份validation的响应内容? 老实说,我不知道。 编辑:参考: http ://weblogs.asp.net/jan/archive/2003/12/04/41154.aspx //在调用Web服务之前System.Net.ServicePointManager.CertificatePolicy = new MyPolicy(); public class MyPolicy : ICertificatePolicy { X509Certificate clientCert = null; public MyPolicy() { clientCert = X509Certificate.CreateFromSignedFile(HTTPUtility.CERT_FILE); } public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem) { Console.WriteLine(“********* Into CheckValidationResult : ” + certificate.ToString()); Console.WriteLine(“####### Client Certificate : ” + clientCert.ToString() + […]

C#SSL安全套接字

我有一个很好的,有效的沟通应用程序,用C#编写。 现在我需要实现与服务器的安全连接。 我已经尝试将Socket和TcpClient对象更改为SslStream,但是我遇到了一些错误。 首先,我使用makecert生成了一个.cer证书。 OpenSSL证书对我没用,因为它们不包含私钥。 接下来,我在服务器上创建了一个证书对象,并将其绑定到SslStream: X509Certificate serverCertificate = X509Certificate.CreateFromCertFile(“ca.cer”); TcpClient clientSocket = this.tcpListener.AcceptTcpClient(); SslStream ssls = new SslStream(clientSocket.GetStream(), false); ssls.AuthenticateAsServer(serverCertificate, false, SslProtocols.Tls, true); 在客户端我这样做: TcpClient client = new TcpClient(settings.IP, settings.Port); sslStream = new SslStream(client.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null); sslStream.AuthenticateAsClient(settings.IP); public static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { if (sslPolicyErrors == […]

导出到Excel不适用于SSL下的IE(https)

我一直在尝试在安全的网站(https)上修复一些东西,这是一个导出到Excel按钮,生成一个CSV文件。 它适用于Firefox,Chrome等…但不适用于Internet Explorer。 我更改了标头消除了无缓存,并编辑了IIS http标头配置设置的截止日期为1天。 我不知道会发生什么以及如何解决它。 你们有没有想过如何解决这个问题? 我读过这么多post,他们都说同样的话……缓存。 谢谢, 更新1: 关于我收到的错误,我收到IE警报说“Internet Explorer无法从web.address.com下载filename.aspx.Internet Explorer无法打开此Internet站点。请求的站点不可用或无法找到。请尝试稍后再试。 正如我所说的,它全部都是SSL(https),但导出到excel按钮,以https打破。 更新2: 我正在使用这些标题: Response.ClearContent(); Response.Clear(); Response.Buffer = true; Response.AddHeader(“content-disposition”, “attachment; filename=” + name.Trim() + “.csv”); Response.AddHeader(“Cache-Control”, “no-cache”); Response.AddHeader(“Pragma”, “public”); Response.AddHeader(“Content-Transfer-Encoding”, “binary”); Response.AddHeader(“Content-Length”, “2026”); Response.Charset = “”; //Response.ContentType = “application/vnd.ms-excel”; Response.ContentType = “text/csv”;

在C#SSL WebSocket客户端是.net 4.0吗?

我想知道目前是否有任何关于这个主题的内容:我已经找到了各种例子EG: c#的4.5s system.net.websockets.websocket for ssl(wss://)客户端我想知道是否有可靠的ssl版本在那里,因为这个类似的问题得到了回答。 但我正在使用Visual c#2010开发,这是一个winforms C# 客户端应用程序,必须接收服务器推送,但它是Windows 7,所以我不能使用net 4.5。 (注:重视客户 ) 如果任何人有任何实际的SSL代码(希望一个不一定强制执行证书身份validation提示)我会很感激 – 我更喜欢代码示例 – 但我会采用命名空间解决方案。 提前致谢:-)

SSL / TLS中的相互身份validation

我是SSL身份validation的新手,我需要使用SSL在信任边界上validation两个架构组件(我可以控制这两个组件)。 我想我需要双向SSL身份validation,服务器和客户端都有证书。 证书可以自签名吗? (即,由供应商签名,这不会首先使用SSL取消?或者我是否需要第三方validation服务以确保证书的身份?) 握手如何在服务器和客户端的公钥和私钥方面工作? 我将不得不在IIS中配置服务器以使用cetificate,并使用请求发送客户端证书(最有可能通过使用WCF配置?),但是还有其他任务我必须做才能使其工作吗?

无法连接到仅使用临时密码套件的SSL服务器(无法联系本地安全机构)

我正在尝试连接到以openssl开头的测试服务器(这个有限的密码组合是有意的): openssl s_server -accept 443 -www -tls1_2 -cipher ECDHE:DHE:EDH -cert selfsignedcert.pem -key sskey.pem 我使用的代码类似于msdn的 public static bool ValidateServerCertificate( object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; } … var client = new TcpClient(target, port); SslStream sslStream = new SslStream(client.GetStream(), false,ValidateServerCertificate,null); sslStream.AuthenticateAsClient(target, null, SslProtocols.Tls12, false); 但是我在最后一行遇到exception: A call to SSPI failed, see inner […]

为什么ServicePointManager.SecurityProtocol在不同的机器上的默认值是不同的?

目前我有一个问题,无法找到严格的答案。 我有针对4.6.1框架的ASP.NET MVC 5应用程序,其目标是使用受TLS 1.1 / TLS 1.2协议保护的第三方API。 我试图在2个环境中运行我的应用程序: 我的本地机器Windows 10与.NET 4.6.2 Framework,IIS Express; 服务器机器Windows Server 2012 with .NET 4.6.1,IIS 8.0; 问题在于,当我在本地启动它时, ServicePointManager.SecurityProtocol默认值设置为Ssl3, Tls ,所以我无法定位API并且必须在应用程序启动时对其进行编码才能使用TLS 1.1 / TLS 1.2: ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 。 当应用程序在服务器上运行时,默认值ServicePointManager.SecurityProtocol设置为Tls, Tls11, Tls12 ,因此它运行良好。 根据文档,在.NET Framework 4.6或更高版本上运行的应用程序默认情况下必须使用TLS 1.1 / TLS 1.2,它是如何在远程计算机上运行的。 为什么ServicePointManager.SecurityProtocol的默认值不同? 是因为.NET Framework配置? 或者可能是注册表设置 […]