diff options
author | Sebastien Pouliot <sebastien@ximian.com> | 2005-11-24 17:01:30 +0300 |
---|---|---|
committer | Sebastien Pouliot <sebastien@ximian.com> | 2005-11-24 17:01:30 +0300 |
commit | c37326ed14856a61f2c53530a772e46d85654a0f (patch) | |
tree | 5bde7e4273042142a374d418ff300730c04d242a /mcs/class | |
parent | cf50bd21d7f9940e6820aca0aa03e11c4e788676 (diff) |
2005-11-24 Sebastien Pouliot <sebastien@ximian.com>
* X500DistinguishedName.cs: Added validation (still missing parsing).
* X509Certificate2Enumerator.cs: Add missing IEnumerator.* methods.
svn path=/trunk/mcs/; revision=53454
Diffstat (limited to 'mcs/class')
3 files changed, 138 insertions, 8 deletions
diff --git a/mcs/class/System/System.Security.Cryptography.X509Certificates/ChangeLog b/mcs/class/System/System.Security.Cryptography.X509Certificates/ChangeLog index e6bdd73a3a1..7a100461ec1 100644 --- a/mcs/class/System/System.Security.Cryptography.X509Certificates/ChangeLog +++ b/mcs/class/System/System.Security.Cryptography.X509Certificates/ChangeLog @@ -1,3 +1,8 @@ +2005-11-24 Sebastien Pouliot <sebastien@ximian.com> + + * X500DistinguishedName.cs: Added validation (still missing parsing). + * X509Certificate2Enumerator.cs: Add missing IEnumerator.* methods. + 2005-11-22 Sebastien Pouliot <sebastien@ximian.com> * PublicKey.cs: Completed implementation for both RSA and DSA public diff --git a/mcs/class/System/System.Security.Cryptography.X509Certificates/X500DistinguishedName.cs b/mcs/class/System/System.Security.Cryptography.X509Certificates/X500DistinguishedName.cs index 0b2369471a4..1c5bdb399a1 100644 --- a/mcs/class/System/System.Security.Cryptography.X509Certificates/X500DistinguishedName.cs +++ b/mcs/class/System/System.Security.Cryptography.X509Certificates/X500DistinguishedName.cs @@ -4,7 +4,7 @@ // Author: // Sebastien Pouliot <sebastien@ximian.com> // -// Copyright (C) 2004 Novell Inc. (http://www.novell.com) +// Copyright (C) 2004-2005 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 @@ -28,56 +28,169 @@ #if NET_2_0 && SECURITY_DEP +using System.Collections; using System.Text; +using Mono.Security; using MX = Mono.Security.X509; namespace System.Security.Cryptography.X509Certificates { public sealed class X500DistinguishedName : AsnEncodedData { + private const X500DistinguishedNameFlags AllFlags = X500DistinguishedNameFlags.Reversed | + X500DistinguishedNameFlags.UseSemicolons | X500DistinguishedNameFlags.DoNotUsePlusSign | + X500DistinguishedNameFlags.DoNotUseQuotes | X500DistinguishedNameFlags.UseCommas | + X500DistinguishedNameFlags.UseNewLines | X500DistinguishedNameFlags.UseUTF8Encoding | + X500DistinguishedNameFlags.UseT61Encoding | X500DistinguishedNameFlags.ForceUTF8Encoding; + + private string name; + private ArrayList list; + [MonoTODO] public X500DistinguishedName (AsnEncodedData encodedDistinguishedName) { + if (encodedDistinguishedName == null) + throw new ArgumentNullException ("encodedDistinguishedName"); + RawData = encodedDistinguishedName.RawData; + DecodeRawData (); + name = Decode (X500DistinguishedNameFlags.None); } [MonoTODO] public X500DistinguishedName (byte[] encodedDistinguishedName) { + if (encodedDistinguishedName == null) + throw new ArgumentNullException ("encodedDistinguishedName"); + Oid = new Oid (); + RawData = encodedDistinguishedName; + DecodeRawData (); + name = Decode (X500DistinguishedNameFlags.None); } [MonoTODO] public X500DistinguishedName (string distinguishedName) { + if (distinguishedName == null) + throw new ArgumentNullException ("distinguishedName"); + + if (distinguishedName.Length == 0) { + // empty (0x00) ASN.1 sequence (0x30) + RawData = new byte [2] { 0x30, 0x00 }; + DecodeRawData (); + } else { + DecodeName (); + name = distinguishedName; + } } [MonoTODO] public X500DistinguishedName (string distinguishedName, X500DistinguishedNameFlags flag) { + if (distinguishedName == null) + throw new ArgumentNullException ("distinguishedName"); + if ((flag != 0) && ((flag & AllFlags) == 0)) + throw new ArgumentException ("flag"); + + if (distinguishedName.Length == 0) { + // empty (0x00) ASN.1 sequence (0x30) + RawData = new byte [2] { 0x30, 0x00 }; + DecodeRawData (); + } else { + DecodeName (); + name = distinguishedName; + } } [MonoTODO] public X500DistinguishedName (X500DistinguishedName distinguishedName) { + if (distinguishedName == null) + throw new ArgumentNullException ("distinguishedName"); + name = distinguishedName.name; + list = (ArrayList) distinguishedName.list.Clone (); } [MonoTODO] public string Name { - get { return null; } + get { return name; } } [MonoTODO] public string Decode (X500DistinguishedNameFlags flag) { - return null; + return String.Empty; } [MonoTODO] public override string Format (bool multiLine) { - return null; + if (list.Count == 0) + return String.Empty; + + StringBuilder sb = new StringBuilder (); + foreach (DictionaryEntry de in list) { + FormatEntry (sb, de, X500DistinguishedNameFlags.None); + if (multiLine) + sb.Append (Environment.NewLine); + } + if (multiLine) + sb.Append (Environment.NewLine); + return sb.ToString (); } + // private stuff + + private void FormatEntry (StringBuilder sb, DictionaryEntry de, X500DistinguishedNameFlags flag) + { + sb.Append (de.Key); + sb.Append ("="); + // needs quotes ? + } + + private string GetSeparator (X500DistinguishedNameFlags flag) + { + if ((flag & X500DistinguishedNameFlags.UseSemicolons) != 0) + return ";"; + if ((flag & X500DistinguishedNameFlags.UseCommas) != 0) + return ","; + if ((flag & X500DistinguishedNameFlags.UseNewLines) != 0) + return Environment.NewLine; + return ","; //default + } + + // decode the DN using the (byte[]) RawData + private void DecodeRawData () + { + list = new ArrayList (); + if ((RawData == null) || (RawData.Length < 3)) { + name = String.Empty; + return; + } + + ASN1 sequence = new ASN1 (RawData); + for (int i=0; i < sequence.Count; i++) { + } + } + + // decode the DN using the (string) name + private void DecodeName () + { + if ((name == null) || (name.Length == 0)) + return; + + ASN1 dn = MX.X501.FromString (name); + + int pos = 0; + ASN1 asn1 = new ASN1 (0x30); +/* while (pos < name.Length) { + MX.X520.AttributeTypeAndValue atv = ReadAttribute (name, ref pos); + atv.Value = ReadValue (name, ref pos); + }*/ + + RawData = dn.GetBytes (); + DecodeRawData (); + } } } diff --git a/mcs/class/System/System.Security.Cryptography.X509Certificates/X509Certificate2Enumerator.cs b/mcs/class/System/System.Security.Cryptography.X509Certificates/X509Certificate2Enumerator.cs index c22f45bdb33..a9363a01624 100644 --- a/mcs/class/System/System.Security.Cryptography.X509Certificates/X509Certificate2Enumerator.cs +++ b/mcs/class/System/System.Security.Cryptography.X509Certificates/X509Certificate2Enumerator.cs @@ -48,10 +48,6 @@ namespace System.Security.Cryptography.X509Certificates { get { return (X509Certificate2) enumerator.Current; } } - object IEnumerator.Current { - get { return enumerator.Current; } - } - // methods public bool MoveNext () @@ -63,6 +59,22 @@ namespace System.Security.Cryptography.X509Certificates { { enumerator.Reset (); } + + // IEnumerator + + object IEnumerator.Current { + get { return enumerator.Current; } + } + + bool IEnumerator.MoveNext () + { + return enumerator.MoveNext (); + } + + void IEnumerator.Reset () + { + enumerator.Reset (); + } } } |