我可以在没有 https 连接的情况下使用 Mutual/2 Way SSL 吗?
Can I have Mutual/2 Way SSL without having https connection?
我对这种 SSL 配置很陌生。我正在努力在 Springboot 应用程序上添加 2 路 ssl 配置。我已经在线浏览了很多关于此实现的代码片段。
我的目标服务器端点 - https://endpoint.com/path/to/service 是安全的,我可以对其进行 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 包含服务器的 public 证书和 CA 证书。
通过此设置,我能够使用 RestTemplate 配置从服务器获得响应。
当我提供另一个没有我的服务器 public 证书的 TrustStore 时,它无法建立连接 - 预期行为。
但是当我禁用 SSL 时:
server:
port: 9001
ssl:
enabled: false
我的应用程序在 HTTP//:localhost:9001 上运行。
我是否仍然能够使用我的 SSL 上下文中可用的信任库和密钥库进行相互身份验证?
我仍然可以使用上面的 yml 配置和下面的代码验证服务器的 public 证书吗?
// 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 调用我的端点。我会在 https://endpoint.com/path/to/service.
上对服务器进行 REST 调用
没有 SSL 就无法进行相互 SSL 身份验证。虽然人们可能会构建某种使用普通 HTTP 而不是 HTTPS 的相互身份验证方法,但没有这方面的标准。在浏览器中实现的通常基于证书的相互身份验证仅适用于 HTTPS,因为它实际上是 SSL 层的一部分。
我对这种 SSL 配置很陌生。我正在努力在 Springboot 应用程序上添加 2 路 ssl 配置。我已经在线浏览了很多关于此实现的代码片段。
我的目标服务器端点 - https://endpoint.com/path/to/service 是安全的,我可以对其进行 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 包含服务器的 public 证书和 CA 证书。
通过此设置,我能够使用 RestTemplate 配置从服务器获得响应。 当我提供另一个没有我的服务器 public 证书的 TrustStore 时,它无法建立连接 - 预期行为。
但是当我禁用 SSL 时:
server:
port: 9001
ssl:
enabled: false
我的应用程序在 HTTP//:localhost:9001 上运行。
我是否仍然能够使用我的 SSL 上下文中可用的信任库和密钥库进行相互身份验证? 我仍然可以使用上面的 yml 配置和下面的代码验证服务器的 public 证书吗?
// 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 调用我的端点。我会在 https://endpoint.com/path/to/service.
上对服务器进行 REST 调用没有 SSL 就无法进行相互 SSL 身份验证。虽然人们可能会构建某种使用普通 HTTP 而不是 HTTPS 的相互身份验证方法,但没有这方面的标准。在浏览器中实现的通常基于证书的相互身份验证仅适用于 HTTPS,因为它实际上是 SSL 层的一部分。