以Mac系统为例
1. 安装mkcert
https://github.com/FiloSottile/mkcert
根据提示安装mkcert
brew install mkcert
2. 使用mkcert
mkcert -install
mkcert localhost 127.0.0.1
此时会在执行目录下生成localhost+1.pem 和 localhost+1-key.pem 两个文件
3. pem转p12
使用openssl进行转换,并输入密码:changeit
openssl pkcs12 -export -in localhost+1.pem -inkey localhost+1-key.pem -out keystore.p12 -name localhost -CAfile $(mkcert -CAROOT)/rootCA.pem -caname root -password pass:changeit
说明:mkcert -CAROOT 命令可以查询根证书的安装位置,替换成自己的真实位置,位置不对会报这个错误:pkcs12: Use -help for summary.
4. 与Springboot项目集成
将上述localhost+1.pem、localhost+1-key.pem和keystore.p12复制到resources下,修改配置如下:
server:
port: 8443
servlet:
context-path: /api
encoding:
charset: utf-8
enabled: true
force: true
ssl:
#开启SSL支持
enabled: true
key-alias: localhost
key-store-type: PKCS12
key-store: classpath:keystore.p12
key-store-password: changeit
http2:
enabled: true
shutdown: graceful
5. 证书信任
打开电脑的钥匙串访问面板,找到mkcert开头的秘钥,双击打开,设置始终信任。
评论区