如何为独立的Wiremock启用HTTPS [英] How to enable HTTPS for standalone Wiremock

查看:595
本文介绍了如何为独立的Wiremock启用HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

概述:

我使用独立的Wiremock 2.1.11,并执行以下操作为请求启用HTTPS URL,但无济于事:

I used wiremock standalone 2.1.11 and did the following to enable HTTPS URL for my request but to no avail:

运行Wiremock的命令如下:

The command for running the wiremock is as follows:

java -jar wiremock-standalone-2.1.11.jar --port 8920 --https-port 8921 --https-keystore /home/wiremock/keystore/clientkeystore --verbose

注意: 我可以通过http端口正确连接

Note: I can connect via http port correctly

现在,如果有人可以帮助我找到HTTPS连接的解决方案,我将不胜感激.

Now I would be grateful if anyone could help me find solution for HTTPS connection.

推荐答案

  1. 为Wiremock生成Java密钥存储区

  1. Generate java key store for wiremock

 keytool -genkey -alias wiremock -keyalg RSA -keysize 1024 \
 -validity 365 -keypass password -keystore identity.jks -storepass password

重要---按照提示指定证书详细信息:

Important --- Follow the prompts to specify the certificate details:

  • 名字和姓氏:这不是您的名字,而是通用名(CN),例如"confluence.example.com". CN必须与运行Confluence的服务器的标准主机名匹配,否则Tomcat无法将证书用于SSL.
  • 组织单位:这是要求证书的团队或部门,例如市场营销".
  • 组织:这是您的公司名称,例如'SeeSpaceEZ'. 城市,州/省,国家/地区代码:这是您的所在地,例如悉尼,新南威尔士州,澳大利亚.
  • First and last name: this is not your name, it is the Common Name (CN), for example 'confluence.example.com'. The CN must match the fully qualified hostname of the server running Confluence, or Tomcat won't be able to use the certificate for SSL.
  • Organizational unit: this is the team or department requesting the certificate, for example 'marketing'.
  • Organization: this is your company name, for example 'SeeSpaceEZ'. City, State / province, country code: this is where you're located, for example Sydney, NSW, AU.

创建自签名证书

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout localhost.key -out localhost.crt -config localhost.conf

  • 将认证导入密钥库

  • Import certification into keystore

     keytool -import -trustcacerts -alias mock -file localhost.crt -keystore identity.jks
    

  • 启用新的密钥库并启用HTTPS来启动Wiremock

  • Start wiremock with the new keystore and HTTPS enabled

     java -jar wiremock-1.54-standalone.jar --https-port 8443 --https-keystore 
     ./identity.jks
    

  • 资源:

    答案来自 https://gist.github.com/mobmad/433ba54e9cb97d6d7771# 1个生成自签名证书

    这篇关于如何为独立的Wiremock启用HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