Skip to content

Commit 8e8f2b1

Browse files
committed
self signed cert gen fixes and trying to figure out the tls issue
1 parent 135bfa3 commit 8e8f2b1

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

Intersect.Server/Web/ApiService.AppSettings.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,21 +182,27 @@ out var validIssuerToken
182182
var certificatePath = certificate.Value<string>("Path");
183183
var keyPath = certificate.Value<string>("KeyPath");
184184

185-
#if DEBUG
186-
if (File.Exists(SelfSignedCertificateName) && File.Exists(SelfSignedKeyName))
187-
{
188-
return;
189-
}
190-
#endif
191-
192185
if (!string.Equals(certificatePath, SelfSignedCertificateName) ||
193186
!string.Equals(keyPath, SelfSignedKeyName))
194187
{
195188
continue;
196189
}
197190

191+
if (File.Exists(certificatePath) && File.Exists(keyPath))
192+
{
193+
var existingSelfSignedCertificate = X509Certificate2.CreateFromPemFile(certificatePath, keyPath);
194+
if (existingSelfSignedCertificate.NotAfter.ToUniversalTime() > DateTime.UtcNow)
195+
{
196+
continue;
197+
}
198+
199+
ApplicationContext.CurrentContext.Logger.LogInformation(
200+
"Self-signed certificate is expired and will be regenerated"
201+
);
202+
}
203+
198204
using var ecdsa = ECDsa.Create();
199-
CertificateRequest request = new("cn=self-signed", ecdsa, HashAlgorithmName.SHA256);
205+
CertificateRequest request = new("cn=self-signed", ecdsa, HashAlgorithmName.SHA384);
200206
var selfSignedCertificate = request.CreateSelfSigned(
201207
DateTimeOffset.Now,
202208
DateTimeOffset.Now.AddDays(30)

Intersect.Server/Web/ApiService.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System.Globalization;
22
using System.Net;
3+
using System.Net.Security;
34
using System.Reflection;
5+
using System.Security.Authentication;
46
using System.Security.Claims;
57
using System.Threading.RateLimiting;
68
using Htmx.TagHelpers;
@@ -69,13 +71,37 @@ internal partial class ApiService : ApplicationService<ServerContext, IApiServic
6971

7072
ApplicationContext.Context.Value?.Logger.LogInformation($"Launching Intersect REST API in '{builder.Environment.EnvironmentName}' mode...");
7173

74+
builder.WebHost.ConfigureKestrel(
75+
ko =>
76+
{
77+
ko.ConfigureHttpsDefaults(
78+
hcao =>
79+
{
80+
// hcao.SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls13;
81+
hcao.SslProtocols = SslProtocols.Tls12;
82+
hcao.OnAuthenticate += (context, options) =>
83+
{
84+
options.AllowRenegotiation = true;
85+
options.CipherSuitesPolicy = new CipherSuitesPolicy(
86+
[
87+
TlsCipherSuite.TLS_AES_128_GCM_SHA256,
88+
TlsCipherSuite.TLS_AES_256_GCM_SHA384,
89+
TlsCipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
90+
]
91+
);
92+
};
93+
}
94+
);
95+
}
96+
);
97+
7298
var updateServerSection = builder.Configuration.GetSection(GetOptionsName<UpdateServerOptions>());
7399
builder.Services.Configure<UpdateServerOptions>(updateServerSection);
74100

75101
// I can't get System.Text.Json to deserialize an array as non-null, and it totally ignores
76102
// the JsonConverter attribute I tried putting on it, so I am just giving up and doing this
77103
// to make sure the array is not null in the event that it is empty.
78-
configuration.StaticFilePaths ??= new List<StaticFilePathOptions>();
104+
configuration.StaticFilePaths ??= [];
79105

80106
var tokenGenerationOptionsSection =
81107
apiConfigurationSection.GetRequiredSection(nameof(TokenGenerationOptions));

0 commit comments

Comments
 (0)