--- /dev/null
+//
+// X509CertificateCollection2Test.cs
+// - NUnit tests for X509CertificateCollection2
+//
+// Author:
+// Sebastien Pouliot <sebastien@ximian.com>
+//
+// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_2_0
+
+using NUnit.Framework;
+
+using System;
+using System.Security.Cryptography;
+using System.Security.Cryptography.X509Certificates;
+using System.Text;
+
+namespace MonoTests.System.Security.Cryptography.X509Certificates {
+
+ [TestFixture]
+ public class X509Certificate2CollectionTest {
+
+ private X509Certificate2Collection empty;
+ private X509Certificate2Collection single;
+ private X509Certificate2Collection collection;
+
+ private X509Certificate2 cert_empty;
+ private X509Certificate2 cert1;
+ private X509Certificate2 cert2;
+
+ [TestFixtureSetUp]
+ public void FixtureSetUp ()
+ {
+ cert_empty = new X509Certificate2 ();
+ cert1 = new X509Certificate2 (X509Certificate2Test.farscape_pfx, "farscape", X509KeyStorageFlags.Exportable);
+ cert2 = new X509Certificate2 (Encoding.ASCII.GetBytes (X509Certificate2Test.base64_cert));
+
+ empty = new X509Certificate2Collection ();
+ single = new X509Certificate2Collection ();
+ single.Add (cert1);
+ collection = new X509Certificate2Collection (single);
+ collection.Add (cert2);
+ }
+
+ [Test]
+ public void Ctor ()
+ {
+ X509Certificate2Collection c = new X509Certificate2Collection ();
+ Assert.AreEqual (0, c.Count, "Count");
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void Ctor_X509CertificateCollection2_Null ()
+ {
+ new X509Certificate2Collection ((X509Certificate2Collection) null);
+ }
+
+ [Test]
+ public void Ctor_X509CertificateCollection2_Empty ()
+ {
+ X509Certificate2Collection c = new X509Certificate2Collection (empty);
+ Assert.AreEqual (0, c.Count, "Count");
+ }
+
+ [Test]
+ public void Ctor_X509CertificateCollection2 ()
+ {
+ X509Certificate2Collection c = new X509Certificate2Collection (collection);
+ Assert.AreEqual (2, c.Count, "Count");
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void Ctor_X509Certificate2_Null ()
+ {
+ new X509Certificate2Collection ((X509Certificate2) null);
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void Ctor_X509Certificate2Array_Null ()
+ {
+ new X509Certificate2Collection ((X509Certificate2[]) null);
+ }
+
+ [Test]
+ public void Ctor_X509Certificate2Array_Empty ()
+ {
+ X509Certificate2[] array = new X509Certificate2 [0];
+ X509Certificate2Collection c = new X509Certificate2Collection (array);
+ Assert.AreEqual (0, c.Count, "Count");
+ }
+
+ [Test]
+ public void Ctor_X509Certificate2Array ()
+ {
+ X509Certificate2[] array = new X509Certificate2[3] { cert1, cert2, cert_empty };
+ X509Certificate2Collection c = new X509Certificate2Collection (array);
+ Assert.AreEqual (3, c.Count, "Count");
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void Add_X509Certificate2_Null ()
+ {
+ collection.Add ((X509Certificate2) null);
+ }
+
+ [Test]
+ public void Add_X509Certificate2 ()
+ {
+ X509Certificate2Collection c = new X509Certificate2Collection ();
+ Assert.AreEqual (0, c.Count, "0");
+ c.Add (cert1);
+ Assert.AreEqual (1, c.Count, "1");
+ // adding invalid certificate
+ c.Add (cert_empty);
+ Assert.AreEqual (2, c.Count, "2");
+ // re-adding same certificate
+ c.Add (cert1);
+ Assert.AreEqual (3, c.Count, "3");
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void AddRange_X509Certificate2Collection_Null ()
+ {
+ collection.AddRange ((X509Certificate2Collection) null);
+ }
+
+ [Test]
+ public void AddRange_X509Certificate2Collection ()
+ {
+ X509Certificate2Collection c = new X509Certificate2Collection ();
+ c.AddRange (empty);
+ Assert.AreEqual (0, c.Count, "0");
+ c.AddRange (single);
+ Assert.AreEqual (1, c.Count, "1");
+ c.AddRange (collection);
+ Assert.AreEqual (3, c.Count, "3");
+ // re-adding same collection
+ c.AddRange (single);
+ Assert.AreEqual (4, c.Count, "4");
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void AddRange_X509Certificate2Array_Null ()
+ {
+ collection.AddRange ((X509Certificate2[]) null);
+ }
+
+ [Test]
+ public void AddRange_X509Certificate2Array ()
+ {
+ X509Certificate2Collection c = new X509Certificate2Collection ();
+ c.AddRange (new X509Certificate2 [0]);
+ Assert.AreEqual (0, c.Count, "0");
+ c.AddRange (new X509Certificate2[3] { cert1, cert2, cert_empty });
+ Assert.AreEqual (3, c.Count, "3");
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void Contains_X509Certificate2_Null ()
+ {
+ empty.Contains ((X509Certificate2) null);
+ }
+
+ [Test]
+ public void Contains_Empty ()
+ {
+ Assert.IsFalse (empty.Contains (cert_empty), "empty|cert_empty");
+ Assert.IsFalse (empty.Contains (cert1), "empty|cert1");
+ Assert.IsFalse (empty.Contains (cert2), "empty|cert2");
+ }
+
+ [Test]
+ public void Contains ()
+ {
+ Assert.IsTrue (single.Contains (cert1), "single|cert1");
+ Assert.IsFalse (single.Contains (cert2), "single|cert2");
+
+ Assert.IsTrue (collection.Contains (cert1), "multi|cert1");
+ Assert.IsTrue (collection.Contains (cert2), "multi|cert2");
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void Contains_EmptyCert ()
+ {
+ single.Contains (cert_empty);
+ // note: Equals fails, but it works for an empty collection (not called)
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void Export_Empty_Authenticode ()
+ {
+ empty.Export (X509ContentType.Authenticode);
+ }
+
+ [Test]
+ public void Export_Empty ()
+ {
+ Assert.IsNull (empty.Export (X509ContentType.Cert), "Cert");
+ Assert.IsNull (empty.Export (X509ContentType.Cert, null), "Cert,null");
+ Assert.IsNull (empty.Export (X509ContentType.Cert, String.Empty), "Cert,Empty");
+ Assert.IsNull (empty.Export (X509ContentType.SerializedCert), "SerializedCert");
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ [Category ("NotWorking")]
+ public void Export_Empty_Pfx ()
+ {
+ byte[] data = empty.Export (X509ContentType.Pfx);
+ Assert.IsNotNull (data, "data");
+ Assert.AreEqual (X509ContentType.Pfx, X509Certificate2.GetCertContentType (data), "GetCertContentType");
+ // not usable
+ new X509Certificate2 (data);
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ [Category ("NotWorking")]
+ public void Export_Empty_Pkcs12 ()
+ {
+ byte[] data = empty.Export (X509ContentType.Pkcs12);
+ Assert.IsNotNull (data, "data");
+ Assert.AreEqual (X509ContentType.Pkcs12, X509Certificate2.GetCertContentType (data), "GetCertContentType");
+ // not usable
+ new X509Certificate2 (data);
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ [Category ("NotWorking")]
+ public void Export_Empty_Pkcs7 ()
+ {
+ byte[] data = empty.Export (X509ContentType.Pkcs7);
+ Assert.IsNotNull (data, "data");
+ Assert.AreEqual (X509ContentType.Pkcs7, X509Certificate2.GetCertContentType (data), "GetCertContentType");
+ // not usable
+ new X509Certificate2 (data);
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ [Category ("NotWorking")]
+ public void Export_Empty_SerializedStore ()
+ {
+ byte[] data = empty.Export (X509ContentType.SerializedStore);
+ Assert.IsNotNull (data, "data");
+ Assert.AreEqual (X509ContentType.SerializedStore, X509Certificate2.GetCertContentType (data), "GetCertContentType");
+ // not usable
+ new X509Certificate2 (data);
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void Export_Empty_Unknown ()
+ {
+ empty.Export (X509ContentType.Unknown);
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void Export_Empty_Bad ()
+ {
+ empty.Export ((X509ContentType)Int32.MinValue);
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void Export_Single_Authenticode ()
+ {
+ single.Export (X509ContentType.Authenticode);
+ }
+
+ [Test]
+ public void Export_Single_Cert ()
+ {
+ byte[] data = single.Export (X509ContentType.Cert);
+ Assert.AreEqual (X509ContentType.Cert, X509Certificate2.GetCertContentType (data), "GetCertContentType");
+ Assert.AreEqual (data, cert1.RawData, "RawData");
+ // usable
+ X509Certificate2 c = new X509Certificate2 (data);
+ Assert.AreEqual (cert1, c, "Equals");
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ public void Export_Single_Pfx ()
+ {
+ byte[] data = single.Export (X509ContentType.Pfx);
+ Assert.AreEqual (X509ContentType.Pfx, X509Certificate2.GetCertContentType (data), "GetCertContentType");
+ // usable
+ X509Certificate2 c = new X509Certificate2 (data);
+ Assert.AreEqual (cert1, c, "Equals");
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ public void Export_Single_Pkcs12 ()
+ {
+ byte[] data = single.Export (X509ContentType.Pkcs12);
+ Assert.AreEqual (X509ContentType.Pkcs12, X509Certificate2.GetCertContentType (data), "GetCertContentType");
+ // usable
+ X509Certificate2 c = new X509Certificate2 (data);
+ Assert.AreEqual (cert1, c, "Equals");
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ [Category ("NotWorking")]
+ public void Export_Single_Pkcs7 ()
+ {
+ byte[] data = single.Export (X509ContentType.Pkcs7);
+ Assert.AreEqual (X509ContentType.Pkcs7, X509Certificate2.GetCertContentType (data), "GetCertContentType");
+ // not usable
+ new X509Certificate2 (data);
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ public void Export_Single_SerializedCert ()
+ {
+ byte[] data = single.Export (X509ContentType.SerializedCert);
+ Assert.AreEqual (X509ContentType.SerializedCert, X509Certificate2.GetCertContentType (data), "GetCertContentType");
+ // usable
+ X509Certificate2 c = new X509Certificate2 (data);
+ Assert.AreEqual (cert1, c, "Equals");
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ [Category ("NotWorking")]
+ public void Export_Single_SerializedStore ()
+ {
+ byte[] data = single.Export (X509ContentType.SerializedStore);
+ Assert.AreEqual (X509ContentType.SerializedStore, X509Certificate2.GetCertContentType (data), "GetCertContentType");
+ // not usable
+ new X509Certificate2 (data);
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void Export_Single_Unknown ()
+ {
+ single.Export (X509ContentType.Unknown);
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void Export_Single_Bad ()
+ {
+ single.Export ((X509ContentType) Int32.MinValue);
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void Export_Multiple_Authenticode ()
+ {
+ collection.Export (X509ContentType.Authenticode);
+ }
+
+ [Test]
+ public void Export_Multiple_Cert ()
+ {
+ byte[] data = collection.Export (X509ContentType.Cert);
+ Assert.AreEqual (X509ContentType.Cert, X509Certificate2.GetCertContentType (data), "GetCertContentType");
+ // last certificate was exported
+ Assert.AreEqual (data, cert2.RawData, "RawData");
+ // usable
+ X509Certificate2 c = new X509Certificate2 (data);
+ Assert.AreEqual (cert2, c, "Equals");
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ public void Export_Multiple_Pfx ()
+ {
+ byte[] data = collection.Export (X509ContentType.Pfx);
+ Assert.AreEqual (X509ContentType.Pfx, X509Certificate2.GetCertContentType (data), "GetCertContentType");
+ // usable
+ X509Certificate2 c = new X509Certificate2 (data);
+ Assert.AreEqual (cert1, c, "Equals");
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ public void Export_Multiple_Pkcs12 ()
+ {
+ byte[] data = collection.Export (X509ContentType.Pkcs12);
+ Assert.AreEqual (X509ContentType.Pkcs12, X509Certificate2.GetCertContentType (data), "GetCertContentType");
+ // usable
+ X509Certificate2 c = new X509Certificate2 (data);
+ Assert.AreEqual (cert1, c, "Equals");
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ [Category ("NotWorking")]
+ public void Export_Multiple_Pkcs7 ()
+ {
+ byte[] data = collection.Export (X509ContentType.Pkcs7);
+ Assert.AreEqual (X509ContentType.Pkcs7, X509Certificate2.GetCertContentType (data), "GetCertContentType");
+ // not usable
+ new X509Certificate2 (data);
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ public void Export_Multiple_SerializedCert ()
+ {
+ byte[] data = collection.Export (X509ContentType.SerializedCert);
+ Assert.AreEqual (X509ContentType.SerializedCert, X509Certificate2.GetCertContentType (data), "GetCertContentType");
+ // usable
+ X509Certificate2 c = new X509Certificate2 (data);
+ // last certificate was exported
+ Assert.AreEqual (cert2, c, "Equals");
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ [Category ("NotWorking")]
+ public void Export_Multiple_SerializedStore ()
+ {
+ byte[] data = collection.Export (X509ContentType.SerializedStore);
+ Assert.AreEqual (X509ContentType.SerializedStore, X509Certificate2.GetCertContentType (data), "GetCertContentType");
+ // not usable
+ new X509Certificate2 (data);
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void Export_Multiple_Unknown ()
+ {
+ collection.Export (X509ContentType.Unknown);
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void Export_Multiple_Bad ()
+ {
+ collection.Export ((X509ContentType) Int32.MinValue);
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void Find_FindValue_Null ()
+ {
+ empty.Find (X509FindType.FindByApplicationPolicy, null, true);
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void Find_FindType_Bad ()
+ {
+ empty.Find ((X509FindType)Int32.MinValue, new object(), true);
+ }
+
+ [Test]
+ public void Find_Empty ()
+ {
+ string oid = "1.2.3.4";
+ Assert.AreEqual (0, empty.Find (X509FindType.FindByApplicationPolicy, oid, false).Count, "Empty|FindByApplicationPolicy");
+ Assert.AreEqual (0, empty.Find (X509FindType.FindByCertificatePolicy, oid, false).Count, "Empty|FindByCertificatePolicy");
+ Assert.AreEqual (0, empty.Find (X509FindType.FindByExtension, oid, false).Count, "Empty|FindByExtension");
+ Assert.AreEqual (0, empty.Find (X509FindType.FindByIssuerDistinguishedName, String.Empty, false).Count, "Empty|FindByIssuerDistinguishedName");
+ Assert.AreEqual (0, empty.Find (X509FindType.FindByIssuerName, String.Empty, false).Count, "Empty|FindByIssuerName");
+ Assert.AreEqual (0, empty.Find (X509FindType.FindByKeyUsage, X509KeyUsageFlags.CrlSign, false).Count, "Empty|FindByKeyUsage");
+ Assert.AreEqual (0, empty.Find (X509FindType.FindBySerialNumber, String.Empty, false).Count, "Empty|FindBySerialNumber");
+ Assert.AreEqual (0, empty.Find (X509FindType.FindBySubjectDistinguishedName, String.Empty, false).Count, "Empty|FindBySubjectDistinguishedName");
+ Assert.AreEqual (0, empty.Find (X509FindType.FindBySubjectKeyIdentifier, String.Empty, false).Count, "Empty|FindBySubjectKeyIdentifier");
+ Assert.AreEqual (0, empty.Find (X509FindType.FindBySubjectName, String.Empty, false).Count, "Empty|FindByTemplateName");
+ Assert.AreEqual (0, empty.Find (X509FindType.FindByTemplateName, String.Empty, false).Count, "Empty|FindByTemplateName");
+ Assert.AreEqual (0, empty.Find (X509FindType.FindByThumbprint, String.Empty, false).Count, "Empty|FindByThumbprint");
+ Assert.AreEqual (0, empty.Find (X509FindType.FindByTimeExpired, DateTime.Now, false).Count, "Empty|FindByTimeExpired");
+ Assert.AreEqual (0, empty.Find (X509FindType.FindByTimeNotYetValid, DateTime.Now, false).Count, "Empty|FindByTimeNotYetValid");
+ Assert.AreEqual (0, empty.Find (X509FindType.FindByTimeValid, DateTime.Now, false).Count, "Empty|FindByTimeValid");
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void Find_CollectionWithEmptyCert ()
+ {
+ new X509Certificate2Collection (cert_empty).Find (X509FindType.FindByIssuerName, String.Empty, false);
+ }
+
+ [Test]
+ public void Find_FindByApplicationPolicy ()
+ {
+ X509Certificate2Collection result = collection.Find (X509FindType.FindByApplicationPolicy, "1.2.3.4", false);
+ Assert.AreEqual (1, result.Count, "FindByApplicationPolicy/Empty/false");
+ Assert.AreEqual (0, result[0].Extensions.Count, "no extension");
+ // FIXME - need a negative test case (with extensions)
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentException))]
+ public void Find_FindByApplicationPolicy_NotOid ()
+ {
+ collection.Find (X509FindType.FindByApplicationPolicy, "policy", false);
+ }
+
+ [Test]
+ public void Find_FindByCertificatePolicy ()
+ {
+ Assert.AreEqual (0, collection.Find (X509FindType.FindByCertificatePolicy, "1.2.3.4", false).Count, "FindByApplicationPolicy/Empty/false");
+ // FIXME - need a positive test case
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentException))]
+ public void Find_FindByCertificatePolicy_NotOid ()
+ {
+ collection.Find (X509FindType.FindByCertificatePolicy, "policy", false);
+ }
+
+ [Test]
+ public void Find_FindByExtension ()
+ {
+ // partial match
+ Assert.AreEqual (0, collection.Find (X509FindType.FindByExtension, "2.5.29", false).Count, "FindByExtension/2.5.29/false");
+ // full match
+ Assert.AreEqual (1, collection.Find (X509FindType.FindByExtension, "2.5.29.1", false).Count, "FindByExtension/2.5.29.1/false");
+ Assert.AreEqual (1, collection.Find (X509FindType.FindByExtension, "2.5.29.37", false).Count, "FindByExtension/2.5.29.37/false");
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentException))]
+ public void Find_FindByExtension_NotOid ()
+ {
+ collection.Find (X509FindType.FindByExtension, "KeyUsage", false);
+ }
+
+ [Test]
+ public void Find_FindByIssuerDistinguishedName ()
+ {
+ // empty
+ Assert.AreEqual (0, collection.Find (X509FindType.FindByIssuerDistinguishedName, String.Empty, false).Count, "FindByIssuerDistinguishedName/Empty/false");
+ // partial match
+ Assert.AreEqual (0, collection.Find (X509FindType.FindByIssuerDistinguishedName, "Mono", false).Count, "FindByIssuerDistinguishedName/Mono/false");
+ Assert.AreEqual (0, collection.Find (X509FindType.FindByIssuerDistinguishedName, "CASTOR\\poupou", false).Count, "FindByIssuerDistinguishedName/castor/false");
+ // full match (requires CN= parts)
+ Assert.AreEqual (1, collection.Find (X509FindType.FindByIssuerDistinguishedName, cert1.Issuer, false).Count, "FindByIssuerDistinguishedName/cert1/false");
+ Assert.AreEqual (1, collection.Find (X509FindType.FindByIssuerDistinguishedName, cert2.IssuerName.Name, false).Count, "FindByIssuerDistinguishedName/cert2/false");
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void Find_FindByIssuerDistinguishedName_NotString ()
+ {
+ collection.Find (X509FindType.FindByIssuerDistinguishedName, 1, false);
+ }
+
+ [Test]
+ public void Find_FindByIssuerName ()
+ {
+ // empty
+ Assert.AreEqual (collection.Count, collection.Find (X509FindType.FindByIssuerName, String.Empty, false).Count, "FindByIssuerName/Empty/false");
+ Assert.AreEqual (0, collection.Find (X509FindType.FindByIssuerName, String.Empty, true).Count, "FindByIssuerName/Empty/true");
+ // partial match
+ Assert.AreEqual (1, collection.Find (X509FindType.FindByIssuerName, "Mono", false).Count, "FindByIssuerName/Mono/false");
+ Assert.AreEqual (1, collection.Find (X509FindType.FindByIssuerName, "CASTOR\\poupou", false).Count, "FindByIssuerName/castor/false");
+ // full match (doesn't like CN= parts)
+ Assert.AreEqual (0, collection.Find (X509FindType.FindByIssuerName, cert1.Issuer, false).Count, "FindByIssuerName/cert1/false");
+ Assert.AreEqual (0, collection.Find (X509FindType.FindByIssuerName, cert2.IssuerName.Name, false).Count, "FindByIssuerName/cert2/false");
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void Find_FindByIssuerName_NotString ()
+ {
+ collection.Find (X509FindType.FindByIssuerName, DateTime.Now, false);
+ }
+
+ [Test]
+ public void Find_FindByKeyUsage ()
+ {
+ // empty
+ Assert.AreEqual (2, collection.Find (X509FindType.FindByKeyUsage, X509KeyUsageFlags.None, false).Count, "FindByKeyUsage/None/false");
+ Assert.AreEqual (0, collection.Find (X509FindType.FindByKeyUsage, X509KeyUsageFlags.None, true).Count, "FindByKeyUsage/None/true");
+ // always match if no KeyUsageExtension is present in certificate, EnhancedKeyUsageExtension not considered
+ Assert.AreEqual (2, collection.Find (X509FindType.FindByKeyUsage, X509KeyUsageFlags.CrlSign, false).Count, "FindByKeyUsage/CrlSign/false");
+ Assert.AreEqual (2, collection.Find (X509FindType.FindByKeyUsage, X509KeyUsageFlags.DataEncipherment, false).Count, "FindByKeyUsage/DataEncipherment/false");
+ Assert.AreEqual (2, collection.Find (X509FindType.FindByKeyUsage, X509KeyUsageFlags.DecipherOnly, false).Count, "FindByKeyUsage/DecipherOnly/false");
+ Assert.AreEqual (2, collection.Find (X509FindType.FindByKeyUsage, X509KeyUsageFlags.DigitalSignature, false).Count, "FindByKeyUsage/DigitalSignature/false");
+ Assert.AreEqual (2, collection.Find (X509FindType.FindByKeyUsage, X509KeyUsageFlags.EncipherOnly, false).Count, "FindByKeyUsage/EncipherOnly/false");
+ Assert.AreEqual (2, collection.Find (X509FindType.FindByKeyUsage, X509KeyUsageFlags.KeyAgreement, false).Count, "FindByKeyUsage/KeyAgreement/false");
+ Assert.AreEqual (2, collection.Find (X509FindType.FindByKeyUsage, X509KeyUsageFlags.KeyCertSign, false).Count, "FindByKeyUsage/KeyCertSign/false");
+ Assert.AreEqual (2, collection.Find (X509FindType.FindByKeyUsage, X509KeyUsageFlags.KeyEncipherment, false).Count, "FindByKeyUsage/KeyEncipherment/false");
+ Assert.AreEqual (2, collection.Find (X509FindType.FindByKeyUsage, X509KeyUsageFlags.NonRepudiation, false).Count, "FindByKeyUsage/NonRepudiation/false");
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void Find_FindByIssuerName_NotX509KeyUsageFlags ()
+ {
+ collection.Find (X509FindType.FindByKeyUsage, String.Empty, false);
+ }
+
+ [Test]
+ public void Find_FindBySerialNumber ()
+ {
+ // empty
+ Assert.AreEqual (0, collection.Find (X509FindType.FindBySerialNumber, String.Empty, false).Count, "FindBySerialNumber/Empty/false");
+ // partial match (start, end)
+ Assert.AreEqual (0, collection.Find (X509FindType.FindBySerialNumber, "748B", false).Count, "FindBySerialNumber/748B/false");
+ Assert.AreEqual (0, collection.Find (X509FindType.FindBySerialNumber, "4769", false).Count, "FindBySerialNumber/4769/false");
+ // full match
+ Assert.AreEqual (1, collection.Find (X509FindType.FindBySerialNumber, cert1.SerialNumber, false).Count, "FindBySerialNumber/cert1/false");
+ Assert.AreEqual (1, collection.Find (X509FindType.FindBySerialNumber, cert2.SerialNumber, false).Count, "FindBySerialNumber/cert2/false");
+ Assert.AreEqual (1, collection.Find (X509FindType.FindBySerialNumber, cert1.SerialNumber.ToLowerInvariant (), false).Count, "FindBySerialNumber/cert1b/false");
+ Assert.AreEqual (1, collection.Find (X509FindType.FindBySerialNumber, cert2.SerialNumber.ToLowerInvariant (), false).Count, "FindBySerialNumber/cert2b/false");
+ // full match inverted
+ Assert.AreEqual (1, collection.Find (X509FindType.FindBySerialNumber, cert1.GetSerialNumberString (), false).Count, "FindBySerialNumber/cert1c/false");
+ Assert.AreEqual (1, collection.Find (X509FindType.FindBySerialNumber, cert2.GetSerialNumberString (), false).Count, "FindBySerialNumber/cert2c/false");
+ Assert.AreEqual (1, collection.Find (X509FindType.FindBySerialNumber, cert1.GetSerialNumberString ().ToLowerInvariant (), false).Count, "FindBySerialNumber/cert1d/false");
+ Assert.AreEqual (1, collection.Find (X509FindType.FindBySerialNumber, cert2.GetSerialNumberString ().ToLowerInvariant (), false).Count, "FindBySerialNumber/cert2d/false");
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void Find_FindBySerialNumber_NotString ()
+ {
+ collection.Find (X509FindType.FindBySerialNumber, DateTime.Now, false);
+ }
+
+ [Test]
+ public void Find_FindBySubjectDistinguishedName ()
+ {
+ // empty
+ Assert.AreEqual (0, collection.Find (X509FindType.FindBySubjectDistinguishedName, String.Empty, false).Count, "FindBySubjectDistinguishedName/Empty/false");
+ // partial match
+ Assert.AreEqual (0, collection.Find (X509FindType.FindBySubjectDistinguishedName, "Mono", false).Count, "FindBySubjectDistinguishedName/Mono/false");
+ Assert.AreEqual (0, collection.Find (X509FindType.FindBySubjectDistinguishedName, "CASTOR\\poupou", false).Count, "FindBySubjectDistinguishedName/castor/false");
+ // full match (requires CN= parts) using all lowercase
+ Assert.AreEqual (1, collection.Find (X509FindType.FindBySubjectDistinguishedName, cert1.Subject.ToLowerInvariant (), false).Count, "FindBySubjectDistinguishedName/cert1/false");
+ Assert.AreEqual (1, collection.Find (X509FindType.FindBySubjectDistinguishedName, cert2.SubjectName.Name.ToLowerInvariant (), false).Count, "FindBySubjectDistinguishedName/cert2/false");
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void Find_FindBySubjectDistinguishedName_NotString ()
+ {
+ collection.Find (X509FindType.FindBySubjectDistinguishedName, new object (), false);
+ }
+
+ [Test]
+ public void Find_FindBySubjectKeyIdentifier ()
+ {
+ // empty
+ Assert.AreEqual (0, collection.Find (X509FindType.FindBySubjectKeyIdentifier, String.Empty, false).Count, "FindBySubjectKeyIdentifier/Empty/false");
+
+ X509Certificate2Collection c = new X509Certificate2Collection (collection);
+ c.Add (new X509Certificate2 (X509Certificate2Test.cert_8));
+ Assert.AreEqual (0, c.Find (X509FindType.FindBySubjectKeyIdentifier, "9D2D73C3B8E34D2928C3", false).Count, "FindBySubjectKeyIdentifier/half/false");
+ Assert.AreEqual (1, c.Find (X509FindType.FindBySubjectKeyIdentifier, "9D2D73C3B8E34D2928C365BEA998CBD68A06689C", false).Count, "FindBySubjectKeyIdentifier/full/false");
+ Assert.AreEqual (1, c.Find (X509FindType.FindBySubjectKeyIdentifier, "9d2d73c3b8e34d2928c365bea998cbd68a06689c", false).Count, "FindBySubjectKeyIdentifier/full/false");
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void Find_FindBySubjectKeyIdentifier_NotString ()
+ {
+ collection.Find (X509FindType.FindBySubjectKeyIdentifier, 1, false);
+ }
+
+ [Test]
+ public void Find_FindBySubjectName ()
+ {
+ // empty
+ Assert.AreEqual (collection.Count, collection.Find (X509FindType.FindBySubjectName, String.Empty, false).Count, "FindBySubjectName/Empty/false");
+ Assert.AreEqual (0, collection.Find (X509FindType.FindBySubjectName, String.Empty, true).Count, "FindBySubjectName/Empty/true");
+ // partial match (using inverted case)
+ Assert.AreEqual (1, collection.Find (X509FindType.FindBySubjectName, "farscap", false).Count, "FindBySubjectName/Mono/false");
+ Assert.AreEqual (1, collection.Find (X509FindType.FindBySubjectName, "castor\\POUPOU", false).Count, "FindBySubjectName/castor/false");
+ // full match (doesn't like CN= parts)
+ Assert.AreEqual (0, collection.Find (X509FindType.FindBySubjectName, cert1.Subject, false).Count, "FindBySubjectName/cert1/false");
+ Assert.AreEqual (0, collection.Find (X509FindType.FindBySubjectName, cert2.SubjectName.Name, false).Count, "FindBySubjectName/cert2/false");
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void Find_FindBySubjectName_NotString ()
+ {
+ collection.Find (X509FindType.FindBySubjectName, 'c', false);
+ }
+
+ [Test]
+ public void Find_FindByTemplateName ()
+ {
+ // empty
+ Assert.AreEqual (0, collection.Find (X509FindType.FindByTemplateName, String.Empty, false).Count, "FindByTemplateName/Empty/false");
+ // wilcard match
+ Assert.AreEqual (0, collection.Find (X509FindType.FindByTemplateName, "*", false).Count, "FindByTemplateName/Mono/false");
+ // FIXME - need a positive test case
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void Find_FindByTemplateName_NotString ()
+ {
+ collection.Find (X509FindType.FindByTemplateName, 0, false);
+ }
+
+ [Test]
+ public void Find_FindByThumbprint ()
+ {
+ // empty
+ Assert.AreEqual (0, collection.Find (X509FindType.FindByThumbprint, String.Empty, false).Count, "FindByThumbprint/Empty/false");
+ // partial match (start, end)
+ Assert.AreEqual (0, collection.Find (X509FindType.FindByThumbprint, "3029", false).Count, "FindByThumbprint/3029/false");
+ Assert.AreEqual (0, collection.Find (X509FindType.FindByThumbprint, "8529", false).Count, "FindByThumbprint/8529/false");
+ // full match
+ Assert.AreEqual (1, collection.Find (X509FindType.FindByThumbprint, cert1.Thumbprint, false).Count, "FindByThumbprint/cert1/false");
+ Assert.AreEqual (1, collection.Find (X509FindType.FindByThumbprint, cert2.Thumbprint, false).Count, "FindByThumbprint/cert2/false");
+ Assert.AreEqual (1, collection.Find (X509FindType.FindByThumbprint, cert1.Thumbprint.ToLowerInvariant (), false).Count, "FindByThumbprint/cert1b/false");
+ Assert.AreEqual (1, collection.Find (X509FindType.FindByThumbprint, cert2.Thumbprint.ToLowerInvariant (), false).Count, "FindByThumbprint/cert2b/false");
+ // full match inverted
+ Assert.AreEqual (1, collection.Find (X509FindType.FindByThumbprint, cert1.GetCertHashString (), false).Count, "FindByThumbprint/cert1c/false");
+ Assert.AreEqual (1, collection.Find (X509FindType.FindByThumbprint, cert2.GetCertHashString (), false).Count, "FindByThumbprint/cert2c/false");
+ Assert.AreEqual (1, collection.Find (X509FindType.FindByThumbprint, cert1.GetCertHashString ().ToLowerInvariant (), false).Count, "FindByThumbprint/cert1d/false");
+ Assert.AreEqual (1, collection.Find (X509FindType.FindByThumbprint, cert2.GetCertHashString ().ToLowerInvariant (), false).Count, "FindByThumbprint/cert2d/false");
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void Find_FindByThumbprint_NotString ()
+ {
+ collection.Find (X509FindType.FindByThumbprint, 0, false);
+ }
+
+ [Test]
+ public void Find_FindByTimeExpired ()
+ {
+ // now (valid from today until 2039)
+ Assert.AreEqual (1, collection.Find (X509FindType.FindByTimeExpired, DateTime.Now, false).Count, "FindByTimeExpired/Now/false");
+ Assert.AreEqual (0, collection.Find (X509FindType.FindByTimeExpired, new DateTime (631108726620000000), false).Count, "FindByTimeExpired/2000/false");
+ Assert.AreEqual (2, collection.Find (X509FindType.FindByTimeExpired, new DateTime (644392619990000000), false).Count, "FindByTimeExpired/2042/false");
+
+ Assert.AreEqual (1, collection.Find (X509FindType.FindByTimeExpired, cert1.NotAfter, false).Count, "FindByTimeExpired/cert1.NotAfter/false");
+ Assert.AreEqual (0, collection.Find (X509FindType.FindByTimeExpired, cert1.NotBefore, false).Count, "FindByTimeExpired/cert1.NotBefore/false");
+ Assert.AreEqual (0, collection.Find (X509FindType.FindByTimeExpired, cert2.NotAfter, false).Count, "FindByTimeExpired/cert2.NotAfter/false");
+ Assert.AreEqual (0, collection.Find (X509FindType.FindByTimeExpired, cert2.NotBefore, false).Count, "FindByTimeExpired/cert2.NotBefore/false");
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void Find_FindByTimeExpired_NotDateTime ()
+ {
+ collection.Find (X509FindType.FindByTimeExpired, String.Empty, false);
+ }
+
+ [Test]
+ public void Find_FindByTimeNotYetValid ()
+ {
+ Assert.AreEqual (0, collection.Find (X509FindType.FindByTimeNotYetValid, DateTime.Now, false).Count, "FindByTimeNotYetValid/Now/false");
+ Assert.AreEqual (2, collection.Find (X509FindType.FindByTimeNotYetValid, new DateTime (631108726620000000), false).Count, "FindByTimeNotYetValid/2000/false");
+ Assert.AreEqual (0, collection.Find (X509FindType.FindByTimeNotYetValid, new DateTime (644392619990000000), false).Count, "FindByTimeNotYetValid/2042/false");
+
+ Assert.AreEqual (0, collection.Find (X509FindType.FindByTimeNotYetValid, cert1.NotAfter, false).Count, "FindByTimeNotYetValid/cert1.NotAfter/false");
+ Assert.AreEqual (1, collection.Find (X509FindType.FindByTimeNotYetValid, cert1.NotBefore, false).Count, "FindByTimeNotYetValid/cert1.NotBefore/false");
+ Assert.AreEqual (0, collection.Find (X509FindType.FindByTimeNotYetValid, cert2.NotAfter, false).Count, "FindByTimeNotYetValid/cert2.NotAfter/false");
+ Assert.AreEqual (0, collection.Find (X509FindType.FindByTimeNotYetValid, cert2.NotBefore, false).Count, "FindByTimeNotYetValid/cert2.NotBefore/false");
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void Find_FindByTimeNotYetValid_NotDateTime ()
+ {
+ collection.Find (X509FindType.FindByTimeNotYetValid, DateTime.Now.ToString (), false);
+ }
+
+ [Test]
+ public void Find_FindByTimeValid ()
+ {
+ Assert.AreEqual (1, collection.Find (X509FindType.FindByTimeValid, DateTime.Now, false).Count, "FindByTimeValid/Now/false");
+ Assert.AreEqual (0, collection.Find (X509FindType.FindByTimeValid, new DateTime (631108726620000000), false).Count, "FindByTimeValid/2000/false");
+ Assert.AreEqual (0, collection.Find (X509FindType.FindByTimeValid, new DateTime (644392619990000000), false).Count, "FindByTimeValid/2042/false");
+
+ Assert.AreEqual (1, collection.Find (X509FindType.FindByTimeValid, cert1.NotAfter, false).Count, "FindByTimeValid/cert1.NotAfter/false");
+ Assert.AreEqual (1, collection.Find (X509FindType.FindByTimeValid, cert1.NotBefore, false).Count, "FindByTimeValid/cert1.NotBefore/false");
+ Assert.AreEqual (2, collection.Find (X509FindType.FindByTimeValid, cert2.NotAfter, false).Count, "FindByTimeValid/cert2.NotAfter/false");
+ Assert.AreEqual (2, collection.Find (X509FindType.FindByTimeValid, cert2.NotBefore, false).Count, "FindByTimeValid/cert2.NotBefore/false");
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void Find_FindByTimeValid_NotDateTime ()
+ {
+ collection.Find (X509FindType.FindByTimeValid, String.Empty, false);
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void Remove_X509Certificate2_Null ()
+ {
+ collection.Remove ((X509Certificate2) null);
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void Remove_X509Certificate2_Empty ()
+ {
+ single.Remove (cert_empty);
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void RemoveRange_X509Certificate2Collection_Null ()
+ {
+ collection.RemoveRange ((X509Certificate2Collection) null);
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void RemoveRange_X509Certificate2Collection_EmptyCert ()
+ {
+ collection.RemoveRange (new X509Certificate2Collection (cert_empty));
+ }
+
+ [Test]
+ public void RemoveRange_X509Certificate2Collection_Empty ()
+ {
+ Assert.AreEqual (2, collection.Count, "Count/before");
+ collection.RemoveRange (empty);
+ Assert.AreEqual (2, collection.Count, "Count/after");
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void RemoveRange_X509Certificate2Array_Null ()
+ {
+ collection.RemoveRange ((X509Certificate2[]) null);
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void RemoveRange_X509Certificate2Array_EmptyCert ()
+ {
+ collection.RemoveRange (new X509Certificate2[1] { cert_empty });
+ }
+
+ [Test]
+ public void RemoveRange_X509Certificate2Array_Empty ()
+ {
+ Assert.AreEqual (2, collection.Count, "Count/before");
+ collection.RemoveRange (new X509Certificate2[0]);
+ Assert.AreEqual (2, collection.Count, "Count/after");
+ }
+
+ [Test]
+ [ExpectedException (typeof (InvalidCastException))]
+ public void MixedCollection_Indexer ()
+ {
+ X509Certificate2Collection c = new X509Certificate2Collection ();
+ c.Add (new X509Certificate (X509Certificate2Test.farscape_pfx, "farscape"));
+ Assert.IsTrue ((c[0] is X509Certificate), "X509Certificate/0");
+ // it's impossible to use the this[int] indexer to get the object in the collection
+ }
+
+ [Test]
+ [ExpectedException (typeof (InvalidCastException))]
+ public void MixedCollection_Enumerator ()
+ {
+ X509Certificate2Collection c = new X509Certificate2Collection ();
+ c.Add (new X509Certificate (X509Certificate2Test.farscape_pfx, "farscape"));
+ foreach (object o in c) {
+ Assert.IsTrue ((o is X509Certificate), "X509Certificate");
+ }
+ }
+ }
+}
+
+#endif
0x4E,0xB5,0x1B,0xBC,0xB9,0xC4,0xB0,0xE2,0x8A,0x3E,0x05,0xA6,0xE3,0x56,0x7D,0x01,0x77,0xAB,0xC2,0xA6,0x72,0x90,0x23,0xD3,0x15,0x8F,0x0F,0xEA,0x7B,0x31,0xDE,0x89,0x31,0xF0,0x1B,0x81,0x6B,0x5F,0xA8,0x13,0xC6,0x62,0x7D,0xFE,0x74,0x14,0x40,0x2A,0x14,0xC2,0xA1,0x1B,0x9C,0xB2,0xD6,0xEF,0x2A,0x6D,0xA5,0xF7,0xA6,0x38,0x8F,0xD4,0x94,0x74,0x30,0x10,0x9E,0xBA,0xA9,0xAB,0x6B,0x61,0x6B,0xFC,0xB2,0x3F,0x87,0x6B,0x19,0x82,0x83,0x70,0xE7,0xD8,0xEA,0x28,0x7B,0xB4,0x29,0x47,0xF4,0x59,0xB3,0x3E,0x4B,0x6A,0x9D,0x54,
0x0D,0x4E,0x1C,0xD0,0x29,0xB4,0xD1,0xE1,0x19,0x79,0x41,0x73,0xF6,0x57,0x72,0xBE,0x75,0x03,0x94,0xD7,0x58,0xA8,0xC4,0x08,0x71,0xA2,0xE3,0x16,0x31,0xCD,0xC0,0xEE,0x1C,0x21,0x26,0x52,0x55,0x7B,0x00,0x54,0x6D,0xA6,0x44,0xC2,0x4F,0xEA,0x8F,0x04,0x1C,0x3A,0xA2,0xE3,0x5B,0xD7,0x9D,0xE2,0x57,0x30,0x2C,0xF5,0xAE,0x62,0x3B,0xB5,0x49,0x89,0xCB,0x01,0xD1,0x5A,0x38,0xDE,0x97,0x57,0x85,0x91,0x68,0x6B,0xFD,0xEC,0xD3,0x80,0xF0,0x82,0xBF,0x9A };
- private static byte[] cert_8 = { 0x30,0x82,0x03,0x04,0x30,0x82,0x02,0xC4,0xA0,0x03,0x02,0x01,0x02,0x02,0x01,0x03,0x30,0x09,0x06,0x07,0x2A,0x86,0x48,0xCE,0x38,0x04,0x03,0x30,0x51,0x31,0x0B,0x30,0x09,0x06,0x03,0x55,0x04,0x06,0x13,0x02,0x55,0x53,0x31,0x18,0x30,0x16,0x06,0x03,0x55,0x04,0x0A,0x13,0x0F,0x55,0x2E,0x53,0x2E,0x20,0x47,0x6F,0x76,0x65,0x72,0x6E,0x6D,0x65,0x6E,0x74,0x31,0x0C,0x30,0x0A,0x06,0x03,0x55,0x04,0x0B,0x13,0x03,0x44,0x6F,0x44,0x31,0x1A,0x30,0x18,0x06,0x03,0x55,0x04,0x03,0x13,0x11,0x41,0x72,0x6D,0x65,0x64,0x20,0x46,0x6F,
+ public static byte[] cert_8 = { 0x30,0x82,0x03,0x04,0x30,0x82,0x02,0xC4,0xA0,0x03,0x02,0x01,0x02,0x02,0x01,0x03,0x30,0x09,0x06,0x07,0x2A,0x86,0x48,0xCE,0x38,0x04,0x03,0x30,0x51,0x31,0x0B,0x30,0x09,0x06,0x03,0x55,0x04,0x06,0x13,0x02,0x55,0x53,0x31,0x18,0x30,0x16,0x06,0x03,0x55,0x04,0x0A,0x13,0x0F,0x55,0x2E,0x53,0x2E,0x20,0x47,0x6F,0x76,0x65,0x72,0x6E,0x6D,0x65,0x6E,0x74,0x31,0x0C,0x30,0x0A,0x06,0x03,0x55,0x04,0x0B,0x13,0x03,0x44,0x6F,0x44,0x31,0x1A,0x30,0x18,0x06,0x03,0x55,0x04,0x03,0x13,0x11,0x41,0x72,0x6D,0x65,0x64,0x20,0x46,0x6F,
0x72,0x63,0x65,0x73,0x20,0x52,0x6F,0x6F,0x74,0x30,0x1E,0x17,0x0D,0x30,0x30,0x31,0x30,0x32,0x35,0x30,0x30,0x30,0x30,0x30,0x30,0x5A,0x17,0x0D,0x30,0x33,0x30,0x31,0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x5A,0x30,0x51,0x31,0x0B,0x30,0x09,0x06,0x03,0x55,0x04,0x06,0x13,0x02,0x55,0x53,0x31,0x18,0x30,0x16,0x06,0x03,0x55,0x04,0x0A,0x13,0x0F,0x55,0x2E,0x53,0x2E,0x20,0x47,0x6F,0x76,0x65,0x72,0x6E,0x6D,0x65,0x6E,0x74,0x31,0x0C,0x30,0x0A,0x06,0x03,0x55,0x04,0x0B,0x13,0x03,0x44,0x6F,0x44,0x31,0x1A,0x30,0x18,
0x06,0x03,0x55,0x04,0x03,0x13,0x11,0x41,0x72,0x6D,0x65,0x64,0x20,0x46,0x6F,0x72,0x63,0x65,0x73,0x20,0x52,0x6F,0x6F,0x74,0x30,0x82,0x01,0xB6,0x30,0x82,0x01,0x2B,0x06,0x07,0x2A,0x86,0x48,0xCE,0x38,0x04,0x01,0x30,0x82,0x01,0x1E,0x02,0x81,0x81,0x00,0x90,0x89,0x3E,0x18,0x1B,0xFE,0xA3,0x1D,0x16,0x89,0x00,0xB4,0xD5,0x40,0x82,0x4C,0x2E,0xEC,0x3D,0x66,0x0D,0x0D,0xB9,0x17,0x40,0x6E,0x3A,0x5C,0x03,0x7B,0x1B,0x93,0x28,0x0C,0xEF,0xB9,0x97,0xE3,0xA1,0xEB,0xE2,0xA3,0x7C,0x61,0xDD,0x6F,0xD5,0xAD,0x15,0x69,0x00,
0x16,0xB2,0xC3,0x08,0x3D,0xC4,0x59,0xC6,0xF2,0x70,0xA5,0xB0,0xF5,0x1F,0x1D,0xF4,0xB0,0x15,0xDA,0x7E,0x28,0x39,0x24,0x99,0x36,0x5B,0xEC,0x39,0x25,0xFA,0x92,0x49,0x65,0xD2,0x43,0x05,0x6A,0x9E,0xA3,0x7B,0xF0,0xDE,0xA3,0x2F,0xD3,0x6F,0x3A,0xF9,0x35,0xC3,0x29,0xD4,0x45,0x6C,0x56,0x9A,0xDE,0x36,0x6E,0xFE,0x12,0x68,0x96,0x7B,0x45,0x1D,0x2C,0xFF,0xB9,0x2D,0xF5,0x52,0x8C,0xDF,0x3E,0x2F,0x63,0x02,0x15,0x00,0x81,0xA9,0xB5,0xD0,0x04,0xF2,0x9B,0xA7,0xD8,0x55,0x4C,0x3B,0x32,0xA1,0x45,0x32,0x4F,0xF5,0x51,0xDD,
new X509Certificate2 ().GetNameInfo ((X509NameType) Int32.MinValue, false);
}
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void Empty_GetNameInfo_SimpleName ()
+ {
+ new X509Certificate2 ().GetNameInfo (X509NameType.SimpleName, true);
+ }
+
[Test]
[ExpectedException (typeof (NullReferenceException))]
- public void Empty_GetNameInfo ()
+ public void Empty_GetNameInfo_DnsName ()
{
new X509Certificate2 ().GetNameInfo (X509NameType.DnsName, true);
}