private T GetTokenInformation <T>(TokenInformationClass tokenInformationClass) where T : struct
 {
     using (SafeLocalAllocHandle handle = GetTokenInformation(this.m_safeTokenHandle, tokenInformationClass))
     {
         return(handle.Read <T>(0L));
     }
 }
 private static Win32Native.LUID GetLogonAuthId(SafeTokenHandle safeTokenHandle)
 {
     using (SafeLocalAllocHandle handle = GetTokenInformation(safeTokenHandle, TokenInformationClass.TokenStatistics))
     {
         return(handle.Read <Win32Native.TOKEN_STATISTICS>(0L).AuthenticationId);
     }
 }
예제 #3
0
 private static Interop.LUID GetLogonAuthId(SafeAccessTokenHandle safeTokenHandle)
 {
     using (SafeLocalAllocHandle pStatistics = GetTokenInformation(safeTokenHandle, TokenInformationClass.TokenStatistics))
     {
         Interop.TOKEN_STATISTICS statistics = pStatistics.Read <Interop.TOKEN_STATISTICS>(0);
         return(statistics.AuthenticationId);
     }
 }
예제 #4
0
        /// <summary>
        ///   Get a property from the current token
        /// </summary>

        private T GetTokenInformation <T>(TokenInformationClass tokenInformationClass) where T : struct
        {
            Debug.Assert(!_safeTokenHandle.IsInvalid && !_safeTokenHandle.IsClosed, "!m_safeTokenHandle.IsInvalid && !m_safeTokenHandle.IsClosed");

            using (SafeLocalAllocHandle information = GetTokenInformation(_safeTokenHandle, tokenInformationClass))
            {
                Debug.Assert(information.ByteLength >= (ulong)Marshal.SizeOf <T>(),
                             "information.ByteLength >= (ulong)Marshal.SizeOf(typeof(T))");

                return(information.Read <T>(0));
            }
        }
예제 #5
0
        public static IList <X509AlternateName> GetAlternateNames(this X509Certificate certificate,
                                                                  Oid2 alternateNameExtensionOid)
        {
            if (alternateNameExtensionOid == null)
            {
                throw new ArgumentNullException("alternateNameExtensionOid");
            }

            List <X509AlternateName> alternateNames = new List <X509AlternateName>();

            using (SafeCertContextHandle certContext = certificate.GetCertificateContext())
            {
                // Make sure we have the extension requested
                if (X509Native.HasExtension(certContext, alternateNameExtensionOid.Value))
                {
                    // If so, get it from the certificate, and decode it into a buffer
                    X509Native.CERT_EXTENSION alternateNameExtension =
                        X509Native.FindExtension(certContext, alternateNameExtensionOid.Value);

                    using (SafeLocalAllocHandle decodedBuffer = X509Native.DecodeExtension(alternateNameExtension))
                    {
                        // This buffer contains CERT_ALT_NAME_INFO which points us at the alternate names we
                        // were looking for
                        X509Native.CERT_ALT_NAME_INFO altNameInfo = decodedBuffer.Read <X509Native.CERT_ALT_NAME_INFO>(0);
                        for (int i = 0; i < altNameInfo.cAltEntry; ++i)
                        {
                            unsafe
                            {
                                X509Native.CERT_ALT_NAME_ENTRY *pAltNameEntry = (X509Native.CERT_ALT_NAME_ENTRY *)altNameInfo.rgAltEntry;
                                alternateNames.Add(X509AlternateName.FromAltNameEntry(pAltNameEntry[i]));
                            }
                        }
                    }
                }
            }

            return(alternateNames);
        }