2012-04-05 19 views
2

私はAzureでSSLで保護された外部Webサービスに接続する必要のあるWebロールを持っています。アプリケーションがWebサービスに接続しようとすると、それがエラーを与えている:それは必要AzureからHTTPS Webサービスに接続

Could not establish trust relationship for the SSL/TLS secure channel with authority 'certname.organization.org'.

証明書は、サービスの証明書としてのAzureにアップロードされていますが、何らかの理由で適切ではないようですそれを参照するか、それを使用します。

これを修正する方法についてのご意見はありますか?

答えて

1

Azureのサービスクライアントのように聞こえるのは、あなたが呼んでいる外部サービスのSSL証明書に満足していません。あなたはそのサービスを管理していますか?

あなたはAzureの中で、あなたのクライアントからのSSLエラーを無視するには、以下の使用してこれをテストすることができます。私は断続的にも、この問題を見てきました

ServicePointManager.ServerCertificateValidationCallback = 
    (obj, certificate, chain, errors) => true; 
+0

私はそれを制御できません。そして、私がローカルで(Azureエミュレータを使用せずに)テストすると、接続して正常に動作します。 Azureが適切な証明書を見つけることができないというアクセス許可の問題のようです。私はあなたの提案を試みました、そして、それはとても感謝しました。しかし、それは修正よりも回避策が多い。 –

1

。私の場合は、ルート証明書の1つを取得するためのネットワーク接続がタイムアウトすることがあることが判明しました。その後、今後のリクエストでは再び動作します。

私は、他の証明書の検証に影響を与えずに、エラーにも関わらず関心のある特定の証明書を動作させるカスタムコールバックを作成しました。以下はそのための私のコードです。おそらくわかるように、Android Cloud-to-Device Messagingエンドポイントをヒットし、Googleが使用するワイルドカード証明書の問題を回避しようとしていますが、一般化可能でなければなりません。これには、特定のエラーを診断するために使用したすべてのログも含まれています。証明書の検証を強制したくない場合でも、ロギングコードはどのように進めるかを決めるのに役立ちます。

private static readonly Uri PUSH_URI = new Uri("https://android.apis.google.com/c2dm/send", UriKind.Absolute); 

/** 
//The following function needs to be wired up in code somewhere else, like this: 
ServicePointManager.ServerCertificateValidationCallback += ValidateDodgyGoogleCertificate; 
**/ 
/// <summary> 
/// Validates the SSL server certificate. Note this is process-wide code. 
/// Wrote a custom one because the certificate used for Google's push endpoint is not for the correct domain. Go Google. 
/// </summary> 
/// <param name="sender">either a host name string, or an object derived from WebRequest</param> 
/// <param name="cert">The certificate used to authenticate the remote party.</param> 
/// <param name="chain">The chain of certificate authorities associated with the remote certificate.</param> 
/// <param name="sslPolicyErrors">One or more errors associated with the remote certificate.</param> 
/// <returns> 
/// Returns a boolean value that determines whether the specified 
/// certificate is accepted for authentication; true to accept or false to 
/// reject. 
/// </returns> 
private static bool ValidateDodgyGoogleCertificate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors sslPolicyErrors) 
{ 
    if (sslPolicyErrors == SslPolicyErrors.None) 
    { 
    // Good certificate. 
    return true; 
    } 

    string hostName = sender as string; 
    if (hostName == null) 
    { 
    WebRequest senderRequest = sender as WebRequest; 
    if (senderRequest != null) 
    { 
     hostName = senderRequest.RequestUri.Host; 
    } 
    } 

    //We want to get past the Google name mismatch, but not allow any other errors 
    if (sslPolicyErrors != SslPolicyErrors.RemoteCertificateNameMismatch) 
    { 
    StringBuilder sb = new StringBuilder(); 
    sb.AppendFormat("Rejecting remote server SSL certificate from host \"{0}\" issued to Subject \"{1}\" due to errors: {2}", hostName, cert.Subject, sslPolicyErrors); 

    if ((sslPolicyErrors | SslPolicyErrors.RemoteCertificateChainErrors) != SslPolicyErrors.None) 
    { 
     sb.AppendLine(); 
     sb.AppendLine("Chain status errors:"); 

     foreach (var chainStatusItem in chain.ChainStatus) 
     { 
     sb.AppendFormat("Chain Item Status: {0} StatusInfo: {1}", chainStatusItem.Status, chainStatusItem.StatusInformation); 
     sb.AppendLine(); 
     } 
    } 

    log.Info(sb.ToString()); 

    return false; 
    } 

    if (PUSH_URI.Host.Equals(hostName, StringComparison.InvariantCultureIgnoreCase)) 
    { 
    return true; 
    } 

    log.Info("Rejecting remote server SSL certificate from host \"{0}\" issued to Subject \"{1}\" due to errors: {2}", hostName, cert.Subject, sslPolicyErrors); 
    return false; 
} 
0

SSLエラーを無視することができます。

しかし、マシン上で動作し、インスタンス上で動作しない場合は、証明書チェーンがインスタンス上で不完全であることもあります。あなたのマシンで証明書を開く必要があります。Certification Pathに行き、パスに各証明書をエクスポートします。その後

、プロジェクトにこれらの証明書を追加し、スタートアップタスク(.BATまたは.CMDファイル)が信頼されたルートCAに追加しています

REM Install certificates. 
certutil -addstore -enterprise -f -v root Startup\Certificates\someROOTca.cer 
certutil -addstore -enterprise -f -v root Startup\Certificates\otherROOTca.cer 
+0

残念ながらこれはAzureなので、コマンドラインでは何も実行できませんが、チェーン内の証明書を破棄する提案を試みます。 –

+0

実際には、スタートアップタスクを使用してこれを実行できます。http://blog.smarx.com/posts/windows-azure-startup-tasks-tips-tricks-and-gotchas –

0

私は私のプロジェクトのルートにCERを追加しました「Copy Always」を選択して、次のコマンドを使用して、SSL自己署名付きサーバに接続します。

REM Install certificates. 
certutil -addstore -enterprise -f -v root startsodev.cer 
関連する問題