[System] Oid from referencesource. Fixes #40646 and other incompabilities
authorMarek Safar <marek.safar@gmail.com>
Wed, 4 May 2016 21:59:22 +0000 (23:59 +0200)
committerMarek Safar <marek.safar@gmail.com>
Wed, 4 May 2016 21:59:22 +0000 (23:59 +0200)
mcs/class/System/ReferenceSources/CAPI.cs [new file with mode: 0644]
mcs/class/System/System.Security.Cryptography.X509Certificates/X509EnhancedKeyUsageExtension.cs
mcs/class/System/System.Security.Cryptography/AsnEncodedData.cs
mcs/class/System/System.Security.Cryptography/Oid.cs [deleted file]
mcs/class/System/System.Security.Cryptography/OidCollection.cs [deleted file]
mcs/class/System/System.Security.Cryptography/OidEnumerator.cs [deleted file]
mcs/class/System/System.Security.Cryptography/OidGroup.cs [deleted file]
mcs/class/System/System.dll.sources
mcs/class/System/Test/System.Security.Cryptography/OidTest.cs
mcs/class/System/mobile_System.dll.sources
mcs/class/referencesource/System/security/system/security/cryptography/x509/x509utils.cs

diff --git a/mcs/class/System/ReferenceSources/CAPI.cs b/mcs/class/System/ReferenceSources/CAPI.cs
new file mode 100644 (file)
index 0000000..28e1c47
--- /dev/null
@@ -0,0 +1,162 @@
+namespace System.Security.Cryptography {
+
+       static class CAPI {
+               // OID key type.
+               internal const uint CRYPT_OID_INFO_OID_KEY   = 1;
+               internal const uint CRYPT_OID_INFO_NAME_KEY  = 2;
+               internal const uint CRYPT_OID_INFO_ALGID_KEY = 3;
+               internal const uint CRYPT_OID_INFO_SIGN_KEY  = 4;
+
+               public static string CryptFindOIDInfoNameFromKey (string key, OidGroup oidGroup)
+               {
+                       // TODO: incomplete
+                       // TODO: oidGroup is ignored
+                       switch (key) {
+                       case "1.2.840.113549.1.1.5":
+                       case "1.3.14.3.2.29":
+                       case "1.3.14.3.2.15":
+                               return "sha1RSA";
+                       case "1.2.840.113549.1.1.4":
+                       case "1.3.14.3.2.3":
+                               return "md5RSA";
+                       case "1.2.840.10040.4.3":
+                       case "1.3.14.3.2.13":
+                               return "sha1DSA";
+                       case "1.2.840.113549.1.1.2":
+                       case "1.3.14.7.2.3.1":
+                               return "md2RSA";
+                       case "1.2.840.113549.1.1.3":
+                               return "md4RSA";
+                               return "md4RSA";
+                               return "md4RSA";
+                       case "1.3.14.3.2.27":
+                               return "dsaSHA1";
+                       case "2.16.840.1.101.2.1.1.19":
+                               return "mosaicUpdatedSig";
+                       case "1.3.14.3.2.26":
+                               return "sha1";
+                       case "1.2.840.113549.2.5":
+                               return "md5";
+                       case "2.16.840.1.101.3.4.2.1":
+                               return "sha256";
+                       case "2.16.840.1.101.3.4.2.2":
+                               return "sha384";
+                       case "2.16.840.1.101.3.4.2.3":
+                               return "sha512";
+                       case "1.2.840.113549.1.1.11":
+                               return "sha256RSA";
+                       case "1.2.840.113549.1.1.12":
+                               return "sha384RSA";
+                       case "1.2.840.113549.1.1.13":
+                               return "sha512RSA";
+                       case "1.2.840.113549.1.1.10":
+                               return "RSASSA-PSS";
+                       case "1.2.840.10045.4.1":
+                               return "sha1ECDSA";
+                       case "1.2.840.10045.4.3.2":
+                               return "sha256ECDSA";
+                       case "1.2.840.10045.4.3.3":
+                               return "sha384ECDSA";
+                       case "1.2.840.10045.4.3.4":
+                               return "sha512ECDSA";
+                       case "1.2.840.10045.4.3":
+                               return "specifiedECDSA";
+                       case "1.2.840.113549.1.1.1":
+                               return "RSA";
+                       case "1.2.840.113549.1.7.1":
+                               return "PKCS 7 Data";
+                       case "1.2.840.113549.1.9.3":
+                               return "Content Type";
+                       case "1.2.840.113549.1.9.4":
+                               return "Message Digest";
+                       case "1.2.840.113549.1.9.5":
+                               return "Signing Time";
+                       case "1.2.840.113549.3.7":
+                               return "3des";
+                       case "2.5.29.17":
+                               return "Subject Alternative Name";
+                       case "2.16.840.1.101.3.4.1.2":
+                               return "aes128";
+                       case "2.16.840.1.101.3.4.1.42":
+                               return "aes256";
+                       case "2.16.840.1.113730.1.1":
+                               return "Netscape Cert Type";
+                       }
+
+                       return null;
+               }
+
+               public static string CryptFindOIDInfoKeyFromName (string name, OidGroup oidGroup)
+               {
+                       // TODO: incomplete
+                       // TODO: oidGroup is ignored                    
+                       switch(name) {
+                       case "sha1RSA":
+                               return "1.2.840.113549.1.1.5";
+                       case "md5RSA":
+                               return "1.2.840.113549.1.1.4";
+                       case "sha1DSA":
+                               return "1.2.840.10040.4.3";
+                       case "shaRSA":
+                               return "1.3.14.3.2.29";
+                       case "md2RSA":
+                               return "1.2.840.113549.1.1.2";
+                       case "md4RSA":
+                               return "1.2.840.113549.1.1.3";
+                       case "dsaSHA1":
+                               return "1.3.14.3.2.27";
+                       case "mosaicUpdatedSig":
+                               return "2.16.840.1.101.2.1.1.19";
+                       case "sha1":
+                               return "1.3.14.3.2.26";
+                       case "md5":
+                               return "1.2.840.113549.2.5";
+                       case "sha256":
+                               return "2.16.840.1.101.3.4.2.1";
+                       case "sha384":
+                               return "2.16.840.1.101.3.4.2.2";
+                       case "sha512":
+                               return "2.16.840.1.101.3.4.2.3";
+                       case "sha256RSA":
+                               return "1.2.840.113549.1.1.11";
+                       case "sha384RSA":
+                               return "1.2.840.113549.1.1.12";
+                       case "sha512RSA":
+                               return "1.2.840.113549.1.1.13";
+                       case "RSASSA-PSS":
+                               return "1.2.840.113549.1.1.10";
+                       case "sha1ECDSA":
+                               return "1.2.840.10045.4.1";
+                       case "sha256ECDSA":
+                               return "1.2.840.10045.4.3.2";
+                       case "sha384ECDSA":
+                               return "1.2.840.10045.4.3.3";
+                       case "sha512ECDSA":
+                               return "1.2.840.10045.4.3.4";
+                       case "specifiedECDSA":
+                               return "1.2.840.10045.4.3";
+                       case "RSA":
+                               return "1.2.840.113549.1.1.1";
+                       case "PKCS 7 Data":
+                               return "1.2.840.113549.1.7.1";
+                       case "Content Type":
+                               return "1.2.840.113549.1.9.3";
+                       case "Message Digest":
+                               return "1.2.840.113549.1.9.4";
+                       case "Signing Time":
+                               return "1.2.840.113549.1.9.5";
+                       case "3des":
+                               return "1.2.840.113549.3.7";
+                       case "Subject Alternative Name":
+                               return "2.5.29.17";
+                       case "aes128":
+                               return "2.16.840.1.101.3.4.1.2";
+                       case "aes256":
+                               return "2.16.840.1.101.3.4.1.42";
+                       case "Netscape Cert Type":
+                               return "2.16.840.1.113730.1.1";
+                       }
+                       return null;
+               }
+       }
+}
\ No newline at end of file
index 92007a397d4fd040e8a65f134b55a5a4bbd91662..eeabf6905e3dcaab28bb514cde75d7419e5212ac 100644 (file)
@@ -70,7 +70,10 @@ namespace System.Security.Cryptography.X509Certificates {
 
                        _oid = new Oid (oid, friendlyName);
                        base.Critical = critical;
-                       _enhKeyUsage = enhancedKeyUsages.ReadOnlyCopy ();
+                       _enhKeyUsage = new OidCollection();
+                       foreach (Oid oid in enhancedKeyUsages) {
+                               _enhKeyUsage.Add(oid);
+                       }
                        RawData = Encode ();
                }
 
