I'm trying to get a list of non-expired certificates from the cert stores of remote machines. For some machines this works fine, but for others I'm getting the following error:
Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: The network path was not found.
at Internal.Cryptography.Pal.StorePal.FromSystemStore(String storeName, StoreLocation storeLocation, OpenFlags openFlags)
at System.Security.Cryptography.X509Certificates.X509Store.Open(OpenFlags flags)
at GetCertificates(String server)
Here is the piece of code where this is coming from:
var store = new X509Store($@"\\{server}\My", StoreLocation.LocalMachine);
var certList = new List<X509Certificate2>();
try
{
store.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadOnly);
certList = store.Certificates.Cast<X509Certificate2>()
.Where(x => x.NotBefore < DateTime.Now &&
DateTime.Now < x.NotAfter).ToList();
}
catch (Exception e)
{
throw;
}
finally
{
store.Close();
}
Any ideas why this maybe happening for some machines and/or possible workarounds/solutions?
Thank you
Found a solution. I ran my application as an administrator and now it seems to be able to resolve the network paths. I'm guessing we have some configuration/permission setup for these servers that only allow 'admins' to access the certs remotely.