You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Gateway/Proxy/SiteCertCheck.cs

73 lines
2.2 KiB
C#

1 year ago
using System;
using UMC.Data;
using UMC.Web;
using UMC.Net;
using System.Security.Cryptography.X509Certificates;
namespace UMC.Proxy;
1 year ago
class SiteCertCheck : UMC.Host.IDoWorker
{
string Domain, Secret;
public SiteCertCheck(string domain, string secret)
1 year ago
{
1 year ago
this.Domain = domain;
this.Secret = secret;
}
int time = 0;
void UMC.Host.IDoWorker.DoWork()
{
time++;
Utility.Sign(new Uri(Net.APIProxy.Uri, "Certificater").WebRequest(), this.Secret).Post(new WebMeta().Put("type", "cert", "domain", this.Domain), xhr =>
1 year ago
{
1 year ago
if (xhr.StatusCode == System.Net.HttpStatusCode.OK)
1 year ago
{
1 year ago
xhr.ReadAsString(str =>
1 year ago
{
1 year ago
var cert = JSON.Deserialize<WebMeta>(str);
if (cert.ContainsKey("privateKey"))
1 year ago
{
1 year ago
var domain = cert["domain"];
var privateKey = cert["privateKey"];
var publicKey = cert["publicKey"];
1 year ago
1 year ago
var x509 = X509Certificate2.CreateFromPem(publicKey, privateKey);
1 year ago
1 year ago
UMC.Proxy.Certificater.Certificates[domain] = new UMC.Proxy.Certificater
1 year ago
{
1 year ago
Name = domain,
Certificate = x509
};
1 year ago
1 year ago
HotCache.Put(new Entities.SiteCert
{
Domain = domain,
ExpirationTime = Utility.TimeSpan(x509.NotAfter),
CheckTime = Utility.TimeSpan(),
PrivateKey = privateKey,
PublicKey = publicKey,
IsApiumc = false
});
}
else if (time < 10)
1 year ago
{
1 year ago
HttpMimeServier.Register(30, this);
1 year ago
1 year ago
}
1 year ago
});
}
else
{
xhr.ReadAsData((b, ch, l) => { }); ;
if (time < 10)
{
1 year ago
HttpMimeServier.Register(30, this);
1 year ago
}
1 year ago
}
});
1 year ago
}
1 year ago
}