@@ -81,10 +84,14 @@ namespace System.Security.Cryptography.X509Certificates {
                                switch (_status) {
                                case AsnDecodeStatus.Ok:
                                case AsnDecodeStatus.InformationNotAvailable:
-                                       if (_enhKeyUsage == null)
-                                               _enhKeyUsage = new OidCollection ();
-                                       _enhKeyUsage.ReadOnly = true;
-                                       return _enhKeyUsage;
+
+                                       OidCollection oids = new OidCollection();
+                                       if (_enhKeyUsage != null) {
+                                               foreach(Oid oid in _enhKeyUsage) {
+                                                       oids.Add(oid);
+                                               }
+                                       }
+                                       return oids;
                                default:
                                        throw new CryptographicException ("Badly encoded extension.");
                                }
index 99860521102f983a62be9679c90bfa724b77610c..f6b45dd5e7ccd06af2833941fe3a4ce78bbe3771 100644 (file)
@@ -157,9 +157,9 @@ namespace System.Security.Cryptography {
                                return SubjectKeyIdentifierExtension (multiLine);
                        // other known objects (i.e. supported structure) - 
                        // but without any corresponding framework class
-                       case Oid.oidSubjectAltName:
+                       case "2.5.29.17": // oidSubjectAltName:
                                return SubjectAltName (multiLine);
-                       case Oid.oidNetscapeCertType:
+                       case "2.16.840.1.113730.1.1": // oidNetscapeCertType
                                return NetscapeCertType (multiLine);
                        default:
                                return Default (multiLine);
diff --git a/mcs/class/System/System.Security.Cryptography/Oid.cs b/mcs/class/System/System.Security.Cryptography/Oid.cs
deleted file mode 100644 (file)
index 7a1e785..0000000
+++ /dev/null
@@ -1,213 +0,0 @@
-//
-// Oid.cs - System.Security.Cryptography.Oid
-//
-// Author:
-//     Sebastien Pouliot  <sebastien@ximian.com>
-//
-// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-// Copyright (C) 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
-// "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 SECURITY_DEP
-
-using System.Security.Cryptography.X509Certificates;
-
-namespace System.Security.Cryptography {
-
-       public sealed class Oid {
-
-               private string _value;
-               private string _name;
-
-               // constructors
-
-               public Oid ()
-               {
-               }
-
-               public Oid (string oid) 
-               {
-                       if (oid == null)
-                               throw new ArgumentNullException ("oid");
-
-                       _value = oid;
-                       _name = GetName (oid);
-               }
-
-               public Oid (string value, string friendlyName)
-               {
-                       _value = value;
-                       _name = friendlyName;
-               }
-
-               public Oid (Oid oid) 
-               {
-                       if (oid == null)
-                               throw new ArgumentNullException ("oid");
-
-                       _value = oid.Value;
-                       _name = oid.FriendlyName;
-               }
-
-               // properties
-
-               public string FriendlyName {
-                       get { return _name; }
-                       set { 
-                               _name = value;
-                               _value = GetValue (_name);
-                       }
-               }
-
-               public string Value { 
-                       get { return _value; }
-                       set { 
-                               _value = value; 
-                               _name = GetName (_value);
-                       }
-               }
-
-               // internal stuff
-
-               // Known OID/Names not defined anywhere else (by OID order)
-               internal const string oidRSA = "1.2.840.113549.1.1.1";
-               internal const string nameRSA = "RSA";
-               internal const string oidPkcs7Data = "1.2.840.113549.1.7.1";
-               internal const string namePkcs7Data = "PKCS 7 Data";
-               internal const string oidPkcs9ContentType = "1.2.840.113549.1.9.3";
-               internal const string namePkcs9ContentType = "Content Type";
-               internal const string oidPkcs9MessageDigest = "1.2.840.113549.1.9.4";
-               internal const string namePkcs9MessageDigest = "Message Digest";
-               internal const string oidPkcs9SigningTime = "1.2.840.113549.1.9.5";
-               internal const string namePkcs9SigningTime = "Signing Time";
-               internal const string oidMd5 = "1.2.840.113549.2.5";
-               internal const string nameMd5 = "md5";
-               internal const string oid3Des = "1.2.840.113549.3.7";
-               internal const string name3Des = "3des";
-               internal const string oidSha1 = "1.3.14.3.2.26";
-               internal const string nameSha1 = "sha1";
-               internal const string oidSubjectAltName = "2.5.29.17";
-               internal const string nameSubjectAltName = "Subject Alternative Name";
-               internal const string oidAes128 = "2.16.840.1.101.3.4.1.2";
-               internal const string nameAes128 = "aes128";
-               internal const string oidAes256 = "2.16.840.1.101.3.4.1.42";
-               internal const string nameAes256 = "aes256";
-               internal const string oidSha256 = "2.16.840.1.101.3.4.2.1";
-               internal const string nameSha256 = "sha256";
-               internal const string oidSha512 = "2.16.840.1.101.3.4.2.3";
-               internal const string nameSha512 = "sha512";
-               internal const string oidNetscapeCertType = "2.16.840.1.113730.1.1";
-               internal const string nameNetscapeCertType = "Netscape Cert Type";
-
-               // TODO - find the complete list
-               private string GetName (string oid) 
-               {
-                       switch (oid) {
-                               case oidRSA:
-                                       return nameRSA;
-                               case oidPkcs7Data:
-                                       return namePkcs7Data;
-                               case oidPkcs9ContentType:
-                                       return namePkcs9ContentType;
-                               case oidPkcs9MessageDigest:
-                                       return namePkcs9MessageDigest;
-                               case oidPkcs9SigningTime:
-                                       return namePkcs9SigningTime;
-                               case oid3Des:
-                                       return name3Des;
-                               case X509BasicConstraintsExtension.oid:
-                                       return X509BasicConstraintsExtension.friendlyName;
-                               case X509KeyUsageExtension.oid:
-                                       return X509KeyUsageExtension.friendlyName;
-                               case X509EnhancedKeyUsageExtension.oid:
-                                       return X509EnhancedKeyUsageExtension.friendlyName;
-                               case X509SubjectKeyIdentifierExtension.oid:
-                                       return X509SubjectKeyIdentifierExtension.friendlyName;
-                               case oidSubjectAltName:
-                                       return nameSubjectAltName;
-                               case oidNetscapeCertType:
-                                       return nameNetscapeCertType;
-                               case oidMd5:
-                                       return nameMd5;
-                               case oidAes128:
-                                       return nameAes128;
-                               case oidAes256:
-                                       return nameAes256;
-                               case oidSha1:
-                                       return nameSha1;
-                               case oidSha256:
-                                       return nameSha256;
-                               case oidSha512:
-                                       return nameSha512;
-                               default:
-                                       return _name;
-                       }
-               }
-
-               // TODO - find the complete list
-               private string GetValue (string name) 
-               {
-                       switch (name) {
-                               case nameRSA:
-                                       return oidRSA;
-                               case namePkcs7Data:
-                                       return oidPkcs7Data;
-                               case namePkcs9ContentType:
-                                       return oidPkcs9ContentType;
-                               case namePkcs9MessageDigest:
-                                       return oidPkcs9MessageDigest;
-                               case namePkcs9SigningTime:
-                                       return oidPkcs9SigningTime;
-                               case name3Des:
-                                       return oid3Des;
-                               case X509BasicConstraintsExtension.friendlyName:
-                                       return X509BasicConstraintsExtension.oid;
-                               case X509KeyUsageExtension.friendlyName:
-                                       return X509KeyUsageExtension.oid;
-                               case X509EnhancedKeyUsageExtension.friendlyName:
-                                       return X509EnhancedKeyUsageExtension.oid;
-                               case X509SubjectKeyIdentifierExtension.friendlyName:
-                                       return X509SubjectKeyIdentifierExtension.oid;
-                               case nameSubjectAltName:
-                                       return oidSubjectAltName;
-                               case nameNetscapeCertType:
-                                       return oidNetscapeCertType;
-                               case nameMd5:
-                                       return oidMd5;
-                               case nameAes128:
-                                       return oidAes128;
-                               case nameAes256:
-                                       return oidAes256;
-                               case nameSha1:
-                                       return oidSha1;
-                               case nameSha256:
-                                       return oidSha256;
-                               case nameSha512:
-                                       return oidSha512;
-                               default:
-                                       return _value;
-                       }
-               }
-       }
-}
-
-#endif
diff --git a/mcs/class/System/System.Security.Cryptography/OidCollection.cs b/mcs/class/System/System.Security.Cryptography/OidCollection.cs
deleted file mode 100644 (file)
index 094582f..0000000
+++ /dev/null
@@ -1,124 +0,0 @@
-//
-// OidCollection.cs - System.Security.Cryptography.OidCollection
-//
-// Author:
-//     Sebastien Pouliot  <sebastien@ximian.com>
-//
-// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-// Copyright (C) 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
-// "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 SECURITY_DEP
-
-using System.Collections;
-
-namespace System.Security.Cryptography {
-
-       public sealed class OidCollection : ICollection, IEnumerable {
-
-               private ArrayList _list;
-               private bool _readOnly;
-
-               // constructors
-
-               public OidCollection ()
-               {
-                       _list = new ArrayList ();
-               }
-
-               // properties
-
-               public int Count {
-                       get { return _list.Count; }
-               }
-
-               public bool IsSynchronized {
-                       get { return _list.IsSynchronized; }
-               }
-
-               public Oid this [int index] {
-                       get { return (Oid) _list [index]; }
-               }
-
-               public Oid this [string oid] {
-                       get { 
-                               foreach (Oid o in _list) {
-                                       if (o.Value == oid)
-                                               return o;
-                               }
-                               return null; 
-                       }
-               }
-
-               public object SyncRoot {
-                       get { return _list.SyncRoot; }
-               }
-
-               // methods
-
-               public int Add (Oid oid)
-               {
-                       return (_readOnly ? 0 : _list.Add (oid));
-               }
-
-               public void CopyTo (Oid[] array, int index)
-               {
-                       _list.CopyTo ((Array)array, index);
-               }
-
-               // to satisfy ICollection - private
-               void ICollection.CopyTo (Array array, int index)
-               {
-                       _list.CopyTo (array, index);
-               }
-
-               public OidEnumerator GetEnumerator () 
-               {
-                       return new OidEnumerator (this);
-               }
-
-               // to satisfy IEnumerator - private
-               IEnumerator IEnumerable.GetEnumerator () 
-               {
-                       return new OidEnumerator (this);
-               }
-
-               // internal stuff
-
-               internal bool ReadOnly {
-                       get { return _readOnly; }
-                       set { _readOnly = value; }
-               }
-
-               internal OidCollection ReadOnlyCopy ()
-               {
-                       OidCollection copy = new OidCollection ();
-                       foreach (Oid oid in _list) {
-                               copy.Add (oid);
-                       }
-                       copy._readOnly = true;
-                       return copy;
-               }
-       }
-}
-
-#endif
diff --git a/mcs/class/System/System.Security.Cryptography/OidEnumerator.cs b/mcs/class/System/System.Security.Cryptography/OidEnumerator.cs
deleted file mode 100644 (file)
index cfd4214..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-//
-// OidEnumerator.cs - System.Security.Cryptography.OidEnumerator
-//
-// Author:
-//     Sebastien Pouliot (spouliot@motus.com)
-//
-// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-// Copyright (C) 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
-// "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 SECURITY_DEP
-
-using System.Collections;
-
-namespace System.Security.Cryptography {
-
-       // Note: Match the definition of framework version 1.2.3400.0 on http://longhorn.msdn.microsoft.com
-
-       public sealed class OidEnumerator : IEnumerator {
-
-               private OidCollection _collection;
-               private int _position;
-
-               // note: couldn't reuse the IEnumerator from ArrayList because 
-               // it doesn't throw the same exceptions
-               internal OidEnumerator (OidCollection collection) 
-               {
-                       _collection = collection;
-                       _position = -1;
-               }
-
-               // properties
-
-               public Oid Current {
-                       get {
-                               if (_position < 0)
-                                       throw new ArgumentOutOfRangeException ();
-                               return (Oid) _collection [_position];
-                       }
-               }
-
-               object IEnumerator.Current {
-                       get {
-                               if (_position < 0)
-                                       throw new ArgumentOutOfRangeException ();
-                               return _collection [_position];
-                       }
-               }
-
-               // methods
-
-               public bool MoveNext () 
-               {
-                       if (++_position < _collection.Count)
-                               return true;
-                       else {
-                               // strangely we must always be able to return the last entry 
-                               _position = _collection.Count - 1;
-                               return false;
-                       }
-               }
-
-               public void Reset () 
-               {
-                       _position = -1;
-               }
-       }
-}
-
-#endif
diff --git a/mcs/class/System/System.Security.Cryptography/OidGroup.cs b/mcs/class/System/System.Security.Cryptography/OidGroup.cs
deleted file mode 100644 (file)
index 55045d9..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-//
-// OidGroup.cs:
-//
-// Authors:
-//     Marek Safar  <marek.safar@gmail.com>
-//
-// Copyright (C) 2015 Xamarin Inc (http://www.xamarin.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.
-//
-
-namespace System.Security.Cryptography
-{
-       public enum OidGroup {
-               All                     = 0,
-               HashAlgorithm           = 1,
-               EncryptionAlgorithm     = 2,
-               PublicKeyAlgorithm      = 3,
-               SignatureAlgorithm      = 4,
-               Attribute               = 5,
-               ExtensionOrAttribute    = 6,
-               EnhancedKeyUsage        = 7,
-               Policy                  = 8,
-               Template                = 9,
-               KeyDerivationFunction   = 10
-       }
-}
index 68a9f89f88fabf5390bd19560ceafde970cd6e8a..d1f99dac40d99b38a49802faa450c1cc57e8ddac 100644 (file)
@@ -521,10 +521,6 @@ System.Security.Authentication.ExtendedProtection.Configuration/ServiceNameEleme
 System.Security.Cryptography/AsnEncodedDataCollection.cs
 System.Security.Cryptography/AsnEncodedData.cs
 System.Security.Cryptography/AsnEncodedDataEnumerator.cs
-System.Security.Cryptography/OidCollection.cs
-System.Security.Cryptography/Oid.cs
-System.Security.Cryptography/OidEnumerator.cs
-System.Security.Cryptography/OidGroup.cs
 System.Security.Cryptography.X509Certificates/OpenFlags.cs
 System.Security.Cryptography.X509Certificates/OSX509Certificates.cs
 System.Security.Cryptography.X509Certificates/PublicKey.cs
@@ -645,6 +641,7 @@ Mono.Net.Security/SystemCertificateValidator.cs
 ReferenceSources/AssertWrapper.cs
 ReferenceSources/BinaryCompatibility.cs
 ReferenceSources/ConfigurationManagerInternalFactory.cs
+ReferenceSources/CAPI.cs
 ReferenceSources/EnvironmentHelpers.cs
 ReferenceSources/Internal.cs
 ReferenceSources/HttpSysSettings.cs
@@ -1072,6 +1069,10 @@ ReferenceSources/_SslStream.cs
 ../referencesource/System/sys/system/threading/Barrier.cs
 ../referencesource/System/sys/system/windows/markup/ValueSerializerAttribute.cs
 
+../referencesource/System/security/system/security/cryptography/oid.cs
+
+../referencesource/System/security/system/security/cryptography/x509/x509utils.cs
+
 ../referencesource/System/security/system/security/permissions/typedescriptorpermission.cs
 
 ../referencesource/System/services/timers/system/timers/ElapsedEventHandler.cs
index 4aa40ff84e75af8e636bd9bfb6d4a4f106e85d8b..7179e186f33987fde7de157ab0cc31975c94b9e0 100644 (file)
@@ -36,7 +36,6 @@ using System.Security.Cryptography;
 namespace MonoTests.System.Security.Cryptography {
 
        [TestFixture]
-
        public class OidTest {
 
                static string invalidOid = "1.0";
@@ -97,7 +96,7 @@ namespace MonoTests.System.Security.Cryptography {
                public void ConstructorStringStringNull () 
                {
                        Oid o = new Oid (validOid, null);
-                       Assert.IsNull (o.FriendlyName, "FriendlyName");
+                       Assert.AreEqual ("RSA", o.FriendlyName, "FriendlyName");
                        Assert.AreEqual (validOid, o.Value, "Value");
                }
 
@@ -136,7 +135,7 @@ namespace MonoTests.System.Security.Cryptography {
                        Oid o = new Oid (validOid, invalidName);
                        Assert.AreEqual (invalidName, o.FriendlyName, "FriendlyName");
                        o.FriendlyName = null;
-                       Assert.IsNull (o.FriendlyName, "FriendlyName-Null");
+                       Assert.AreEqual ("RSA", o.FriendlyName, "FriendlyName-Null");
                }
 
                [Test]
@@ -212,8 +211,15 @@ namespace MonoTests.System.Security.Cryptography {
                        o.FriendlyName = "sha512";
                        Assert.AreEqual (o.Value, "2.16.840.1.101.3.4.2.3", "sha512 Value from FriendlyName");
 
+                       o = new Oid ("2.16.840.1.101.3.4.2.2");
+                       Assert.AreEqual ("2.16.840.1.101.3.4.2.2", o.Value, "sha384 Value");
+                       Assert.AreEqual ("sha384", o.FriendlyName, "sha384 FriendlyName");
+
+                       o = new Oid ("1.2.840.113549.1.1.12");
+                       Assert.AreEqual ("1.2.840.113549.1.1.12", o.Value, "sha384RSA Value");
+                       Assert.AreEqual ("sha384RSA", o.FriendlyName, "sha384RSA FriendlyName");
+
                        // TODO: add other well known oid as we find them
                }
        }
 }
-
index 4bb3791c6d412f070cd861899fa16ce814be4574..fde44350a2c67cb5ac395431eae6bb079743c619 100644 (file)
@@ -331,10 +331,6 @@ System.Security.Cryptography.X509Certificates/X509VerificationFlags.cs
 System.Security.Cryptography/AsnEncodedData.cs
 System.Security.Cryptography/AsnEncodedDataCollection.cs
 System.Security.Cryptography/AsnEncodedDataEnumerator.cs
-System.Security.Cryptography/Oid.cs
-System.Security.Cryptography/OidCollection.cs
-System.Security.Cryptography/OidEnumerator.cs
-System.Security.Cryptography/OidGroup.cs
 System.Threading/Semaphore.cs
 System.Threading/ThreadExceptionEventArgs.cs
 System.Threading/ThreadExceptionEventHandler.cs
@@ -376,6 +372,7 @@ Mono.Net.Security/NoReflectionHelper.cs
 Mono.Net.Security/SystemCertificateValidator.cs
 
 ReferenceSources/AssertWrapper.cs
+ReferenceSources/CAPI.cs
 ReferenceSources/EnvironmentHelpers.cs
 ReferenceSources/Internal.cs
 ReferenceSources/HttpSysSettings.cs
@@ -781,6 +778,10 @@ ReferenceSources/Win32Exception.cs
 
 ../referencesource/System/sys/system/threading/Barrier.cs
 
+../referencesource/System/security/system/security/cryptography/oid.cs
+
+../referencesource/System/security/system/security/cryptography/x509/x509utils.cs
+
 ../referencesource/System/security/system/security/permissions/typedescriptorpermission.cs
 
 ../referencesource/System/services/timers/system/timers/ElapsedEventHandler.cs
index 92fecf7812adb3acf330548b3ab483e8070d53ff..c5a093a1765a87ffbe3856cec3636fdc2d8cf76f 100644 (file)
@@ -23,7 +23,7 @@ namespace System.Security.Cryptography.X509Certificates {
 
     internal class X509Utils {
         private X509Utils () {}
-
+#if !MONO
         internal static bool IsCertRdnCharString (uint dwValueType) {
             return ((dwValueType & CAPI.CERT_RDN_TYPE_MASK) >= CAPI.CERT_RDN_NUMERIC_STRING);
         }
@@ -349,16 +349,26 @@ namespace System.Security.Cryptography.X509Certificates {
             CAPI.CRYPT_OID_INFO pOIDInfo = CAPI.CryptFindOIDInfo(CAPI.CRYPT_OID_INFO_OID_KEY, pszOid, 0);
             return pOIDInfo.Algid;
         }
-
+#endif
 #if FEATURE_CORESYSTEM
         [SecuritySafeCritical]
 #endif
-        internal static string FindOidInfo(uint keyType, string keyValue, OidGroup oidGroup) {
+        internal static string FindOidInfo(uint keyType, string keyValue, System.Security.Cryptography.OidGroup oidGroup) {
             if (keyValue == null)
                 throw new ArgumentNullException("keyValue");
             if (keyValue.Length == 0)
                 return null;
 
+#if MONO
+            switch(keyType) {
+                case CAPI.CRYPT_OID_INFO_OID_KEY:
+                    return CAPI.CryptFindOIDInfoNameFromKey(keyValue, oidGroup);
+                case CAPI.CRYPT_OID_INFO_NAME_KEY:
+                    return CAPI.CryptFindOIDInfoKeyFromName(keyValue, oidGroup);
+                default:
+                    throw new NotImplementedException(keyType.ToString());
+            }
+#else
             SafeLocalAllocHandle pvKey = SafeLocalAllocHandle.InvalidHandle;
 
             try {
@@ -389,21 +399,22 @@ namespace System.Security.Cryptography.X509Certificates {
             finally {
                 pvKey.Dispose();
             }
+#endif
         }
 
         // Try to find OID info within a specific group, and if that doesn't work fall back to all
         // groups for compatibility with previous frameworks
-        internal static string FindOidInfoWithFallback(uint key, string value, OidGroup group) {
+        internal static string FindOidInfoWithFallback(uint key, string value, System.Security.Cryptography.OidGroup group) {
             string info = FindOidInfo(key, value, group);
 
             // If we couldn't find it in the requested group, then try again in all groups
-            if (info == null && group != OidGroup.All) {
-                info = FindOidInfo(key, value, OidGroup.All);
+            if (info == null && group != System.Security.Cryptography.OidGroup.All) {
+                info = FindOidInfo(key, value, System.Security.Cryptography.OidGroup.All);
             }
 
             return info;
         }
-
+#if !MONO
         //
         // verify the passed keyValue is valid as per X.208
         //
@@ -568,5 +579,6 @@ error:
             else 
                 return SR.GetString(SR.Unknown_Error);
         }
+#endif
     }
 }