mirror of
https://github.com/BililiveRecorder/BililiveRecorder.git
synced 2024-11-16 11:42:22 +08:00
CLI: Generate self signed certificated with a CA
This commit is contained in:
parent
c054e8a3f5
commit
b253826dbc
|
@ -319,8 +319,20 @@ namespace BililiveRecorder.Cli
|
|||
{
|
||||
logger.Warning("使用录播姬生成的自签名证书");
|
||||
|
||||
var firstDayofCurrentYear = new DateTimeOffset(DateTime.Now.Year, 1, 1, 0, 0, 0, TimeSpan.Zero);
|
||||
X509Certificate2? CA = null;
|
||||
try
|
||||
{
|
||||
{
|
||||
using var key = RSA.Create();
|
||||
var req = new CertificateRequest("CN=B站录播姬, OU=自签名证书,每次启动都会重新生成", key, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
|
||||
var req = new CertificateRequest("CN=自签名证书,每次启动都会重新生成", key, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
|
||||
req.CertificateExtensions.Add(new X509BasicConstraintsExtension(true, false, 0, false));
|
||||
CA = new X509Certificate2(req.CreateSelfSigned(firstDayofCurrentYear, firstDayofCurrentYear.AddYears(10)).Export(X509ContentType.Pfx));
|
||||
}
|
||||
|
||||
{
|
||||
using var key = RSA.Create();
|
||||
var req = new CertificateRequest("CN=B站录播姬", key, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
|
||||
|
||||
var subjectAltName = new SubjectAlternativeNameBuilder();
|
||||
subjectAltName.AddDnsName("BililiveRecorder");
|
||||
|
@ -331,10 +343,15 @@ namespace BililiveRecorder.Cli
|
|||
subjectAltName.AddDnsName("*.sslip.io");
|
||||
req.CertificateExtensions.Add(subjectAltName.Build());
|
||||
|
||||
var firstDayofCurrentYear = new DateTimeOffset(DateTime.Now.Year, 1, 1, 0, 0, 0, TimeSpan.Zero);
|
||||
using var cert = req.CreateSelfSigned(firstDayofCurrentYear, firstDayofCurrentYear.AddYears(10));
|
||||
var bytes = cert.Export(X509ContentType.Pfx);
|
||||
return new X509Certificate2(bytes);
|
||||
using var cert = req.Create(CA, firstDayofCurrentYear, firstDayofCurrentYear.AddYears(10), "BililiveRecorder".Select(x => (byte)x).ToArray());
|
||||
using var withPrivateKey = cert.CopyWithPrivateKey(key);
|
||||
return new X509Certificate2(withPrivateKey.Export(X509ContentType.Pfx));
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
CA?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private static (string schema, string host, int port) ParseBindArgument(string bind, ILogger logger)
|
||||
|
|
Loading…
Reference in New Issue
Block a user