2013-08-05 37 views
5

クライアント証明書認証を使用してSSL経由でWebサービスに接続するための.p12ファイルを提供しました。私はこれをcURLを使用してPHPで正常に動作させています。クライアント証明書認証を使用したWebサービスへの接続

$headers = array(
    'Method: POST', 
    'Connection: Keep-Alive', 
    'User-Agent: PHP-SOAP-CURL', 
    'Content-Type: text/xml; charset=utf-8', 
    'SOAPAction: "'.$action.'"', 
); 

$ch = curl_init(); 

curl_setopt($ch, CURLOPT_URL, $location); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $request); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 
curl_setopt($ch, CURLOPT_FAILONERROR, 1); 
curl_setopt($ch, CURLOPT_SSLCERT, $this->clientcert); 
curl_setopt($ch, CURLOPT_SSLKEYTYPE, $this->clientcerttype); 
curl_setopt($ch, CURLOPT_SSLKEY, $this->keyfile); 
curl_setopt($ch, CURLOPT_SSLKEYPASSWD, $this->keypassword); 
curl_setopt($ch, CURLOPT_SSLVERSION, 3); 

$response = curl_exec($ch); 

私は今C#と.NETを使用して同じタスクをやろうとしているが、私はエラーが「SSLのための安全なチャネルを確立できませんでし得続ける:これらは、要求を実行するときに私が使用しているオプションです/権限を持つTLS: ''。 "

私は鍵を見つけることに問題がないようで、信頼関係の問題はないようです。それでも、何かが正しいとは言えません。

私はテストプログラムを作ったので、基本的な呼び出しが動作することをテストできます。

public void StartviaWSHttp() 
{ 
    var binding = new WSHttpBinding(); 
    binding.Security.Mode = SecurityMode.Transport; 
    binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None; 
    binding.Security.Message.NegotiateServiceCredential = false; 
    binding.Security.Message.ClientCredentialType = MessageCredentialType.None; 

    var baseAddress = new Uri("https://<host>:<port>/LineEndpoint1"); 
    var endpointAddress = new EndpointAddress(baseAddress); 

    var client = new LinePortTypeClient(binding, endpointAddress); 

    client.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.CurrentUser, StoreName.My, X509FindType.FindBySerialNumber, "00d48a233bf4b77523"); 

    Debug.Assert(client.ClientCredentials.ClientCertificate.Certificate.SerialNumber.ToLower() == "00d48a233bf4b77523"); 

    var header = new ctSoapHeaderMsg(); 
    var response = new object(); 
    client.Open(); 
    var responseCode = client.PerformFunction(ref header, "0893411111", out response); 
    client.Close(); 

    Console.WriteLine("Response Code :" + responseCode); 
    Console.WriteLine("Response :" + response); 
} 

現在のユーザーの個人/証明書で証明書を表示すると、信頼に関する問題は報告されません。証明書情報には、以下の目的を意図した証明書が記載されています。すべての発行ポリシーとすべてのアプリケーションポリシー。証明書パスには1つのエントリしかなく、証明書ステータスに「この証明書はOKです。」と表示されます。

私は問題の原因を紛失しています。おそらく、PHP呼び出しのためにPEERとHOSTの検証がオフになっているので、信頼の問題があります。それがC#のオプションであるかどうかはわかりません。


更新:(2013年8月9日) 私はSystem.NetとSystem.Net.Socketのためのいくつかの詳細なトレースを設定します。これが出力の開始です。

