Spring boot 我可以在没有https连接的情况下使用双向SSL吗?

Spring boot 我可以在没有https连接的情况下使用双向SSL吗?,spring-boot,ssl,ssl-certificate,Spring Boot,Ssl,Ssl Certificate,我对这种SSL配置非常陌生。我正在为Springboot应用程序添加双向ssl配置。我已经在网上浏览了很多关于这个实现的代码片段 我的目标服务器端点-是我进行REST调用的安全服务器 如果我设置application.yml: server: port: 9001 ssl: enabled: true client-auth: need key-store: classpath:KEYSTORE.pfx key-store-password: passwo

我对这种SSL配置非常陌生。我正在为Springboot应用程序添加双向ssl配置。我已经在网上浏览了很多关于这个实现的代码片段

我的目标服务器端点-是我进行REST调用的安全服务器

如果我设置application.yml:

server:
  port: 9001
  ssl:
    enabled: true
    client-auth: need
    key-store: classpath:KEYSTORE.pfx
    key-store-password: password
    key-alias: aliasname
    key-store-type: PKCS12
    trust-store: classpath:TRUSTSTORE.p12
    trust-store-password: password
    trust-store-type: PKCS12
我的应用程序在https上运行://localhost:9001

TRUSTSTORE.p12包含服务器的公共证书和CA证书

通过此设置,我可以使用RestTemplate配置从服务器获得响应。 当我给另一个没有我的服务器的公共证书的信任库时,它无法建立预期的连接行为

但当我禁用SSL时:

server:
      port: 9001
      ssl:
        enabled: false
我的应用程序在HTTP/:localhost:9001上运行

我仍然能够在SSL上下文中使用truststore和keystore进行相互身份验证吗? 我仍然可以使用上面的yml配置和下面的代码验证服务器的公共证书吗

    // KeyStore and TrustStore
            keyStore = KeyStore.getInstance("pkcs12");
            ClassPathResource classPathResource = new ClassPathResource("KEYSTORE.pfx");
            InputStream inputStream = classPathResource.getInputStream();
            keyStore.load(inputStream, "password".toCharArray());

            TS = KeyStore.getInstance("pkcs12");
            ClassPathResource classPathResource1 = new ClassPathResource("TRUSTSTORE.p12");
            InputStream inputStream1 = classPathResource1.getInputStream();
            TS.load(inputStream1, "password".toCharArray());

// configuring the SSLContext
            SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
                    new SSLContextBuilder().loadTrustMaterial(TS, new TrustSelfSignedStrategy())
                            .loadKeyMaterial(keyStore, "password".toCharArray()).build());

注意:当ssl设置为FALSE时,其他应用程序将在http/:localhost:9001处调用我的端点。我会在服务器上进行REST调用。

如果没有SSL,就无法进行相互SSL身份验证。虽然有人可能会构造某种相互身份验证方法,该方法可以使用普通HTTP而不是HTTPS,但对此没有标准。浏览器中实现的通常基于证书的相互身份验证仅适用于HTTPS,因为它实际上是SSL层的一部分。

尝试加密端点时cURL-v会输出什么?误导性标题。你的标题中的问题的答案是“是”,因为你可以直接使用TLS,但这不是你真正想要的。