如何在 Spring Boot 应用程序中使用自签名证书启用 SSL,我在属性文件中添加了配置,但对我不起作用。
最佳答案
首先要做的是生成证书。您可以选择不同的格式,例如 PKCS12或 JKS .我将使用 PKCS12,因为它是一种不限于 JVM 的标准格式:
$keytool -genkeypair -alias so57488831 -keyalg RSA -keysize 2048 -storetype PKCS12 -keystore so57488831.p12 -validity 365
Enter keystore password: <so57488831>
Re-enter new password: <so57488831>
What is your first and last name?
[Unknown]: madhead
What is the name of your organizational unit?
[Unknown]: N/A
What is the name of your organization?
[Unknown]: N/A
What is the name of your City or Locality?
[Unknown]: Minsk
What is the name of your State or Province?
[Unknown]: Minsk
What is the two-letter country code for this unit?
[Unknown]: BY
Is CN=madhead, OU=N/A, O=N/A, L=Minsk, ST=Minsk, C=BY correct?
[no]: yes
将生成一个名为 so57488831.p12
的文件。将它放在项目的 resources
目录中:src/main/resources/so57488831.p12
。
应用程序.yml:
server:
ssl:
key-store-type: PKCS12
key-store: classpath:so57488831.p12
key-alias: so57488831
key-store-password: so57488831
你可以开始了。通过 HTTPS 调用您的应用:
看到 Firefox 中的“不受信任的证书”黄色三角警告了吗?让我们检查一下:
如果您有兴趣,请查看 demo project我已经为这个问题创建了。
关于java - 在 Spring Boot 应用程序中启用 SSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57488831/