System.Net Verbose: 0 : [16124] WebRequest::Create(https://dsl-wholesale-testing.iinet.net.au:50500/LineEndpoint1) 
System.Net Verbose: 0 : [16124] HttpWebRequest#58508234::HttpWebRequest(https://dsl-wholesale-testing.iinet.net.au:50500/LineEndpoint1#128335743) 
System.Net Information: 0 : [16124] Current OS installation type is 'Client'. 
System.Net Information: 0 : [16124] RAS supported: True 
System.Net Verbose: 0 : [16124] Exiting HttpWebRequest#58508234::HttpWebRequest() 
System.Net Verbose: 0 : [16124] Exiting WebRequest::Create() -> HttpWebRequest#58508234 
System.Net Verbose: 0 : [16124] ServicePoint#36898364::ServicePoint(dsl-wholesale-testing.iinet.net.au:50500) 
System.Net Information: 0 : [16124] Associating HttpWebRequest#58508234 with ServicePoint#36898364 
System.Net Verbose: 0 : [16124] HttpWebRequest#58508234::GetRequestStream() 
System.Net Information: 0 : [16124] Associating Connection#47995487 with HttpWebRequest#58508234 
System.Net.Sockets Verbose: 0 : [16124] Socket#31002555::Socket(AddressFamily#2) 
System.Net.Sockets Verbose: 0 : [16124] Exiting Socket#31002555::Socket() 
System.Net.Sockets Verbose: 0 : [16124] Socket#6243847::Socket(AddressFamily#23) 
System.Net.Sockets Verbose: 0 : [16124] Exiting Socket#6243847::Socket() 
System.Net.Sockets Verbose: 0 : [16124] DNS::TryInternalResolve(dsl-wholesale-testing.iinet.net.au) 
System.Net.Sockets Verbose: 0 : [16124] Socket#31002555::Connect(203.173.51.130:50500#-2110560113) 
System.Net.Sockets Information: 0 : [16124] Socket#31002555 - Created connection from 192.168.190.202:55397 to 203.173.51.130:50500. 
System.Net.Sockets Verbose: 0 : [16124] Exiting Socket#31002555::Connect() 
System.Net.Sockets Verbose: 0 : [16124] Socket#6243847::Close() 
System.Net.Sockets Verbose: 0 : [16124] Socket#6243847::Dispose() 
System.Net.Sockets Verbose: 0 : [16124] Exiting Socket#6243847::Close() 
System.Net Information: 0 : [16124] Connection#47995487 - Created connection from 192.168.190.202:55397 to 203.173.51.130:50500. 
System.Net Information: 0 : [16124] TlsStream#29695768::.ctor(host=dsl-wholesale-testing.iinet.net.au, #certs=0) 
System.Net Information: 0 : [16124] Associating HttpWebRequest#58508234 with ConnectStream#25001628 
System.Net Verbose: 0 : [16124] Exiting HttpWebRequest#58508234::GetRequestStream()  -> ConnectStream#25001628 
System.Net Verbose: 0 : [16124] ConnectStream#25001628::Write() 
System.Net Verbose: 0 : [16124] Data from ConnectStream#25001628::Write 
System.Net Verbose: 0 : [16124] (printing 1024 out of 1206) 
System.Net Verbose: 0 : [16124] 00000000 : 3C 73 3A 45 6E 76 65 6C-6F 70 65 20 78 6D 6C 6E : <s:Envelope xmln 

System.Net Information: 0 : [16124] TlsStream#29695768::.ctor(host=dsl-wholesale-testing.iinet.net.au, #certs=0)は、証明書が、私はclient.ClientCredentials.ClientCertificateに証明書を添付したにも関わらず、使用のために拾っていないが、私はこれが起こっまたはどのようにしている理由はわからないされていることを示唆しているラインそれをつける。証明書のプロパティは、接続先のホスト名と一致する必要がありますか?

答えて

4

サーバーがTLSを認識していないようです。

は、私がコメントで述べたよう@ajeh

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3; 
+0

興味深い。私はまったく同じコードで同じエラーを出していますが、トレースで同じTLS cert#0を取得していますが、サーバがTLS 1.2をサポートしていることは確かです。私は私の知恵の終わりです。 – ajeh

+0

System.Net.ServicePointManager.SecurityProtocolはフラグであるため、追加のSecurityProtocolTypesをビット単位のORで指定できます。あなたがSsl13しか持っていなければ、Tlsは無視されます(PHP CurlではなくC#コードを参照していると仮定します)。 – Reuben

+1

Webサービスバインディングのセキュリティ要素に、追加要素が必要でした。それを追加し、すべてが機能しました。 – ajeh

0

を経由して、のSSLv3を指定する必要がありました "輸送clientCredentialType = ..." 私のために働きました!

<binding name="....."> 
    <security mode="Transport" > 
     <transport clientCredentialType="Certificate"></transport> 
    </security> 
</binding> 

また、IISアプリケーションプールユーザーが証明書の秘密キーを読み取る権限を持っていることを確認する必要があります。

関連する問題