update http certificate validator to match server startup behavior

This commit is contained in:
Tamer Wahba 2026-05-02 17:04:34 -04:00
parent 15f83cf005
commit 29e9d2992e
No known key found for this signature in database
GPG key ID: B934B3FE68CD2A72

View file

@ -3,6 +3,7 @@
using FluentValidation;
using FluentValidation.Validators;
using NLog;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Instrumentation;
namespace Radarr.Api.V3.Config
@ -33,11 +34,11 @@ protected override bool IsValid(PropertyValidatorContext context)
return true;
}
var certificateCollection = new X509Certificate2Collection();
try
{
new X509Certificate2(resource.SslCertPath, resource.SslCertPassword, X509KeyStorageFlags.DefaultKeySet);
return true;
certificateCollection.Import(resource.SslCertPath, resource.SslCertPassword, X509KeyStorageFlags.DefaultKeySet);
}
catch (CryptographicException ex)
{
@ -47,6 +48,19 @@ protected override bool IsValid(PropertyValidatorContext context)
return false;
}
if (certificateCollection.None(c => c.HasPrivateKey))
{
var message = $"The SSL certificate file {resource.SslCertPath} does not contain a certificate with an associated private key";
Logger.Debug($"{message}");
context.MessageFormatter.AppendArgument("message", message);
return false;
}
return true;
}
}
}