Many apologies for the mistakes! I appreciate the thoroughness and have hopefully not looked over any issues in this patch.

Regards,
David

Sebastien Pouliot wrote:
Hello David,

General note: Please review the Mono coding guidelines.
http://www.mono-project.com/Coding_Guidelines

E.g. use tabs not spaces, add a space before '('


diff -urN mono-1.9.1-old/mcs/class/Mono.Security/Mono.Security_test.dll.sources mono-1.9.1/mcs/class/Mono.Security/Mono.Security_test.dll.sources
--- mono-1.9.1-old/mcs/class/Mono.Security/Mono.Security_test.dll.sources	2007-11-08 17:34:20.000000000 -0500
+++ mono-1.9.1/mcs/class/Mono.Security/Mono.Security_test.dll.sources	2008-06-13 01:58:07.000000000 -0400
@@ -40,3 +40,4 @@
 Mono.Security.X509.Extensions/KeyUsageExtensionTest.cs
 Mono.Security.X509.Extensions/ExtendedKeyUsageExtensionTest.cs
 Mono.Security.X509.Extensions/BasicConstraintsExtensionTest.cs
+Mono.Security.X509.Extensions/SubjectAltNameTest.cs
diff -urN mono-1.9.1-old/mcs/class/Mono.Security/Mono.Security.X509/ChangeLog mono-1.9.1/mcs/class/Mono.Security/Mono.Security.X509/ChangeLog
--- mono-1.9.1-old/mcs/class/Mono.Security/Mono.Security.X509/ChangeLog	2007-11-08 17:34:18.000000000 -0500
+++ mono-1.9.1/mcs/class/Mono.Security/Mono.Security.X509/ChangeLog	2008-06-16 12:47:03.000000000 -0400
@@ -1,3 +1,8 @@
+2008-06-13  David Wolinsky  <[EMAIL PROTECTED]>
+
+	* X509CertificateBuilder.cs: Extensions is now writable so that it
+	can be added unto during run time.
+
 2007-05-09  Sebastien Pouliot  <[EMAIL PROTECTED]>
 
 	* PKCS12.cs: Adds SecretBag support. Patch by Jay Miller.
diff -urN mono-1.9.1-old/mcs/class/Mono.Security/Mono.Security.X509/X509CertificateBuilder.cs mono-1.9.1/mcs/class/Mono.Security/Mono.Security.X509/X509CertificateBuilder.cs
--- mono-1.9.1-old/mcs/class/Mono.Security/Mono.Security.X509/X509CertificateBuilder.cs	2007-11-08 17:34:18.000000000 -0500
+++ mono-1.9.1/mcs/class/Mono.Security/Mono.Security.X509/X509CertificateBuilder.cs	2008-06-16 12:45:25.000000000 -0400
@@ -136,6 +136,7 @@
 
 		public X509ExtensionCollection Extensions {
 			get { return extensions; }
+			set { extensions = value; }
 		}
 
 
diff -urN mono-1.9.1-old/mcs/class/Mono.Security/Mono.Security.X509.Extensions/ChangeLog mono-1.9.1/mcs/class/Mono.Security/Mono.Security.X509.Extensions/ChangeLog
--- mono-1.9.1-old/mcs/class/Mono.Security/Mono.Security.X509.Extensions/ChangeLog	2008-01-29 17:05:09.000000000 -0500
+++ mono-1.9.1/mcs/class/Mono.Security/Mono.Security.X509.Extensions/ChangeLog	2008-06-16 12:48:09.000000000 -0400
@@ -1,3 +1,9 @@
+2008-06-13  David Wolinsky  <[EMAIL PROTECTED]>
+	* SubjectAltName.cs: IP Addresses are handled and now this class
+	can be generated via the constructor from arrays.
+	* GeneralNames.cs: Added support to generate GeneralNames from
+	an arrays of strings.
+
 2007-12-14  Sebastien Pouliot  <[EMAIL PROTECTED]>
 
 	* AuthorityKeyIdentifierExtension.cs: Don't throw on what we don't
diff -urN mono-1.9.1-old/mcs/class/Mono.Security/Mono.Security.X509.Extensions/GeneralNames.cs mono-1.9.1/mcs/class/Mono.Security/Mono.Security.X509.Extensions/GeneralNames.cs
--- mono-1.9.1-old/mcs/class/Mono.Security/Mono.Security.X509.Extensions/GeneralNames.cs	2007-11-08 17:34:17.000000000 -0500
+++ mono-1.9.1/mcs/class/Mono.Security/Mono.Security.X509.Extensions/GeneralNames.cs	2008-06-16 12:51:08.000000000 -0400
@@ -72,11 +72,55 @@
 		private ArrayList directoryNames;
 		private ArrayList uris;
 		private ArrayList ipAddr;
