Exemple #1
0
		void m_initialize(OidCollection applicationPolicies, Boolean critical) {
			Oid = _oid;
			Critical = critical;
			List<Byte> rawData = new List<Byte>();
			foreach (Oid aoid in applicationPolicies.Cast<Oid>().Where(aoid => !String.IsNullOrEmpty(aoid.Value))) {
				_oids.Add(aoid);
				rawData.AddRange(Asn1Utils.Encode(Asn1Utils.EncodeObjectIdentifier(aoid), 48));
			}
			RawData = Asn1Utils.Encode(rawData.ToArray(), 48);
		}
Exemple #2
0
        /// <summary>
        /// Adapted from .NET source <see cref="System.Security.Cryptography.X509Certificates.X509Utils.CopyOidsToUnmanagedMemory"/>
        /// </summary>
        private static SafeLocalAllocHandle CopyOidsToUnmanagedMemory(OidCollection oids)
        {
            SafeLocalAllocHandle safeLocalAllocHandle = SafeLocalAllocHandle.InvalidHandle;

            if (oids == null || oids.Count == 0)
            {
                return(safeLocalAllocHandle);
            }

            // Copy the oid strings to a local list to prevent a security race condition where
            // the OidCollection or individual oids can be modified by another thread and
            // potentially cause a buffer overflow
            List <string> oidStrs = oids.Cast <Oid>().Select(oid => oid.Value).ToList();

            IntPtr pOid = IntPtr.Zero;

            // Needs to be checked to avoid having large sets of oids overflow the sizes and allow
            // a potential buffer overflow
            checked
            {
                int ptrSize = oidStrs.Count * Marshal.SizeOf(typeof(IntPtr));
                int oidSize = oidStrs.Sum(oidStr => oidStr.Length + 1);
                safeLocalAllocHandle = NativeMethods.LocalAlloc(NativeMethods.LPTR, new IntPtr((uint)ptrSize + (uint)oidSize));
                pOid = new IntPtr((long)safeLocalAllocHandle.DangerousGetHandle() + ptrSize);
            }

            for (int index = 0; index < oidStrs.Count; index++)
            {
                Marshal.WriteIntPtr(new IntPtr((long)safeLocalAllocHandle.DangerousGetHandle() + index * Marshal.SizeOf(typeof(IntPtr))), pOid);
                byte[] ansiOid = Encoding.ASCII.GetBytes(oidStrs[index]);
                Marshal.Copy(ansiOid, 0, pOid, ansiOid.Length);
                pOid = new IntPtr((long)pOid + oidStrs[index].Length + 1);
            }

            return(safeLocalAllocHandle);
        }
Exemple #3
0
 public static Boolean Contains2(this OidCollection collection, Oid value)
 {
     return(collection.Cast <Oid>().Any(x => x.Value == value.Value));
 }