Skip to content

Commit

Permalink
change 1 (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
leefine02 authored Jul 28, 2021
1 parent 0d7daac commit acdecad
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions PEMStoreSSH/PEMStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Text;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Threading;

using PEMStoreSSH.RemoteHandlers;
using Keyfactor.Extensions.Pam.Utilities;
Expand All @@ -21,6 +22,8 @@ internal class PEMStore
private const string NO_EXTENSION = "noext";
private const string FULL_SCAN = "fullscan";

static Mutex mutex = new Mutex(false, "ModifyStore");

public enum FormatTypeEnum
{
PEM,
Expand Down Expand Up @@ -116,38 +119,54 @@ internal void RemoveCertificate(string alias)
{
try
{
mutex.WaitOne();
CertificateHandler.RemoveCertificate(ServerType, StorePath, PrivateKeyPath, SSH, alias, String.IsNullOrEmpty(PrivateKeyPath));
}
catch (Exception ex)
{
throw new PEMException($"Error attempting to remove certificate from store {StorePath}.", ex);
}
finally
{
mutex.ReleaseMutex();
}

if (!string.IsNullOrEmpty(PrivateKeyPath))
{
try
{
mutex.WaitOne();
SSH.RemoveCertificateFile(PrivateKeyPath);
SSH.CreateEmptyStoreFile(PrivateKeyPath);
}
catch (Exception ex)
{
throw new PEMException($"Error attempting to remove private key {PrivateKeyPath}.", ex);
}
finally
{
mutex.ReleaseMutex();
}

}
}

internal void AddCertificateToStore(string cert, string alias, string pfxPassword, string storePassword, bool overwrite, bool containsPrivateKey)
{
try
{
mutex.WaitOne();
List<SSHFileInfo> files = CertificateHandler.CreateCertificatePacket(cert, alias, pfxPassword, storePassword, !String.IsNullOrEmpty(PrivateKeyPath));
CertificateHandler.AddCertificateToStore(files, StorePath, PrivateKeyPath, SSH, ServerType, overwrite, containsPrivateKey, IsSingleCertificateStore);
}
catch (Exception ex)
{
throw new PEMException($"Error attempting to add certificate to store {StorePath}.", ex);
}
finally
{
mutex.ReleaseMutex();
}
}

internal bool IsValidStore(string path)
Expand Down

0 comments on commit acdecad

Please sign in to comment.