Yubico / yubihsm-connector

https://developers.yubico.com/yubihsm-connector/
Apache License 2.0
31 stars 14 forks source link

HTTP connect with python to yubihsm-connector - Timeout #14

Closed Pymann closed 4 years ago

Pymann commented 4 years ago

So everything is running fine i can see status with curl and the connector claims to see the device:

^CXXXXX@Husten:~/go/yubihsm-connector/bin$ sudo ./yubihsm-conntor -d [sudo] Hohl: DEBU[0000] preflight complete cert= config= key= pid=14393 seccomp=false serial= syslog=false timeout=0s version=2.1.0 DEBU[0000] takeoff TLS=false listen="localhost:12345" pid=14393 DEBU[0168] reopening usb context Correlation-ID=ab256601-a7b3-4697-9179-981f83dd6246 why="status request" DEBU[0168] usb context not yet open Correlation-ID=ab256601-a7b3-4697-9179-981f83dd6246 DEBU[0168] Returning a matched device Correlation-ID=ab256601-a7b3-4697-9179-981f83dd6246 Device-Serial=0007550878 Wanted-Serial= DEBU[0168] usb endpoint read Correlation-ID=ab256601-a7b3-4697-9179-981f83dd6246 buf="[]" err="transfer was cancelled" len=0 n=0 INFO[0168] handled request Content-Length=0 Content-Type= Method=GET RemoteAddr="127.0.0.1:57608" StatusCode=200 URI=/connector/status User-Agent=curl/7.58.0 X-Real-IP=127.0.0.1 X-Request-ID=ab256601-a7b3-4697-9179-981f83dd6246 latency=280.515203ms ERRO[0177] error in handling request Content-Length=0 Content-Type= Method=GET RemoteAddr="127.0.0.1:57612" StatusCode=405 URI=/connector/api User-Agent=curl/7.58.0 X-Real-IP=127.0.0.1 X-Request-ID=d6b7b21b-211e-4f11-856f-e97aeafe1724 latency="26.92µs" DEBU[0181] reopening usb context Correlation-ID=cb69976f-262d-4dd6-a3ec-c82bb3ec2e19 why="status request" DEBU[0181] Returning a matched device Correlation-ID=cb69976f-262d-4dd6-a3ec-c82bb3ec2e19 Device-Serial=0007550878 Wanted-Serial= DEBU[0181] usb endpoint read Correlation-ID=cb69976f-262d-4dd6-a3ec-c82bb3ec2e19 buf="[]" err="transfer was cancelled" len=0 n=0 INFO[0181] handled request Content-Length=0 Content-Type= Method=GET RemoteAddr="127.0.0.1:57616" StatusCode=200 URI=/connector/status User-Agent=curl/7.58.0 X-Real-IP=127.0.0.1 X-Request-ID=cb69976f-262d-4dd6-a3ec-c82bb3ec2e19 latency=281.189278ms

But when i want to connect with python, I'm using the example Code: https://developers.yubico.com/YubiHSM2/Component_Reference/python-yubihsm/

I get http timeout, I have attached strace-log. st_log_sign.txt

dainnilsson commented 4 years ago

It looks to me like the example code in that link is incorrect/outdated in regards to the URL. Compare it to the sample code here: https://developers.yubico.com/python-yubihsm/

Based on your trace, it looks like this is causing an extra /connector to be added in the request. Please try dropping the path from the URL and providing it as hsm = YubiHsm.connect('http://localhost:12345') instead.

Pymann commented 4 years ago

So Curl answers to this URL: http://localhost:12345 404 page not found (server seems to answer) and i still face timeout with python.

So Exception shows now correct URL: Max retries exceeded with url: http://localhost:12345/connector/api

... still timeout. I also wonder about the port: port=3128

curl shows: curl http://localhost:12345/connector/api Method Not Allowed

Pymann commented 4 years ago

I tried to reduce the problem with following script:

from six.moves.urllib import parse
import requests

url="http://www.google.de/"
timeout = None

_url = parse.urljoin(url, '')
print(_url)
_timeout = timeout

_session = requests.Session()
msg="hi"

try:
    resp = _session.post(
        url=_url,
        data=msg,
        timeout=_timeout
    )
    resp.raise_for_status()
except Exception as e:
    raise Exception(e)

And still timeout occurs, so problems is about requests-module. Or settings of it or of OS.

I dont think problem is up to yubihsm

Theres left to say, that requests python lib is buggy concerning proxy-servers, issues are known.