mirror of
https://github.com/MikuLeaks/MikuSB.git
synced 2026-06-04 08:04:01 +00:00
Change certificate generation
This commit is contained in:
@@ -48,19 +48,7 @@ public static class CertHelper
|
|||||||
|
|
||||||
private static X509Certificate2 CreateSelfSigned(string host)
|
private static X509Certificate2 CreateSelfSigned(string host)
|
||||||
{
|
{
|
||||||
// CNG key must have AllowPlainTextExport so the private key is included in PFX export.
|
using var rsa = RSA.Create(2048);
|
||||||
// Without this, Export(Pfx) produces a cert-only PFX, and EphemeralKeySet loads a
|
|
||||||
// keyless cert that Kestrel cannot use for TLS.
|
|
||||||
var cngParams = new CngKeyCreationParameters
|
|
||||||
{
|
|
||||||
ExportPolicy = CngExportPolicies.AllowPlaintextExport,
|
|
||||||
KeyUsage = CngKeyUsages.AllUsages
|
|
||||||
};
|
|
||||||
cngParams.Parameters.Add(new CngProperty("Length",
|
|
||||||
BitConverter.GetBytes(2048), CngPropertyOptions.None));
|
|
||||||
|
|
||||||
using var cngKey = CngKey.Create(CngAlgorithm.Rsa, null, cngParams);
|
|
||||||
using var rsa = new RSACng(cngKey);
|
|
||||||
|
|
||||||
var req = new CertificateRequest(
|
var req = new CertificateRequest(
|
||||||
new X500DistinguishedName($"CN={host}"),
|
new X500DistinguishedName($"CN={host}"),
|
||||||
@@ -84,7 +72,6 @@ public static class CertHelper
|
|||||||
DateTimeOffset.UtcNow.AddHours(-1),
|
DateTimeOffset.UtcNow.AddHours(-1),
|
||||||
DateTimeOffset.UtcNow.AddYears(10));
|
DateTimeOffset.UtcNow.AddYears(10));
|
||||||
|
|
||||||
// Private key is now exportable — PFX includes key material
|
|
||||||
var pfx = cert.Export(X509ContentType.Pfx, Password);
|
var pfx = cert.Export(X509ContentType.Pfx, Password);
|
||||||
return LoadPkcs12(pfx);
|
return LoadPkcs12(pfx);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user