2

我在 Azure 中有一个 Web 角色,它必须连接到受 SSL 保护的外部 Web 服务。当应用程序尝试连接到 Web 服务时,它会给出一个错误:

无法为具有“certname.organization.org”权限的 SSL/TLS 安全通道建立信任关系。

它所需的证书已作为服务证书上传到 Azure,但由于某种原因,它似乎没有正确引用或使用它。

关于如何解决这个问题的任何想法?

4

4 回答 4

1

听起来您在 Azure 中的服务客户端对您正在调用的外部服务的 SSL 证书不满意 - 您是否可以控制该服务?

您可以通过使用以下内容来测试这一点,以忽略来自 Azure 中客户端的 SSL 错误:

ServicePointManager.ServerCertificateValidationCallback =
    (obj, certificate, chain, errors) => true;
于 2012-04-05T16:13:57.547 回答
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;
}
于 2012-04-05T17:54:49.907 回答
0

忽略 SSL 错误是您可以做的一件事。

但是,如果它在您的机器上运行,并且在您的实例上不起作用,则也可能是实例上的证书链不完整。您需要在您的机器上打开证书,转到证书路径并导出路径中的每个证书。

然后,将这些证书添加到您的项目并让启动任务(.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
于 2012-04-06T06:25:13.913 回答
0

我将 cer 添加到项目的根目录并选择“始终复制”并使用以下命令使 azure 使用 SSL 自签名连接到服务器

 REM Install certificates.
certutil -addstore -enterprise -f -v root startsodev.cer
于 2013-01-23T00:03:10.433 回答