Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public async Task<X509Certificate2> GetCertificateFromStoreAsync(string thumbpri
}

X509Certificate2 result = null;

string errorMessage = $"Certificate not found. A certificate for user '{Environment.UserName}' with matching thumbprint '{thumbprint}' " +
$"was not found in any one of the following expected certificate stores: ";
foreach (StoreLocation storeLocation in storeLocations)
{
try
Expand All @@ -66,6 +67,10 @@ public async Task<X509Certificate2> GetCertificateFromStoreAsync(string thumbpri
// Certificate access permissions issue
throw;
}
catch (Exception exc)
{
errorMessage = errorMessage + $"Message from location '{storeLocation.ToString()}': {exc.Message}.";
}

if (result != null)
{
Expand All @@ -75,9 +80,7 @@ public async Task<X509Certificate2> GetCertificateFromStoreAsync(string thumbpri

if (result == null)
{
throw new CryptographicException(
$"Certificate not found. A certificate for user '{Environment.UserName}' with matching thumbprint '{thumbprint}' was not found in any one of the following expected certificate stores: " +
$"{string.Join(", ", storeLocations.Select(loc => $"{loc}/{storeName}"))}");
throw new CryptographicException(errorMessage);
}

return result;
Expand All @@ -95,7 +98,8 @@ public async Task<X509Certificate2> GetCertificateFromStoreAsync(string issuer,
}

X509Certificate2 result = null;

string errorMessage = $"Certificate not found. A certificate for user '{Environment.UserName}' with matching issuer '{issuer}' and subject '{subject}' " +
$"was not found in any one of the following expected certificate stores: ";
foreach (StoreLocation storeLocation in storeLocations)
{
try
Expand All @@ -115,6 +119,10 @@ public async Task<X509Certificate2> GetCertificateFromStoreAsync(string issuer,
// Certificate access permissions issue
throw;
}
catch (Exception exc)
{
errorMessage = errorMessage + $"Message from location '{storeLocation.ToString()}': {exc.Message}.";
}

if (result != null)
{
Expand All @@ -124,9 +132,7 @@ public async Task<X509Certificate2> GetCertificateFromStoreAsync(string issuer,

if (result == null)
{
throw new CryptographicException(
$"Certificate not found. A certificate for user '{Environment.UserName}' with matching issuer '{issuer}' and subject '{subject}' was not found in any one of the following expected certificate stores: " +
$"{string.Join(", ", storeLocations.Select(loc => $"{loc}/{storeName}"))}");
throw new CryptographicException(errorMessage);
}

return result;
Expand Down