Skip to content

Commit ee2161b

Browse files
Populate only certs from store in PopulateCertsFromStore. (#43358)
1 parent 898d551 commit ee2161b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/Shared/CertificateGeneration/MacOSCertificateManager.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ protected override IList<X509Certificate2> GetCertificatesToRemove(StoreName sto
375375

376376
protected override void PopulateCertificatesFromStore(X509Store store, List<X509Certificate2> certificates)
377377
{
378-
if (store.Name! == StoreName.My.ToString() && store.Location == store.Location && Directory.Exists(MacOSUserHttpsCertificateLocation))
378+
if (store.Name! == StoreName.My.ToString() && store.Location == StoreLocation.CurrentUser && Directory.Exists(MacOSUserHttpsCertificateLocation))
379379
{
380380
var certsFromDisk = GetCertsFromDisk();
381381

@@ -388,7 +388,10 @@ protected override void PopulateCertificatesFromStore(X509Store store, List<X509
388388
// Certs created (or "upgraded") by .NET 7+.
389389
// .NET 7+ installs the certificate on disk as well as on the user keychain (for backwards
390390
// compatibility with pre-.NET 7).
391-
var onDiskAndKeychain = certsFromDisk.Intersect(certsFromStore, ThumbprintComparer.Instance);
391+
// Note that the actual certs we populate need to be the ones from the store location, and
392+
// not the version from disk, since we may do other operations with these certs later (such
393+
// as exporting) which would fail with crypto errors otherwise.
394+
var onDiskAndKeychain = certsFromStore.Intersect(certsFromDisk, ThumbprintComparer.Instance);
392395

393396
// The only times we can find a certificate on the keychain and a certificate on keychain+disk
394397
// are when the certificate on disk and keychain has expired and a pre-.NET 7 SDK has been

0 commit comments

Comments
 (0)