(这是一个continuation of this question,其中我解决了一个问题并找到了另一个问题。)
我通过WireMock代理使用wget获取HTTPS网站。这是我的fetch命令,指向一个演示安全站点:
wget -e use_proxy=yes -e https_proxy=localhost:8100 \
https://www.rottentomatoes.com/
这是我的代理设置:
java -jar wiremock-standalone-2.5.1.jar \
--port 8081 --https-port 8100 \
--proxy-all https://www.rottentomatoes.com/ \
--record-mappings \
--root-dir ./proxy-cache \
--verbose
WireMock屏幕日志说明了这一点:
2017-03-27 12:08:09.066 Verbose logging enabled
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
2017-03-27 12:08:09.827 Verbose logging enabled
2017-03-27 12:08:09.892 Recording mappings to ./proxy-cache/mappings
/$$ /$$ /$$ /$$ /$$ /$$
| $$ /$ | $$|__/ | $$$ /$$$ | $$
| $$ /$$$| $$ /$$ /$$$$$$ /$$$$$$ | $$$$ /$$$$ /$$$$$$ /$$$$$$$| $$ /$$
| $$/$$ $$ $$| $$ /$$__ $$ /$$__ $$| $$ $$/$$ $$ /$$__ $$ /$$_____/| $$ /$$/
| $$$$_ $$$$| $$| $$ \__/| $$$$$$$$| $$ $$$| $$| $$ \ $$| $$ | $$$$$$/
| $$$/ \ $$$| $$| $$ | $$_____/| $$\ $ | $$| $$ | $$| $$ | $$_ $$
| $$/ \ $$| $$| $$ | $$$$$$$| $$ \/ | $$| $$$$$$/| $$$$$$$| $$ \ $$
|__/ \__/|__/|__/ \_______/|__/ |__/ \______/ \_______/|__/ \__/
port: 8081
https-port: 8100
https-keystore: jar:file:(removed)/wiremock-standalone-2.5.1.jar!/keystore
proxy-all: https://www.rottentomatoes.com/
preserve-host-header: false
enable-browser-proxying: false
record-mappings: true
match-headers: []
no-request-journal: false
verbose: true
结果是:
--2017-03-27 12:08:25-- https://www.rottentomatoes.com/
Resolving localhost (localhost)... 127.0.0.1
Connecting to localhost (localhost)|127.0.0.1|:8100... connected.
Failed reading proxy response: Success
Retrying.
--2017-03-27 12:08:26-- (try: 2) https://www.rottentomatoes.com/
Connecting to localhost (localhost)|127.0.0.1|:8100... connected.
Failed reading proxy response: Success
Retrying.
^C
如您所见,提取失败,自动重试,需要取消才能结束。
我在WireMock命令(standalone docs here)中尝试了--preserve-host-header
,但结果是一样的。
我想知道代理是否在内部失败,因为它需要指向有效的HTTPS证书存储区?也就是说,我希望正在运行的代理输出一些东西(甚至是错误),但它看起来根本就不会处理这个调用。等效的HTTP调用可以正常工作。
我能做些什么来了解为什么Wget会失败?错误信息不是很有帮助,据我所知,我不能使它更详细(默认情况下,wget中有详细信息)。
这种行为在Alpine 3.4(在Docker容器中)和在我的Ubuntu 14.04 VM上运行时是相同的。 WireMock 2.4.1,2.5.0和2.5.1也是如此。
我尝试将我的浏览器(Firefox)HTTPS代理设置切换为指向WireMock,并且由于证书错误而在我尝试获取的网站上失败。有趣的是,尽管看起来Firefox已经联系了远程服务器,但WireMock并没有向stdout输出任何内容。
我想知道Wiremock中的内置密钥库是否过时或是空的,因此学习如何指定“真正的”证书库可能是下一个值得尝试的东西。我使用these instructions将browser cert file转换为JKS格式,这对Wget或Firefox没有任何影响。
我注意到我新创建的密钥库是955字节,而原始的PEM证书文件是~260K,所以很明显并非所有的证书都已添加(可能只是添加了第一个?)。 FWIW我使用了这个命令:
keytool -import -v -trustcacerts -alias endeca-ca \
-file cacert.pem -keystore truststore.ks
我已将-verbose
和-verbose:jni
切换添加到java
调用,以证明在需要HTTPS代理时发生了某些事情。当我运行Wget命令时,打印出一篇名副其实的文章,所以我确信HTTPS代理正在被击中。 Wget在HTTP模式下也可以正常运行。
我正处于可以盲目尝试各种事情的阶段,我认为我需要从Java系统获得一些情报,以查看为什么它首先失败。我的猜测是Wiremock是问题,而不是Wget。
我在Wiremock --print-all-network-traffic
找到了一个未记录的功能,提供了这个功能:
2017-03-27 17:36:51.287 Opened Socket[addr=/127.0.0.1,port=54140,localport=8100]
2017-03-27 17:36:51.397 Incoming bytes: CONNECT www.rottentomatoes.com:443 HTTP/1.1
User-Agent: Wget/1.15 (linux-gnu)
Host: www.rottentomatoes.com:443
2017-03-27 17:36:51.398 Closed Socket[addr=/127.0.0.1,port=54140,localport=8100]
2017-03-27 17:36:51.399 Closed Socket[addr=/127.0.0.1,port=54140,localport=8100]
2017-03-27 17:36:52.400 Opened Socket[addr=/127.0.0.1,port=54142,localport=8100]
2017-03-27 17:36:52.483 Incoming bytes: CONNECT www.rottentomatoes.com:443 HTTP/1.1
User-Agent: Wget/1.15 (linux-gnu)
Host: www.rottentomatoes.com:443
第二部分经常重复wget重试,但这里仍然没有什么用处。我想知道为什么它失败了。
我可以添加到java -jar
的日志记录参数,还是存在系统范围的Java错误日志我可以参考?我已经安装了VisualVM,但各种输出似乎并不相关。我希望我对异常最感兴趣吗?
答案 0 :(得分:1)
我在PHP中编写了自己的代理,并根据目标是HTTP还是HTTPS来查看代理端wget
的行为,这表明我的误解。
基本上,HTTP客户端会使用标准方法(例如GET
或POST
)将HTTP请求转发(明文)到代理,如果需要,可以由代理捕获这些请求(例如,用于播放目的)。这就是WireMock和其他类似工具的功能。
但是,如果HTTP客户端通过代理获取HTTPS目标,则似乎需要使用CONNECT
方法,然后代理将充当双方之间的流量交换器 - 它有效编组加密数据的交换,无法对其进行解码。
因此,这里可能的解释是WireMock不打算处理这个动词,因为它无论如何也无法记录数据。
令我困惑的一个方面是,如果WireMock无法记录通过此端口传输的数据,则会提供--https-port
。如果我找到答案,我会更新这篇文章。