Skip to content

Commit 8994a8b

Browse files
When checking for private key location allow user to have no appdata path
1 parent d080825 commit 8994a8b

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

src/Certify.Shared/Management/CertificateManager.cs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -776,27 +776,42 @@ private static string GetWindowsPrivateKeyLocation(string keyFileName)
776776
//if no results from common app data path, try alternative use specific app data (files may be under user specific subfolder)
777777
appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
778778
machineKeyPath = Path.Combine(new string[] { appDataPath, "Microsoft", "Crypto", "RSA" });
779-
fileList = Directory.GetDirectories(machineKeyPath);
780-
781-
if (fileList.Any())
779+
try
782780
{
783-
foreach (var filename in fileList)
781+
fileList = Directory.GetDirectories(machineKeyPath);
782+
783+
if (fileList.Any())
784784
{
785-
var dirList = Directory.GetFiles(filename, keyFileName);
786-
if (dirList.Any())
785+
foreach (var filename in fileList)
787786
{
788-
return filename;
787+
var dirList = Directory.GetFiles(filename, keyFileName);
788+
if (dirList.Any())
789+
{
790+
return filename;
791+
}
789792
}
790793
}
791794
}
795+
catch (System.IO.DirectoryNotFoundException)
796+
{
797+
// user has no appdata path
798+
}
792799

793800
appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
794801
machineKeyPath = Path.Combine(appDataPath, "Microsoft", "Crypto", "Keys");
795-
fileList = Directory.GetFiles(machineKeyPath);
796802

797-
if (fileList.Any())
803+
try
798804
{
799-
return machineKeyPath;
805+
fileList = Directory.GetFiles(machineKeyPath);
806+
807+
if (fileList.Any())
808+
{
809+
return machineKeyPath;
810+
}
811+
}
812+
catch (System.IO.DirectoryNotFoundException)
813+
{
814+
// user has no appdata path
800815
}
801816

802817
//Could not access private key file.

0 commit comments

Comments
 (0)