+		private ASN1 asn;
 
 		public GeneralNames ()
 		{
 		}
 
+		public GeneralNames (string[] rfc822s, string[] dnsNames, string[] ipAddresses, string[] uris)
+		{
+			// This is an extension
+			asn = new ASN1 (0x30);
+
+			if (rfc822s != null) {
+				rfc822Name = new ArrayList ();
+				foreach (string rfc822 in rfc822s) {
+					asn.Add (new ASN1 (0x81, Encoding.ASCII.GetBytes (rfc822)));
+					rfc822Name.Add (rfc822s);
+				}
+			}
+
+			if (dnsNames != null) {
+				dnsName = new ArrayList ();
+				foreach (string dnsname in dnsNames) {
+					asn.Add (new ASN1 (0x82, Encoding.ASCII.GetBytes (dnsname)));
+					dnsName.Add(dnsname);
+				}
+			}
+
+			if (ipAddresses != null) {
+				ipAddr = new ArrayList ();
+				foreach (string ipaddress in ipAddresses) {
+					string[] parts = ipaddress.Split ('.', ':');
+					byte[] bytes = new byte[parts.Length];
+					for (int i = 0; i < parts.Length; i++) {
+						bytes[i] = Byte.Parse (parts[i]);
+					}
+					asn.Add (new ASN1 (0x87, bytes));
+					ipAddr.Add (ipaddress);
+				}
+			}
+
+			if (uris != null) {
+				this.uris = new ArrayList();
+				foreach (string uri in uris) {
+					asn.Add (new ASN1 (0x86, Encoding.ASCII.GetBytes (uri)));
+					this.uris.Add (uri);
+				}
+			}
+		}
+
 		public GeneralNames (ASN1 sequence)
 		{
 			for (int i = 0; i < sequence.Count; i++) {
@@ -105,7 +149,17 @@
 				case 0x87: // iPAddress				[7]     OCTET STRING
 					if (ipAddr == null)
 						ipAddr = new ArrayList ();
-					// TODO - Must find sample certificates
+					byte[] bytes = sequence[i].Value;
+					string space = (bytes.Length == 4) ? "." : ":";
+					StringBuilder sb = new StringBuilder();
+					for (int j = 0; j < bytes.Length; j++) {
+						sb.Append (bytes[j].ToString ());
+						if (j < bytes.Length - 1)
+							sb.Append (space); 
+					}
+					ipAddr.Add (sb.ToString());
+					if (ipAddr == null)
+						ipAddr = new ArrayList ();
 					break;
 				default:
 					break;
@@ -145,7 +199,6 @@
 			}
 		}
 
-		// Incomplete support
 		public string[] IPAddresses {
 			get {
 				if (ipAddr == null)
@@ -154,6 +207,11 @@
 			}
 		}
 
+		public byte[] GetBytes ()
+		{
+			return asn.GetBytes ();
+		}
+
 		public override string ToString ()
 		{
 			StringBuilder sb = new StringBuilder ();
diff -urN mono-1.9.1-old/mcs/class/Mono.Security/Mono.Security.X509.Extensions/SubjectAltNameExtension.cs mono-1.9.1/mcs/class/Mono.Security/Mono.Security.X509.Extensions/SubjectAltNameExtension.cs
--- mono-1.9.1-old/mcs/class/Mono.Security/Mono.Security.X509.Extensions/SubjectAltNameExtension.cs	2007-11-08 17:34:17.000000000 -0500
+++ mono-1.9.1/mcs/class/Mono.Security/Mono.Security.X509.Extensions/SubjectAltNameExtension.cs	2008-06-16 12:51:03.000000000 -0400
@@ -67,9 +67,9 @@
 	 * }
 	 */
 
