[Mono-dev] patch for X509Certificate
Sebastien Pouliot
sebastien.pouliot at gmail.com
Mon Jul 31 08:31:03 EDT 2006
Hello Atsushi,
On Mon, 2006-07-31 at 16:50 +0900, Atsushi Eno wrote:
> Hello,
>
> I have some X509Certificate fixes for constructors and Equals(),
Looks fine :)
Please move the new tests, in X509CertificateTest.cs, between the "NON
GENERATED CODE" comments (near the start of the file) in case I
regenerate the file someday.
> attached (ChangeLog inclusive). Please review it.
and update the dates in the ChangeLog entries.
Thanks
Sebastien
>
> Atsushi Eno
> plain text document attachment (x509-cert-fixes.patch)
> Index: System.Security.Cryptography.X509Certificates/ChangeLog
> ===================================================================
> --- System.Security.Cryptography.X509Certificates/ChangeLog (revision 63029)
> +++ System.Security.Cryptography.X509Certificates/ChangeLog (working copy)
> @@ -1,3 +1,11 @@
> +2006-03-31 Atsushi Enomoto <atsushi at ximian.com>
> +
> + * X509Certificate.cs :
> + In 2.0 IntPtr constructor reject IntPtr.Zero as invalid handle.
> + In 2.0 copy constructor rejects null argument.
> + Equals() should return false if the argument cert is null.
> + Also if both x509 and raw data are null it caused NRE.
> +
> 2005-11-09 Sebastien Pouliot <sebastien at ximian.com>
>
> * X509ContentType.cs: Removed extra [Serializable] (2.0).
> Index: System.Security.Cryptography.X509Certificates/X509Certificate.cs
> ===================================================================
> --- System.Security.Cryptography.X509Certificates/X509Certificate.cs (revision 63029)
> +++ System.Security.Cryptography.X509Certificates/X509Certificate.cs (working copy)
> @@ -160,11 +160,20 @@
> Marshal.Copy (cc.pbCertEncoded, data, 0, (int)cc.cbCertEncoded);
> x509 = new Mono.Security.X509.X509Certificate (data);
> }
> +#if NET_2_0
> + else
> + throw new ArgumentException ("Invalid handle.");
> +#endif
> // IntPtr.Zero results in an "empty" certificate instance
> }
>
> public X509Certificate (System.Security.Cryptography.X509Certificates.X509Certificate cert)
> {
> +#if NET_2_0
> + if (cert == null)
> + throw new ArgumentNullException ();
> +#endif
> +
> if (cert != null) {
> byte[] data = cert.GetRawCertData ();
> if (data != null)
> @@ -262,7 +271,9 @@
> return false;
> }
> }
> - return (x509.RawData == null);
> + else
> + return false;
> + return x509 == null || (x509.RawData == null);
> }
>
> // LAMESPEC: This is the equivalent of the "thumbprint" that can be seen
> Index: Test/System.Security.Cryptography.X509Certificates/X509CapiTest.cs
> ===================================================================
> --- Test/System.Security.Cryptography.X509Certificates/X509CapiTest.cs (revision 63029)
> +++ Test/System.Security.Cryptography.X509Certificates/X509CapiTest.cs (working copy)
> @@ -157,6 +157,9 @@
> }
>
> [Test]
> +#if NET_2_0
> + [ExpectedException (typeof (ArgumentException))]
> +#endif
> public void ConstructorIntPtrZero ()
> {
> X509Certificate spc = new X509Certificate (IntPtr.Zero);
> Index: Test/System.Security.Cryptography.X509Certificates/ChangeLog
> ===================================================================
> --- Test/System.Security.Cryptography.X509Certificates/ChangeLog (revision 63029)
> +++ Test/System.Security.Cryptography.X509Certificates/ChangeLog (working copy)
> @@ -1,3 +1,9 @@
> +2006-03-31 Atsushi Enomoto <atsushi at ximian.com>
> +
> + * X509CapiTest.cs : ConstructorIntPtrZero() is valid only under 1.x.
> + * X509CertificateTest.cs :
> + Added tests for equality and null certificate constructor.
> +
> 2005-09-25 Sebastien Pouliot <sebastien at ximian.com>
>
> * X509CapiTest.cs: Update the test cases as the 1.x date/time bug
> Index: Test/System.Security.Cryptography.X509Certificates/X509CertificateTest.cs
> ===================================================================
> --- Test/System.Security.Cryptography.X509Certificates/X509CertificateTest.cs (revision 63029)
> +++ Test/System.Security.Cryptography.X509Certificates/X509CertificateTest.cs (working copy)
> @@ -973,7 +973,37 @@
> //Assertion.AssertEquals ("ToString(true)", tsa, x509.ToString (true));
> }
>
> +[Test]
> +public void Equality ()
> +{
> + // copy from Certificate1()
> + byte[] cert = { 0x30,0x82,0x01,0xFF,0x30,0x82,0x01,0x6C,0x02,0x05,0x02,0x72,0x00,0x06,0xE8,0x30,0x0D,0x06,0x09,0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x02,0x05,0x00,0x30,0x5F,0x31,0x0B,0x30,0x09,0x06,0x03,0x55,0x04,0x06,0x13,0x02,0x55,0x53,0x31,0x20,0x30,0x1E,0x06,0x03,0x55,0x04,0x0A,0x13,0x17,0x52,0x53,0x41,0x20,0x44,0x61,0x74,0x61,0x20,0x53,0x65,0x63,0x75,0x72,0x69,0x74,0x79,0x2C,0x20,0x49,0x6E,0x63,0x2E,0x31,0x2E,0x30,0x2C,0x06,0x03,0x55,0x04,0x0B,0x13,0x25,0x53,0x65,0x63,0x75,0x72,0x65,0x20,0x53,0x65,0x72,0x76,
> + 0x65,0x72,0x20,0x43,0x65,0x72,0x74,0x69,0x66,0x69,0x63,0x61,0x74,0x69,0x6F,0x6E,0x20,0x41,0x75,0x74,0x68,0x6F,0x72,0x69,0x74,0x79,0x30,0x1E,0x17,0x0D,0x39,0x36,0x30,0x33,0x31,0x32,0x31,0x38,0x33,0x38,0x34,0x37,0x5A,0x17,0x0D,0x39,0x37,0x30,0x33,0x31,0x32,0x31,0x38,0x33,0x38,0x34,0x36,0x5A,0x30,0x61,0x31,0x0B,0x30,0x09,0x06,0x03,0x55,0x04,0x06,0x13,0x02,0x55,0x53,0x31,0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x08,0x13,0x0A,0x43,0x61,0x6C,0x69,0x66,0x6F,0x72,0x6E,0x69,0x61,0x31,0x14,0x30,0x12,0x06,0x03,
> + 0x55,0x04,0x0A,0x13,0x0B,0x43,0x6F,0x6D,0x6D,0x65,0x72,0x63,0x65,0x4E,0x65,0x74,0x31,0x27,0x30,0x25,0x06,0x03,0x55,0x04,0x0B,0x13,0x1E,0x53,0x65,0x72,0x76,0x65,0x72,0x20,0x43,0x65,0x72,0x74,0x69,0x66,0x69,0x63,0x61,0x74,0x69,0x6F,0x6E,0x20,0x41,0x75,0x74,0x68,0x6F,0x72,0x69,0x74,0x79,0x30,0x70,0x30,0x0D,0x06,0x09,0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x01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,0xEB,0xB4,0x06,0x6A,0x22,0x54,
> + 0xD7,0xBA,0x18,0x3A,0x48,0xA6,0xCB,0xC2,0xFD,0x20,0x57,0xBC,0x63,0x1C };
>
> + X509Certificate x509 = new X509Certificate (cert);
> + Assert.IsFalse (x509.Equals (null), "#1");
> +
> +#if !NET_2_0
> + X509Certificate nullobj = new X509Certificate (IntPtr.Zero);
> + Assert.IsFalse (x509.Equals (nullobj), "#2");
> + Assert.IsFalse (nullobj.Equals (null), "#3");
> + Assert.IsFalse (nullobj.Equals (x509), "#4");
> +#endif
> +}
> +
> +[Test]
> +#if NET_2_0
> +[ExpectedException (typeof (ArgumentNullException))]
> +#endif
> +public void ConstructorX509CertificateNull ()
> +{
> + X509Certificate nullcopy = new X509Certificate ((X509Certificate) null);
> +}
> +
> // Number of certificates: 12
> // Number of invalid certificates: 1
> }
More information about the Mono-devel-list
mailing list