internal static T QueryContextAttribute <T>(SecHandle context, SECPKG_ATTR attribute) where T : new()
 {
     using (var buffer = new SafeStructureInOutBuffer <T>())
     {
         SecurityNativeMethods.QueryContextAttributes(context, attribute, buffer).CheckResult();
         return(buffer.Result);
     }
 }
        private static X509Certificate2 GetCertificate(SecHandle context, SECPKG_ATTR attr)
        {
            var cert = QueryContextAttribute <IntPtr>(context, attr);

            try
            {
                return(new X509Certificate2(cert));
            }
            finally
            {
                SecurityNativeMethods.CertFreeCertificateContext(cert);
            }
        }
Ejemplo n.º 3
0
 private static X509Certificate2 GetCertificate(SecHandle context, SECPKG_ATTR attr)
 {
     using (var buffer = new SafeStructureInOutBuffer <IntPtr>())
     {
         SecurityNativeMethods.QueryContextAttributesEx(context, attr, buffer, buffer.Length).CheckResult();
         try
         {
             return(new X509Certificate2(buffer.Result));
         }
         finally
         {
             SecurityNativeMethods.CertFreeCertificateContext(buffer.Result);
         }
     }
 }
Ejemplo n.º 4
0
 internal static extern SecStatusCode QueryContextAttributes(
     SecHandle phContext,
     SECPKG_ATTR ulAttribute,
     SafeBuffer pBuffer
     );
        internal static Tuple <T, SecStatusCode> QueryContextAttributeNoThrow <T>(SecHandle context, SECPKG_ATTR attribute) where T : new()
        {
            using (var buffer = new SafeStructureInOutBuffer <T>())
            {
                var result = SecurityNativeMethods.QueryContextAttributes(context, attribute, buffer);

                return(Tuple.Create(result != SecStatusCode.SUCCESS ? default : buffer.Result, result));
            }
        }