2011-07-27 2 views
5

私はクライアントサーバーの設定をしています。 クライアントは、サーバーと通信するためにプロキシを作成します。証明書の例外を除いてSSL証明書データを消去する方法

ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateRemoteCertificate); 

ValidateRemoteCertificate方法のお得な情報:通信プロトコルはHTTPSである場合は、プロキシは、次の行を経由してSSL証明書の検証イベントをリッスンします。

クライアントでは、3つのセキュリティレベル(低、中、高)のいずれかを選択できます。 低レベルでは、ValidateRemoteCertificateメソッドはエラーを無視し、常にtrueを返します。 中レベルでは、ValidateRemoteCertificateメソッドはクライアントに問題を通知するイベントを発生させます。この段階で、証明書に問題があることを知らせるメッセージがユーザーに表示され、サーバーとの接続を継続するか受け入れるかを選択することができます。 高レベルでは、ValidateRemoteCertificateメソッドは、エラーの接続を拒否します。

これまでのところとても良いです。すでにユーザーに受け入れられたとの接続が伝播するすべての証明書を発行せずにサーバーとの間で確立された中のあらかじめ定義されたセキュリティレベルの

  1. クライアントの負荷を次のように

    シナリオがあります。

  2. ユーザーは、クライアントをサーバーから切断します(特別なボタン)。
  3. ユーザーがクライアントに再接続を試みます。この段階で、クライアントはテストボタンを使用して接続をテストすることができます。接続テスト用に新しいプロキシが作成され、(特定のプロキシタイプの)ServerCertificateValidationCallbackからすべてのValidateRemoteCertificateメソッドがクリアされていても、テストメソッドは成功を返します。また、問題のある証明書に対してイベントが発生せず、ValidateRemoteCertificateメソッドが呼び出されません。

私が達成しようとしている行動は、テストが行​​われた場合、クライアントが開始されているとValidateRemoteCertificateが遊びに来るの後に、それはそれへの最初の呼び出しだかのように、ServerCertificateValidationCallbackが振る舞うということです。

ServicePointManagerのデリゲート/イベントをクリアするメソッドを探してみましたが、何も見つかりませんでした。

ここにキャッシュをクリアすることはできますか? シナリオが十分明確であることを願っています。

答えて

4

私はそれがほぼ4年経っていることを知っていますが、私はちょうどこの同じ問題を抱えていました。

public void EnsureNoServicePointCertificate(Uri uri) 
    { 
     // find the service point for the Uri 
     ServicePoint sp = ServicePointManager.FindServicePoint(uri); 
     // Check if there is a service point and there is a certificate 
     if (sp != null && sp.Certificate != null) 
     { 
      try 
      { 
       // ServicePointManager has a hashtable (private static Hashtable s_ServicePointTable) of all service points 
       Type servicePointType = sp.GetType(); 
       // ServicePoint.LookupString is the key for the hashtable 
       PropertyInfo lookupStringProperty = servicePointType.GetProperty("LookupString", BindingFlags.Instance | BindingFlags.NonPublic); 
       string lookupString = (string)lookupStringProperty.GetValue(sp, null); 

       // Get the hashtable from ServicePointManager 
       Hashtable s_ServicePointTable = (Hashtable)typeof(ServicePointManager).InvokeMember("s_ServicePointTable", 
        BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.GetField, null, null, null); 

       // ServicePointManager locks the hashtable and calls 
       // s_ServicePointTable.Remove(servicePoint.LookupString); 
       lock (s_ServicePointTable) 
       { 
        s_ServicePointTable.Remove(lookupString); 
       } 

       // At this point, ServicePointManager calls 
       // servicePoint.ReleaseAllConnectionGroups(); 
       MethodInfo release = servicePointType.GetMethod("ReleaseAllConnectionGroups", BindingFlags.Instance | BindingFlags.NonPublic); 
       release.Invoke(sp, null); 
      } 
      catch { } 
     } 
    } 

私はそうここのServicePointやServicePointManagerのソースコードを見て、これを処理する方法で構築見つけることができませんでしたが、私が思いついたものです