* Ignore removing empty or disposed certificates from X509Store.
* Fix X509Chain.Build with empty certificate.
Commit migrated from https://github.com/dotnet/corefx/commit/
906725f53f9f84a911bcddc60e72ba7abb8adaf8
{
lock (_syncRoot)
{
- if (certificate == null)
+ if (certificate == null || certificate.Pal == null)
throw new ArgumentException(SR.Cryptography_InvalidContextHandle, nameof(certificate));
Reset();
if (_storePal == null)
throw new CryptographicException(SR.Cryptography_X509_StoreNotOpen);
- if (certificate.Handle == IntPtr.Zero)
+ if (certificate.Pal == null)
throw new CryptographicException(SR.Cryptography_InvalidHandle, "pCertContext");
_storePal.Add(certificate.Pal);
if (_storePal == null)
throw new CryptographicException(SR.Cryptography_X509_StoreNotOpen);
+ if (certificate.Pal == null)
+ return;
+
_storePal.Remove(certificate.Pal);
}
}
[Fact]
+ public static void BuildChainInvalidValues()
+ {
+ using (var chain = X509Chain.Create())
+ {
+ AssertExtensions.Throws<ArgumentException>("certificate", () => chain.Build(null));
+ AssertExtensions.Throws<ArgumentException>("certificate", () => chain.Build(new X509Certificate2()));
+ }
+ }
+
+ [Fact]
public static void InvalidSelfSignedSignature()
{
X509ChainStatusFlags expectedFlags;
}
}
+ [Fact]
+ public static void RemoveDisposedIsIgnored()
+ {
+ using (X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser))
+ using (X509Certificate2 cert = new X509Certificate2(TestData.MsCertificate))
+ {
+ store.Open(OpenFlags.ReadWrite);
+ cert.Dispose();
+ store.Remove(cert);
+ }
+ }
+
/* Placeholder information for these tests until they can be written to run reliably.
* Currently such tests would create physical files (Unix) and\or certificates (Windows)
* which can collide with other running tests that use the same cert, or from a