【问题标题】:Azure WebJobs can't connect to SQL using encrypted communicationAzure WebJobs 无法使用加密通信连接到 SQL
【发布时间】:2016-12-14 11:08:38
【问题描述】:

我有一个在 Azure 上作为 WebJob 运行的 Java 应用程序。此作业尝试连接到我的 Azure SQL Server。如果加密开启,我会收到连接错误:

The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "java.security.cert.CertificateException: Failed to validate the server name in a certificate during Secure Sockets Layer (SSL) initialization.".

如果encrypt = false 连接正常。

Azure 中资源之间的通信不应该一直加密吗?

另外,如果我在本地运行应用程序,数据库连接以加密模式成功连接。

【问题讨论】:

    标签: java azure azure-sql-database azure-webjobs


    【解决方案1】:

    首先,我应该解释一下 Azure SQL DB 始终默认使用加密连接。您看到的错误是关于 验证您正在与之通信的服务器的身份,这是 SSL 握手的一部分。 [这里有一些关于这个想法的解包。] (https://security.stackexchange.com/questions/1779/how-does-an-ssl-server-prove-its-identity)

    我在MSDN thread 的答案中解开了与 Azure SQL 数据库的通信加密,但我会将相关部分带到这里:

    When using Azure SQL DB, connections are encrypted even when the connection
    string does not include those portions we recommend. 
    ...
    Encryption occurs only if there is a verifiable server certificate,
    otherwise the connection attempt fails.
    

    正如MSDN article 所述,您的错误源于以下情况:

    If the encrypt property is set to true and the trustServerCertificate 
    property is set to false and if the server name in the connection string 
    does not match the server name in the SQL Server SSL certificate, the 
    following error will be issued: The driver could not establish a secure 
    connection to SQL Server by using Secure Sockets Layer (SSL) encryption. 
    Error: "java.security.cert.CertificateException: Failed to validate the
    server name in a certificate during Secure Sockets Layer (SSL) initialization."
    

    显然,SQL Server 4.0 的 JDBC 驱动程序似乎可以解决这个错误: Azure VM Fails to Connect to Azure SQL Service

    Certificate Exception connecting to Azure SQL with JDBC with default connection string (the one the management console says to use)

    【讨论】:

    • 我正在使用 PaaS(Azure 的 WebApp 和 SQL Server)。我尝试了 Microsoft 的 JDBC 驱动程序的 4.0.2206.100 版本,现在它可以在加密模式下工作。谢谢!
    • 出于好奇,有人知道这是什么原因吗?
    • 很高兴它成功了。我会确保明天将其提交为回归。 (我也会尝试解释为什么会发生这种情况,但为了准确起见,我想在发帖之前与团队核实原因。)
    • 谢谢丹!欣赏它。
    • Paul - 我更新了我的答案,但我仍在与这里的一些人合作,以查明为什么这是较新的 JDBC 驱动程序中的行为。
    猜你喜欢
    • 2018-02-09
    • 1970-01-01
    • 1970-01-01
    • 2016-07-16
    • 1970-01-01
    • 2022-06-13
    • 1970-01-01
    • 2021-12-17
    • 1970-01-01
    相关资源
    最近更新 更多