diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2021-02-13 17:05:59 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-13 17:05:59 -0600 |
| commit | 034eff1ad47a4ac976237d4e13c596ba1404cd2f (patch) | |
| tree | 8d9650d86237fe511a600ae58016b1ff3de3a389 /src/slskd/Common/Cryptography/X509.cs | |
| parent | aec49da74c08865353faae4d97fb4e405ae970e5 (diff) | |
| parent | 1744c9b2ded05a8a83874864957229a3235fb546 (diff) | |
| download | slskd-034eff1ad47a4ac976237d4e13c596ba1404cd2f.tar.gz | |
Merge pull request #40 from slskd/housekeeping
Tidy up
Diffstat (limited to 'src/slskd/Common/Cryptography/X509.cs')
| -rw-r--r-- | src/slskd/Common/Cryptography/X509.cs | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/src/slskd/Common/Cryptography/X509.cs b/src/slskd/Common/Cryptography/X509.cs index 19b1c4ba..95743cc0 100644 --- a/src/slskd/Common/Cryptography/X509.cs +++ b/src/slskd/Common/Cryptography/X509.cs @@ -1,11 +1,38 @@ -namespace slskd.Common.Cryptography +// <copyright file="X509.cs" company="slskd Team"> +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// </copyright> + +namespace slskd.Common.Cryptography { using System; using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; - public class X509 + /// <summary> + /// X509 utility methods. + /// </summary> + public static class X509 { + /// <summary> + /// Generates an X509 certificate for the specified <paramref name="subject"/>. + /// </summary> + /// <param name="subject">The certificate subject.</param> + /// <param name="password">The optional password for the certificate.</param> + /// <param name="x509KeyStorageFlags">The optional key storage flags for the certificate.</param> + /// <returns>The generated certificate.</returns> public static X509Certificate2 Generate(string subject, string password = null, X509KeyStorageFlags x509KeyStorageFlags = X509KeyStorageFlags.MachineKeySet) { password ??= Guid.NewGuid().ToString(); @@ -25,6 +52,13 @@ return new X509Certificate2(certificate.Export(X509ContentType.Pkcs12, password), password, x509KeyStorageFlags); } + /// <summary> + /// Validates an X509 certificate given a PFX <paramref name="fileName"/> and optional <paramref name="password"/>. + /// </summary> + /// <param name="fileName">The path to the PFX certificate file to validate.</param> + /// <param name="password">The optional password for the certificate.</param> + /// <param name="result">The error message, if the certificate is invalid.</param> + /// <returns>A value indicating whether the certificate is valid.</returns> public static bool TryValidate(string fileName, string password, out string result) { result = null; @@ -41,4 +75,4 @@ } } } -} +}
\ No newline at end of file |
