JDBC 驱动程序连接到 SQL Server 时出现 SSl 握手验证错误

Meh*_*hdi 4 eclipse sql-server ssl hibernate jdbc

我正在尝试在 Spring Boot 应用程序中使用其最新的 JDBC 驱动程序从 linux 连接到 SQL Server。当我使用 eclipse 运行 junit 测试用例时,出现“ssl 握手”错误。当我使用 mvn 在命令行中运行时,一切都很好。

我是否遗漏了什么或在我的配置中犯了任何错误:

@RunWith(SpringRunner.class)
@SpringBootTest
public class BarcodeRepositoryTest {

    @Autowired
    private BarcodeRepository addressRepository;

    @Test
    public void testFetchData() {
        List<Barcode> addresses = addressRepository.findAll();

        assertNotNull(addresses);
        assertNotEquals(0, addresses.size());
    }
}




spring.datasource.url=jdbc:sqlserver://[server]:1433;databaseName=ITTemp
spring.datasource.username=[username]
spring.datasource.password=[password]
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SQLServer2008Dialect
spring.jpa.hibernate.ddl-auto=none
Run Code Online (Sandbox Code Playgroud)

错误堆栈跟踪:

引起:java.security.cert.CertificateException:证书不符合 sun.security.ssl.AbstractTrustManagerWrapper.checkAlgorithmConstraints(SSLContextImpl.java:1120) ~[na:1.8.0_172] 在 sun.security.ssl 的算法约束。 AbstractTrustManagerWrapper.checkAdditionalTrust(SSLContextImpl.java:1044) ~[na:1.8.0_172] 在 sun.security.ssl.AbstractTrustManagerWrapper.checkServerTrusted(SSLContextImpl.java:986) ~[na:1.8.0_172] 在 sun.security.s. ClientHandshaker.serverCertificate(ClientHandshaker.java:1596) ~[na:1.8.0_172] ... 省略了 86 个常见帧 原因:java.security.cert.CertPathValidatorException:密钥大小限制的算法约束检查失败。与证书一起使用的 RSA 1024 位密钥:CN=SSL_Self_Signed_Fallback。用法是 sun.security.util 上的 tls 服务器。

当我从 eclipse 运行测试用例时,我看到了这个错误。

小智 7

我在 SQL Server 2014 和 Open JDK 11 中遇到了同样的问题。我最终通过按照说明为 SQL Server 2014 实例创建自签名证书来解决它:

https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/enable-encrypted-connections-to-the-database-engine?view=sql-server-2014

此问题是因为 SQL Server 生成的默认自签名证书在尝试验证 SQL Server 实例提供的证书时使用了 JDK 不允许的一种或多种算法。关键是生成一个新的自签名证书(遵循上述指导),该证书将被 JDK 接受。添加回不允许的算法几乎肯定会导致您使用较弱的加密。