Skip to content

Commit

Permalink
Do not create the default folders for DirectoryStore on Open (#2773)
Browse files Browse the repository at this point in the history
For convenience, the DirectoryStore class creates the default folders when the DirectoryStore is opened. (since #2720)
However this may lead into issues mapping folders to the store when started in docker.

Fix: remove the code which creates default folders and ensure a null directory does not throw a NullReferenceException.
  • Loading branch information
mregen authored Sep 26, 2024
1 parent 8131a02 commit 3d24c0e
Showing 1 changed file with 3 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void Open(string location, bool noPrivateKeys = false)
NoPrivateKeys = noPrivateKeys;
StorePath = location;
m_directory = directory;
if (m_noSubDirs)
if (m_noSubDirs || m_directory == null)
{
m_certificateSubdir = m_directory;
m_crlSubdir = m_directory;
Expand All @@ -125,39 +125,6 @@ public void Open(string location, bool noPrivateKeys = false)
// force load
ClearCertificates();
m_lastDirectoryCheck = DateTime.MinValue;

// create folders if they do not exist
try
{
if (!m_directory.Exists)
{
m_directory.Create();
}

if (!m_certificateSubdir.Exists)
{
m_certificateSubdir.Create();
}

if (noPrivateKeys)
{
if (!m_crlSubdir.Exists)
{
m_crlSubdir.Create();
}
}
else
{
if (!m_privateKeySubdir.Exists)
{
m_privateKeySubdir.Create();
}
}
}
catch (IOException ex)
{
Utils.LogError("Failed to create certificate store: {0}", ex.Message);
}
}
}
}
Expand Down Expand Up @@ -825,17 +792,16 @@ private IDictionary<string, Entry> Load(string thumbprint)
DateTime now = DateTime.UtcNow;

// refresh the directories.
m_certificateSubdir.Refresh();
m_certificateSubdir?.Refresh();

if (!NoPrivateKeys)
{
m_privateKeySubdir?.Refresh();
}

// check if store exists.
if (!m_certificateSubdir.Exists)
if (m_certificateSubdir?.Exists != true)
{
m_certificateSubdir.Create();
ClearCertificates();
return m_certificates;
}
Expand Down

0 comments on commit 3d24c0e

Please sign in to comment.