You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.8 KiB
70 lines
1.8 KiB
using System;
|
|
using System.Net;
|
|
using System.Security.Cryptography;
|
|
using System.Security.Cryptography.X509Certificates;
|
|
using System.IO;
|
|
|
|
namespace pyxis.helloworld
|
|
{
|
|
class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
Program p = new Program();
|
|
p.run();
|
|
}
|
|
|
|
public void run()
|
|
{
|
|
X509Certificate2 cert_default = this.readKeyAndCert("gemini.key", "gemini.crt");
|
|
X509Certificate2 cert_alt = this.readKeyAndCert("alt.key", "alt.crt");
|
|
|
|
gemini.Server.Server server = new gemini.Server.Server(
|
|
new IPEndPoint(IPAddress.Loopback, 1965),
|
|
cert_default
|
|
);
|
|
server.AddCertificate("test.l.nucleardog.org", cert_alt);
|
|
|
|
server.OnProcessRequest += this.processRequest;
|
|
|
|
server.Start();
|
|
|
|
Console.WriteLine("[Press Any Key to Continue]");
|
|
Console.ReadKey();
|
|
|
|
server.Stop();
|
|
}
|
|
|
|
public gemini.Protocol.Response processRequest(gemini.Server.Server server, gemini.Protocol.Request request)
|
|
{
|
|
gemini.Protocol.Response resp = new gemini.Protocol.Response();
|
|
resp.setStatus(20);
|
|
resp.setMeta("text/gemini; charset=utf-8");
|
|
resp.setBody(System.Text.Encoding.UTF8.GetBytes("Hello, world!"));
|
|
return resp;
|
|
}
|
|
|
|
private X509Certificate2 readKeyAndCert(string keypath, string certpath)
|
|
{
|
|
// Read cert
|
|
X509Certificate2 cert = new X509Certificate2(certpath);
|
|
|
|
// Read key
|
|
string[] lines = File.ReadAllLines(keypath);
|
|
string privateKeyString = "";
|
|
foreach (string line in lines)
|
|
{
|
|
privateKeyString += line;
|
|
}
|
|
byte[] privateKeyData = Convert.FromBase64String(privateKeyString);
|
|
|
|
RSA rsa = RSA.Create();
|
|
rsa.ImportPkcs8PrivateKey(privateKeyData, out _);
|
|
|
|
cert = cert.CopyWithPrivateKey(rsa);
|
|
cert = new X509Certificate2(cert.Export(X509ContentType.Pfx));
|
|
|
|
return cert;
|
|
}
|
|
}
|
|
}
|
|
|