aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Common/Validation/X509CertificateAttribute.cs26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/slskd/Common/Validation/X509CertificateAttribute.cs b/src/slskd/Common/Validation/X509CertificateAttribute.cs
new file mode 100644
index 00000000..db122930
--- /dev/null
+++ b/src/slskd/Common/Validation/X509CertificateAttribute.cs
@@ -0,0 +1,26 @@
+namespace slskd.Validation
+{
+ using System.ComponentModel.DataAnnotations;
+ using slskd.Common.Cryptography;
+ using static slskd.Options.WebOptions.HttpsOptions;
+
+ public class X509CertificateAttribute : ValidationAttribute
+ {
+ protected override ValidationResult IsValid(object value, ValidationContext validationContext)
+ {
+ if (value != null)
+ {
+ var cert = (CertificateOptions)value;
+
+ System.Console.WriteLine($"pass: {cert.Password} {string.IsNullOrEmpty(cert.Password)}");
+
+ if (!string.IsNullOrEmpty(cert.Pfx) && !X509.TryValidate(cert.Pfx, cert.Password, out var certResult))
+ {
+ return new ValidationResult($"Invalid HTTPs certificate: {certResult}");
+ }
+ }
+
+ return ValidationResult.Success;
+ }
+ }
+} \ No newline at end of file