This article introduces the open-source. net Communication Framework NetworkComms framework-six x509 Certificate communication, networkcommsx509
Http://www.cnblogs.com/csdev
Networkcomms is a C # TCP/UDP communication framework written by the British. It was previously charged by the British. Currently, the author has open-source License: Apache License v2.
Open Source Address: https://github.com/MarcFletcher/NetworkComms.Net
First of all, I am not particularly familiar with the certificate, but I just reorganized the Demo of NetworkComms itself. If not, criticize and correct it.
First
Server:
(1) generate a certificate:
public void CreateCert() { if (!File.Exists("testCertificate.pfx")) { CertificateDetails details = new CertificateDetails("CN=wwww", DateTime.Now, DateTime.Now.AddYears(1)); SSLTools.CreateSelfSignedCertificatePFX(details, "testCertificate.pfx"); } X509Certificate cert = new X509Certificate2("testCertificate.pfx"); sslOptions = new SSLOptions(cert, true); }
In the above Code, the certificate is assigned to sslOptions as a parameter.
SslOptions will be assigned to the listener. The Code is as follows:
ConnectionListenerBase listener = new TCPConnectionListener(customOptions, ApplicationLayerProtocolStatus.Enabled,sslOptions); Connection.StartListening(listener, thePoint, true);
The running server generates
TestCertificate. pfx file. We need to copy this file to the client.
Client code:
X509Certificate cert = new X509Certificate2 ("testCertificate. pfx "); SSLOptions sslOptions = new SSLOptions (cert, true); connInfo = new ConnectionInfo (txtIP. text, int. parse (txtPort. text); newTcpConnection = TCPConnection. getConnection (connInfo, customOptions, sslOptions); button1.Enabled = false; button1.Text = "connection successful ";
In this way, clients without certificates cannot establish connections with the server.
Source code: http://pan.baidu.com/s/1dEJEdNz