Mono.Security[00 24 00 00 04 80 00 00 94 00 00 00 06 02 00 00 00 24 00 00 52 53 41 31 00 04 00 00 01 00 01 00 79 15 99 77 D2 D0 3A 8E 6B EA 7A 2E 74 E8 D1 AF CC 93 E8 85 19 74 95 2B B4 80 A1 2C 91 34 47 4D 04 06 24 47 C3 7E 0E 68 C0 80 53 6F CF 3C 3F BE 2F F9 C9 79 CE 99 84 75 E5 06 E8 CE 82 DD 5B 0F 35 0D C1 0E 93 BF 2E EE CF 87 4B 24 77 0C 50 81 DB EA 74 47 FD DA FA 27 7B 22 DE 47 D6 FF EA 44 96 74 A4 F9 FC CF 84 D1 50 69 08 93 80 28 4D BD D3 5F 46 CD FF 12 A1 BD 78 E4 EF 00 65 D0 16 DF]1.0.5000.02.0.0.0Gtk# is thread aware, but not thread safe; See the Gtk# Thread Programming for details.Mono.Security.Protocol.Tls.SslStreamBaseServer-side SSL/TLS stream.
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;
using Mono.Security.Authenticode;
using Mono.Security.Protocol.Tls;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
namespace SslHttpServer
{
class SslHttpServer
{
private static X509Certificate _certificate;
private static string certfile;
private static string keyfile;
static void Main (string [] args)
{
certfile = (args.Length > 0) ? args [0] : "ssl.cer";
keyfile = (args.Length > 0) ? args [0] : "ssl.pvk";
Socket listenSocket = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint localEndPoint = new IPEndPoint (IPAddress.Any, 1888);
Socket requestSocket;
listenSocket.Bind (localEndPoint);
listenSocket.Listen (10);
while (true) {
try {
requestSocket = listenSocket.Accept ();
using (NetworkStream ns = new NetworkStream (requestSocket, FileAccess.ReadWrite, true)) {
using (SslServerStream s = new SslServerStream (ns, Certificate, false, false)) {
s.PrivateKeyCertSelectionDelegate += new PrivateKeySelectionCallback (GetPrivateKey);
StreamReader reader = new StreamReader (s);
StreamWriter writer = new StreamWriter (s, Encoding.ASCII);
string line;
string answer =
"HTTP/1.0 200\r\n" +
"Connection: close\r\n" +
"Content-Type: text/html\r\n" +
"Content-Encoding: " + Encoding.ASCII.WebName + "\r\n" +
"\r\n" +
"<html><body><h1>Hello World!</h1></body></html>\r\n";
// Read request header
do {
line = reader.ReadLine ();
if (line != null)
Console.WriteLine (line);
}
while (line != null && line.Length > 0);
// Send response
writer.Write (answer);
writer.Flush ();
s.Flush ();
ns.Flush ();
}
}
}
catch (Exception ex) {
Console.WriteLine ("---------------------------------------------------------");
Console.WriteLine (ex.ToString ());
}
}
}
private static X509Certificate Certificate {
get {
if (_certificate == null)
_certificate = X509Certificate.CreateFromCertFile (certfile);
return _certificate;
}
}
// note: makecert creates the private key in the PVK format
private static AsymmetricAlgorithm GetPrivateKey (X509Certificate certificate, string targetHost)
{
PrivateKey key = PrivateKey.CreateFromFile (keyfile);
return key.RSA;
}
}
}
You can create a X.509 test certificate and it's private key with the following command:
makecert -n "CN=localhost" -r -sv ssl.pvk ssl.cer
Note: Thanks to Jörg Rosenkranz for the original code sample.Constructor
a
a To be addedTo be added1.0.5000.02.0.0.0Constructor
a
a
a
a To be addedTo be added1.0.5000.02.0.0.0Constructor
a
a
a
a
a To be addedTo be added1.0.5000.02.0.0.0PropertySystem.BooleanTo be addeda To be added1.0.5000.02.0.0.0PropertySystem.BooleanTo be addeda To be added1.0.5000.02.0.0.0PropertySystem.BooleanTo be addeda To be added1.0.5000.02.0.0.0PropertySystem.BooleanTo be addeda To be added1.0.5000.02.0.0.0PropertyMono.Security.Protocol.Tls.CipherAlgorithmTypeTo be addeda To be added1.0.5000.02.0.0.0PropertySystem.Int32To be addeda To be added1.0.5000.02.0.0.0PropertySystem.Security.Cryptography.X509Certificates.X509CertificateTo be addeda To be added1.0.5000.02.0.0.0PropertyMono.Security.Protocol.Tls.CertificateValidationCallbackTo be addeda To be added1.0.5000.02.0.0.0MethodSystem.Void
a To be addedTo be added1.0.5000.02.0.0.0MethodSystem.VoidTo be addedTo be added1.0.5000.02.0.0.0PropertyMono.Security.Protocol.Tls.HashAlgorithmTypeTo be addeda To be added1.0.5000.02.0.0.0PropertySystem.Int32To be addeda To be added1.0.5000.02.0.0.0PropertyMono.Security.Protocol.Tls.ExchangeAlgorithmTypeTo be addeda To be added1.0.5000.02.0.0.0PropertySystem.Int32To be addeda To be added1.0.5000.02.0.0.0PropertySystem.Int64To be addeda To be added1.0.5000.02.0.0.0PropertySystem.Int64To be addeda To be added1.0.5000.02.0.0.0PropertyMono.Security.Protocol.Tls.PrivateKeySelectionCallbackSet the method that can find the private key associated with a specific X.509 certificate and a host name.a See for an example on how to use this delegate.1.0.5000.02.0.0.0PropertyMono.Security.Protocol.Tls.SecurityProtocolTypeTo be addeda To be added1.0.5000.02.0.0.0PropertySystem.Security.Cryptography.X509Certificates.X509CertificateTo be addeda To be added1.0.5000.02.0.0.0