生成RootCA.pem、RootCA.key & RootCA.crt:
openssl req -x509 -nodes -new -sha256 -days 1024 -newkey rsa:2048 -keyout RootCA.key -out RootCA.pem -subj "/C=BR/CN=Example-Root-CA"
openssl x509 -outform pem -in RootCA.pem -out RootCA.crt
自定义你想要的...(C=?,CN=?等)
域名证书
添加您在本地计算机上托管的域myapp.local 以进行开发(使用hosts 文件将它们指向127.0.0.1)。
127.0.0.1 myapp.local
首先,创建一个文件domains.ext,列出所有本地域:
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names
[alt_names]
DNS.1 = localhost
DNS.2 = myapp.local
生成localhost.key、localhost.csr和localhost.crt:
openssl req -new -nodes -newkey rsa:2048 -keyout localhost.key -out localhost.csr -subj "/C=BR/ST=BAHIA/L=SSA/O=Example-Certificates/CN=localhost.local"
openssl x509 -req -sha256 -days 1024 -in localhost.csr -CA RootCA.pem -CAkey RootCA.key -CAcreateserial -extfile domains.ext -out localhost.crt
openssl pkcs12 -export -inkey localhost.key -in localhost.crt -out localhost.p12
自定义你想要的...(C=?,CN=?等)
对于 p12 使用“密码”。这是我在 springboot 应用程序上的密钥库,例如:
正在配置 Keystore(使用 PKCS12 格式,也可以使用 JKS 格式)...
https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-configure-ssl
cp localhost.p12 myapp/src/main/resources/keystore/localhost.p12
编辑application.properties
# secure server port
server.port=8443
# The format used for the keystore. It could be set to JKS in case it is a JKS file
server.ssl.key-store-type=PKCS12
# The path to the keystore containing the certificate
server.ssl.key-store=classpath:keystore/localhost.p12
# The password used to generate the certificate
server.ssl.key-store-password=password
# Enable ssl
server.ssl.enabled=true
信任本地 CA
此时,该站点将加载有关自签名证书的警告。为了获得绿色锁,您的新本地 CA 必须添加到受信任的根证书颁发机构。
在 Postman 中转到:
- 设置 -> 启用 SSL 证书验证:开启。
- 设置 -> 证书 -> CA 证书:添加 PEM RootCA.pem
在 curl 命令行中:
curl --cacert RootCA.crt -v https://myapp.local:8449/endpoint