From f150312eb33433a9787b404f2b87d1b3a48a9020 Mon Sep 17 00:00:00 2001 From: Gert Driesen Date: Mon, 7 Aug 2006 17:43:26 +0000 Subject: [PATCH] * System_test.dll.sources: Added X509Certificate2Test.cs. * X509Certificate2Test.cs: Added test for bug #78986. svn path=/trunk/mcs/; revision=63443 --- mcs/class/System/ChangeLog | 4 + mcs/class/System/System_test.dll.sources | 1 + .../ChangeLog | 4 + .../X509Certificate2Test.cs | 91 ++++++++++++++++++++++ 4 files changed, 100 insertions(+) create mode 100644 mcs/class/System/Test/System.Security.Cryptography.X509Certificates/X509Certificate2Test.cs diff --git a/mcs/class/System/ChangeLog b/mcs/class/System/ChangeLog index e7de759e53c..cbc4eb97f8b 100644 --- a/mcs/class/System/ChangeLog +++ b/mcs/class/System/ChangeLog @@ -1,3 +1,7 @@ +2006-08-07 Gert Driesen + + * System_test.dll.sources: Added X509Certificate2Test.cs. + 2006-07-14 Peter Dennis Bartok * System.dll.sources: Added System.ComponentModel/MaskedTextResultHint.cs diff --git a/mcs/class/System/System_test.dll.sources b/mcs/class/System/System_test.dll.sources index b0ba7b19653..55097bcaf1b 100644 --- a/mcs/class/System/System_test.dll.sources +++ b/mcs/class/System/System_test.dll.sources @@ -192,6 +192,7 @@ System.Security.Cryptography/OidTest.cs System.Security.Cryptography.X509Certificates/PublicKeyTest.cs System.Security.Cryptography.X509Certificates/X500DistinguishedNameTest.cs System.Security.Cryptography.X509Certificates/X509BasicConstraintsExtensionTest.cs +System.Security.Cryptography.X509Certificates/X509Certificate2Test.cs System.Security.Cryptography.X509Certificates/X509CertificateCollectionTest.cs System.Security.Cryptography.X509Certificates/X509ChainPolicyTest.cs System.Security.Cryptography.X509Certificates/X509ChainTest.cs diff --git a/mcs/class/System/Test/System.Security.Cryptography.X509Certificates/ChangeLog b/mcs/class/System/Test/System.Security.Cryptography.X509Certificates/ChangeLog index 4e35e999b19..7f30f4bd87c 100644 --- a/mcs/class/System/Test/System.Security.Cryptography.X509Certificates/ChangeLog +++ b/mcs/class/System/Test/System.Security.Cryptography.X509Certificates/ChangeLog @@ -1,3 +1,7 @@ +2006-08-07 Gert Driesen + + * X509Certificate2Test.cs: Added test for bug #78986. + 2006-04-25 Atsushi Enomoto * X509EnhancedKeyUsageExtensionTest.cs, diff --git a/mcs/class/System/Test/System.Security.Cryptography.X509Certificates/X509Certificate2Test.cs b/mcs/class/System/Test/System.Security.Cryptography.X509Certificates/X509Certificate2Test.cs new file mode 100644 index 00000000000..9c9de7646d1 --- /dev/null +++ b/mcs/class/System/Test/System.Security.Cryptography.X509Certificates/X509Certificate2Test.cs @@ -0,0 +1,91 @@ +// +// X509Certificate2Test.cs - NUnit Test Cases for +// System.Security.Cryptography.X509Certificates.X509Certificate2 +// +// Author: +// Gert Driesen +// +// 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 System; +using System.IO; +using System.Security; +using System.Security.Cryptography.X509Certificates; + +using NUnit.Framework; + +namespace MonoTests.System.Security.Cryptography.X509Certificates { + [TestFixture] + public class X509Certificate2Test + { + private static byte[] cert_a = { 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,0x05,0x00,0x03,0x5F,0x00,0x30,0x5C,0x02,0x55,0x2D,0x58,0xE9,0xBF,0xF0,0x31,0xCD,0x79,0x06,0x50,0x5A,0xD5,0x9E,0x0E,0x2C,0xE6,0xC2,0xF7,0xF9, + 0xD2,0xCE,0x55,0x64,0x85,0xB1,0x90,0x9A,0x92,0xB3,0x36,0xC1,0xBC,0xEA,0xC8,0x23,0xB7,0xAB,0x3A,0xA7,0x64,0x63,0x77,0x5F,0x84,0x22,0x8E,0xE5,0xB6,0x45,0xDD,0x46,0xAE,0x0A,0xDD,0x00,0xC2,0x1F,0xBA,0xD9,0xAD,0xC0,0x75,0x62,0xF8,0x95,0x82,0xA2,0x80,0xB1,0x82,0x69,0xFA,0xE1,0xAF,0x7F,0xBC,0x7D,0xE2,0x7C,0x76,0xD5,0xBC,0x2A,0x80,0xFB,0x02,0x03,0x01,0x00,0x01,0x30,0x0D,0x06,0x09,0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x02,0x05,0x00,0x03,0x7E,0x00,0x54,0x20,0x67,0x12,0xBB,0x66,0x14,0xC3,0x26,0x6B,0x7F, + 0xDA,0x4A,0x25,0x4D,0x8B,0xE0,0xFD,0x1E,0x53,0x6D,0xAC,0xA2,0xD0,0x89,0xB8,0x2E,0x90,0xA0,0x27,0x43,0xA4,0xEE,0x4A,0x26,0x86,0x40,0xFF,0xB8,0x72,0x8D,0x1E,0xE7,0xB7,0x77,0xDC,0x7D,0xD8,0x3F,0x3A,0x6E,0x55,0x10,0xA6,0x1D,0xB5,0x58,0xF2,0xF9,0x0F,0x2E,0xB4,0x10,0x55,0x48,0xDC,0x13,0x5F,0x0D,0x08,0x26,0x88,0xC9,0xAF,0x66,0xF2,0x2C,0x9C,0x6F,0x3D,0xC3,0x2B,0x69,0x28,0x89,0x40,0x6F,0x8F,0x35,0x3B,0x9E,0xF6,0x8E,0xF1,0x11,0x17,0xFB,0x0C,0x98,0x95,0xA1,0xC2,0xBA,0x89,0x48,0xEB,0xB4,0x06,0x6A,0x22,0x54, + 0xD7,0xBA,0x18,0x3A,0x48,0xA6,0xCB,0xC2,0xFD,0x20,0x57,0xBC,0x63,0x1C }; + + [Test] // bug #78986 + [Category ("NotWorking")] // ctors with password result in ArgumentException (invalid PFX version) + public void RawData_FromFile () + { + string tempFile = Path.GetTempFileName (); + try { + using (FileStream fs = File.OpenWrite (tempFile)) { + fs.Write (cert_a, 0, cert_a.Length); + fs.Close (); + } + + X509Certificate2 cert = new X509Certificate2(tempFile, "mono"); + Assert.IsNotNull (cert.RawData, "#A1"); + Assert.AreEqual (cert_a.Length, cert.RawData.Length, "#A2"); + Assert.AreEqual (cert_a, cert.RawData, "#A3"); + Assert.IsNotNull (cert.GetRawCertData(), "#A4"); + Assert.AreEqual (cert_a.Length, cert.GetRawCertData().Length, "#A5"); + Assert.AreEqual (cert_a, cert.GetRawCertData(), "#A6"); + + cert = new X509Certificate2(tempFile, new SecureString ()); + Assert.IsNotNull (cert.RawData, "#B1"); + Assert.AreEqual (cert_a.Length, cert.RawData.Length, "#B2"); + Assert.AreEqual (cert_a, cert.RawData, "#B3"); + Assert.IsNotNull (cert.GetRawCertData(), "#B4"); + Assert.AreEqual (cert_a.Length, cert.GetRawCertData().Length, "#B5"); + Assert.AreEqual (cert_a, cert.GetRawCertData(), "#B6"); + + cert = new X509Certificate2(tempFile); + Assert.IsNotNull (cert.RawData, "#C1"); + Assert.AreEqual (cert_a.Length, cert.RawData.Length, "#C2"); + Assert.AreEqual (cert_a, cert.RawData, "#C3"); + Assert.IsNotNull (cert.GetRawCertData(), "#C4"); + Assert.AreEqual (cert_a.Length, cert.GetRawCertData().Length, "#C5"); + Assert.AreEqual (cert_a, cert.GetRawCertData(), "#C6"); + } finally { + File.Delete (tempFile); + } + } + } +} + +#endif -- 2.11.4.GIT