【问题标题】:How to use self signed certificates in Postman?如何在 Postman 中使用自签名证书?
【发布时间】:2020-09-27 21:51:03
【问题描述】:

我正在使用Postman 来测试我的 API。我正在使用自签名证书在我的应用程序中使用 HTTPS。

打开 HTTPS 设置后,邮递员应用显示此错误

它显示

错误:自签名证书

当我在邮递员设置中关闭 SSL 证书验证时,API 调用运行良好。我尝试在邮递员应用程序中安装证书/密钥,但没有成功。

我想在邮递员中使用证书/密钥,以便我可以使用 SSL 访问 API。有什么办法吗?

【问题讨论】:

  • 你管理过这个吗?我有类似的问题?提前致谢!
  • 没有。我仍在寻找解决方案。
  • 当我在设置中关闭 SSL 证书验证时,它对我有用。
  • 运气好吗?我想用“SSL 开启”进行测试

标签: ssl https certificate postman


【解决方案1】:

生成RootCA.pemRootCA.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.keylocalhost.csrlocalhost.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

【讨论】:

    猜你喜欢
    • 2018-01-12
    • 2018-01-23
    • 1970-01-01
    • 2019-05-25
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    相关资源
    最近更新 更多