-	// TODO - incomplete (only rfc822Name, dNSName are supported)
+	// TODO: Directories not supported
 	public class SubjectAltNameExtension : X509Extension {
-		
+
 		private GeneralNames _names;
 
 		public SubjectAltNameExtension ()
@@ -88,6 +88,16 @@
 		{
 		}
 
+		public SubjectAltNameExtension (string[] rfc822, string[] dnsNames,
+				string[] ipAddresses, string[] uris)
+		{
+			_names = new GeneralNames(rfc822, dnsNames, ipAddresses, uris);
+			// 0x04 for string decoding and then the General Names!
+			extnValue = new ASN1 (0x04, _names.GetBytes());
+			extnOid = "2.5.29.17";
+		//	extnCritical = true;
+		}
+
 		protected override void Decode () 
 		{
 			ASN1 sequence = new ASN1 (extnValue.Value);
@@ -108,11 +118,14 @@
 			get { return _names.DNSNames; }
 		}
 
-		// Incomplete support
 		public string[] IPAddresses {
 			get { return _names.IPAddresses; }
 		}
 
+		public string[] UniformResourceIdentifiers {
+			get { return _names.UniformResourceIdentifiers; }
+		}
+
 		public override string ToString () 
 		{
 			return _names.ToString ();
diff -urN mono-1.9.1-old/mcs/class/Mono.Security/Test/Mono.Security.X509.Extensions/SubjectAltNameTest.cs mono-1.9.1/mcs/class/Mono.Security/Test/Mono.Security.X509.Extensions/SubjectAltNameTest.cs
--- mono-1.9.1-old/mcs/class/Mono.Security/Test/Mono.Security.X509.Extensions/SubjectAltNameTest.cs	1969-12-31 19:00:00.000000000 -0500
+++ mono-1.9.1/mcs/class/Mono.Security/Test/Mono.Security.X509.Extensions/SubjectAltNameTest.cs	2008-06-16 12:55:16.000000000 -0400
@@ -0,0 +1,97 @@
+//
+//	SubjectAltNameTest.cs - NUnit Test Cases for 
+//	Mono.Security.X509.Extensions.SubjectAltName
+//
+// Authors:
+//	David Wolinsky <[EMAIL PROTECTED]>
+//
+// Copyright  (C) 2008 
+//
+
+//
+// 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.
+//
+
+using System;
+using System.Collections;
+using System.Security.Cryptography;
+using System.IO;
+
+using Mono.Security;
+using Mono.Security.X509;
+using Mono.Security.X509.Extensions;
+
+using NUnit.Framework;
+
+namespace MonoTests.Mono.Security.X509.Extensions {
+
+	[TestFixture]
+	public class SubjectAltNameTest {
+
+		[Test]
+		public void SubjectAltNameGenerator ()
+		{
+			RSACryptoServiceProvider rsa = new RSACryptoServiceProvider ();
+			X509CertificateBuilder x509 = new X509CertificateBuilder ();
+			x509.IssuerName = "C=ZA, ST=Western Cape, L=Cape Town, O=Thawte Consulting cc, OU=Certification Services Division, CN=Thawte Server";
+			x509.NotAfter = DateTime.MaxValue;
+			x509.NotBefore = DateTime.MinValue;
+			x509.SubjectName = "C=US, ST=Maryland, L=Pasadena, O=Brent Baccala, OU=FreeSoft, CN=www.freesoft.org";
+			x509.SerialNumber = new byte[] {12, 34, 56, 78, 90};
+			x509.Version = 3;
+			x509.SubjectPublicKey = rsa;
+
+			string[] dns = new string[2];
+			dns[0] = "one";
+			dns[1] = "two";
+      string[] uris = new string[3];
+			uris[0] = "one:two://three";
+			uris[1] = "Here:I:AM://12345";
+			uris[2] = "last:one";
+			SubjectAltNameExtension sane = new SubjectAltNameExtension (null, dns, null, uris);
+			x509.Extensions = new X509ExtensionCollection ();
+			x509.Extensions.Add (sane);
+			byte[] data = x509.Sign (rsa);
+
+			X509Certificate x509_loaded = new X509Certificate (data);
+			SubjectAltNameExtension	sane_test = new SubjectAltNameExtension (x509_loaded.Extensions[0]);
+			Assert.AreEqual (sane_test.RFC822.Length, 0, "RFC822 count");
+			Assert.AreEqual (sane_test.DNSNames.Length, 2, "DNSName count");
+			Assert.AreEqual (sane_test.IPAddresses.Length, 0, "IPAddresses count");
+			Assert.AreEqual (sane_test.UniformResourceIdentifiers.Length, 3, "URI Count");
+			Assert.AreEqual (sane_test.DNSNames[1], "two", "DNSName test");
+			Assert.AreEqual (sane_test.UniformResourceIdentifiers[2], "last:one", "URI Test");
+		}
+
+		[Test]
+		public void ThirdPartyCertificateParse  ()
+		{
+      byte[] certificate_with_ip_subjectaltname = new byte[] {0x30, 0x82, 0x02, 0x78, 0x30, 0x82, 0x01, 0xE1, 0xA0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x09, 0x00, 0xEE, 0xF3, 0xC0, 0x32, 0x13, 0x12, 0x66, 0x06, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x78, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x41, 0x55, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x0A, 0x53, 0x6F, 0x6D, 0x65, 0x2D, 0x53, 0x74, 0x61, 0x74, 0x65, 0x31, 0x21, 0x30, 0x1F, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x13, 0x18, 0x49, 0x6E, 0x74, 0x65, 0x72, 0x6E, 0x65, 0x74, 0x20, 0x57, 0x69, 0x64, 0x67, 0x69, 0x74, 0x73, 0x20, 0x50, 0x74, 0x79, 0x20, 0x4C, 0x74, 0x64, 0x31, 0x0D, 0x30, 0x0B, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x04, 0x6E, 0x6F, 0x6E, 0x65, 0x31, 0x0D, 0x30, 0x0B, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x04, 0x6E, 0x6F, 0x6E, 0x65, 0x31, 0x13, 0x30, 0x11, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x01, 0x16, 0x04, 0x6E, 0x6F, 0x6E, 0x65, 0x30, 0x1E, 0x17, 0x0D, 0x30, 0x38, 0x30, 0x36, 0x31, 0x33, 0x30, 0x34, 0x35, 0x39, 0x34, 0x36, 0x5A, 0x17, 0x0D, 0x30, 0x39, 0x30, 0x36, 0x31, 0x33, 0x30, 0x34, 0x35, 0x39, 0x34, 0x36, 0x5A, 0x30, 0x6F, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x41, 0x55, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x0A, 0x53, 0x6F, 0x6D, 0x65, 0x2D, 0x53, 0x74, 0x61, 0x74, 0x65, 0x31, 0x21, 0x30, 0x1F, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x13, 0x18, 0x49, 0x6E, 0x74, 0x65, 0x72, 0x6E, 0x65, 0x74, 0x20, 0x57, 0x69, 0x64, 0x67, 0x69, 0x74, 0x73, 0x20, 0x50, 0x74, 0x79, 0x20, 0x4C, 0x74, 0x64, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x01, 0x61, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x61, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x01, 0x16, 0x01, 0x61, 0x30, 0x81, 0x9F, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81, 0x8D, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xA6, 0xD2, 0x03, 0x5D, 0x91, 0x3D, 0xF3, 0x04, 0x4F, 0xB9, 0xF0, 0xE6, 0x40, 0xD0, 0x4E, 0xDF, 0xF7, 0xCE, 0x35, 0x87, 0xC1, 0x95, 0xEA, 0xFD, 0xDF, 0x44, 0x46, 0x20, 0xE4, 0xAF, 0x69, 0xC8, 0x1C, 0xF1, 0x06, 0x6C, 0x46, 0x20, 0x4D, 0xAA, 0xCC, 0x86, 0x40, 0xBB, 0x79, 0xF8, 0x71, 0x22, 0x87, 0x65, 0xBD, 0x20, 0x1D, 0xAD, 0xC6, 0xB0, 0x7C, 0x17, 0xE6, 0x57, 0xE4, 0x3C, 0x55, 0xD7, 0x7C, 0x8A, 0x98, 0xA2, 0xCD, 0x22, 0x85, 0x0E, 0xA2, 0x90, 0x18, 0x44, 0xA9, 0x7F, 0xA6, 0xD8, 0xDB, 0x6D, 0x09, 0x6D, 0x48, 0x6D, 0xD0, 0xDF, 0x94, 0xBF, 0x3B, 0xE5, 0xDA, 0x5F, 0xA2, 0x6F, 0x3C, 0xE5, 0xCE, 0x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0xE5, 0x77, 0x12, 0xCB, 0xBE, 0xBB, 0x0F, 0x50, 0x5A, 0x14, 0x3B, 0xA7, 0x86, 0x15, 0x5C, 0x61, 0x0A};
+
+			X509Certificate cert = new X509Certificate (certificate_with_ip_subjectaltname);
+			SubjectAltNameExtension	sane_test = new SubjectAltNameExtension (cert.Extensions[0]);
+			Assert.AreEqual (sane_test.RFC822.Length, 0, "RFC822 count");
+			Assert.AreEqual (sane_test.DNSNames.Length, 0, "DNSName count");
+			Assert.AreEqual (sane_test.IPAddresses.Length, 1, "IPAddresses count");
+			Assert.AreEqual (sane_test.UniformResourceIdentifiers.Length, 0, "URI Count");
+			Assert.AreEqual (sane_test.IPAddresses[0], "192.168.111.111", "IPAddress Test");
+		}
+	}
+}
_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list

Reply via email to