Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > .NET > VB.NET > Program to Get Trusted CA List from IIS
【标  题】:Program to Get Trusted CA List from IIS
【关键字】:Program,to,Get,Trusted,CA,List,from,IIS
【来  源】:http://blog.joycode.com/mvm/archive/2007/04/13/101055.aspx

Program to Get Trusted CA List from IIS

Your Ad Here

Lots of people have seen the client certificate selection dialog when we use IE to browser HTTPS resources. Few people have thought about and understand why the certificate selection dialog doesn't include all certificate in personal store. The fact is: IE has received an acceptable issuer list from the web server side. IE will show nothing in the certificate selection dialog if there is no certificate which has "Client Authentication" usage and issued by any issuer (aka CA, root or intermediate CA) on that acceptable issuer list.

Knowing the acceptable issuer list of a certain web server is one of the key factors to troubleshotting HTTPS connectivity issues. We can tracing the acceptable issuers list by the C# code as below (sorry for long paragraph, joycode use to fancy code collapse feature which seems gone) :

 

using System;
using System.Collections;
using System.Net;
using System.Net.Sockets;
using System.Net.Security;
using System.Security.Authentication;
using System.Text;
using System.Security.Cryptography.X509Certificates;
using System.IO;

namespace ListServerTrustedCAs
{
   class Program
   {
      static void Main(string[] args)
      {
         if (args.Length != 1)
         {
            Console.WriteLine("\r\nUsage: ListServerTrustedCAs <servername>\r\n");
            return;
         }

         string serverName = args[0];
         TcpClient client = new TcpClient(serverName, 443);
         Console.WriteLine("Client connected.");
         SslStream sslStream = new SslStream(
            client.GetStream(),
            false,
            new RemoteCertificateValidationCallback(ValidateServerCertificate),
            new LocalCertificateSelectionCallback(SelectLocalCertificate)
            );

         try
         {
            sslStream.AuthenticateAsClient(serverName);
         }
         catch (AuthenticationException e)
         {
            Console.WriteLine("Exception: {0}", e.ToString());
            client.Close();
            return;
         }
         client.Close();
         Console.WriteLine("Client closed.");
      }

      public static bool ValidateServerCertificate(
           object sender,
           X509Certificate certificate,
           X509Chain chain,
           SslPolicyErrors sslPolicyErrors)
      {
         Console.WriteLine("ValidateServerCertificate. \r\n   Server-side cert: " + certificate.Subject);
         return true; // do nothing.
      }

      public static X509Certificate SelectLocalCertificate(
         object sender,
         string targetHost,
         X509CertificateCollection localCertificates,
         X509Certificate remoteCertificate,
         string[] acceptableIssuers)
      {
         if (acceptableIssuers != null)
         {
            foreach (string issuer in acceptableIssuers)
            {
               Console.WriteLine("<" + issuer + ">");
            }
         }
         return null;
      }
   }
}

The code above can also print out the IIS's Server Certificate.

The last but most important thing is: if your web server is IIS, you get to turn on SSLAlwaysNegoClientCert in IIS. Otherwise, the code above gets empty acceptable issuer list. The command line to turn on SSLAlwaysNegoClientCert is:

  Cscript.exe adsutil.vbs SET w3svc/SSLAlwaysNegoClientCert “true”

But the trick thing is: even without SSLAlwaysNegoClientCert turned on, IE still can get IIS's trusted CA list (so that IE shows eligible certificates in the selection dialog). I don't know how IE talks to IIS and force IIS to send back trusted CA list. Could be a undocumented flag in the hello message?

Reference (Must-Read!):
RFC 2246 "The TLS Protocol Version 1.0", section 7.4.4 "Certificate request".

 

CommunityServer2007改变授权策略, 不再有免费的午餐了:【上一篇】
:【下一篇】
【相关文章】
  • 实现 iSCSI Target的两种方法
  • 实现 iSCSI Initiator 的两种方法
  • 如何多人共享 iscsi target server
  • 请教iSCSI的target端多用户同时访问的问题
  • 单一登录:Active Directory 联合身份验证服务开发简介
  • stored procedure 收集session wait 信息(转)
  • JoyiStar发布在线操作系统--TOMOS内测体验
  • 国际化编程中Locale相关概念的一些解释
  • Apache Tomcat 5.5 的安装和配置
  • Canny算法源码,欢迎交流
  • 【随机文章】
  • 白头粉刺与黑头粉刺的区别粉刺治疗方法粉刺的治疗康本最好最迅速
  • Linux进程管理及作业控制(1)
  • DB2 Universal Database 和高可用数据存储
  • Create为什么可以为虚函数?
  • 使用SQL Server数据转换服务升迁Access数据库
  • GmailFS
  • 病毒名称 天堂地狱火Win32.Troj.T2yuhuo
  • PXE无盘网络原理
  • 使用GRUB引导多个操作系统
  • 动手加固OpenSSH服务器
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.