Some web server/reverse proxy require the client to announce which hostname it wants to connect to. It's done via the Server Name Indication TLS extension. This allow sharing the same public IP between multiple hostnames. locust.io for example uses Cloudflare, which requires SNI in this setup.
Unlike HttpUser, FastHttpUser doesn't send the SNI extension, making all TLS connection to SNI-requiring servers fail.
Users are warned that FastHttpUser doesn't necessarily implement the same feature set as HttpUser, but geventhttpclient, used by FastHttpUser does support SNI in the included version.
The FastHttpUser client send the SNI extension as host, and the TLS connection succeed.
The following error is obtained and every TLS connection
SSLError(1, '[SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:1108)')
It can confirmed by capturing the TLS Client Hello network packet.
locustfile.py :
from locust import task, between
from locust.contrib.fasthttp import FastHttpUser
class ApiUser(FastHttpUser):
wait_time = between(1.0, 8.0)
@task(1)
def index(self):
self.client.get("/")
Execute
% locust -H 'https://locust.io' --headless
locust -H 'https://locust.io' --headlessDoes it work if you set ApiUser.insecure = False ?
No it does not, same error with this code (and verified with packet capture)
from locust import task, between
from locust.contrib.fasthttp import FastHttpUser
class ApiUser(FastHttpUser):
wait_time = between(1.0, 8.0)
insecure = False
@task(1)
def index(self):
self.client.get("/")
geventhttpclient is supposed to have SNI support (https://github.com/gwik/geventhttpclient/pull/109) but I can confirm that I can reproduce this bug.
Would definitely be interested in a fix.
Even though SNI support is supposed to work in geventhttpclient, it appears to be broken. This code causes the same exception:
from geventhttpclient.useragent import UserAgent
ua = UserAgent()
response = ua.urlopen('https://locust.io')
print("response:", response)
Found the same issue today, resolved this locally by changing the ssl_options to ssl_context_factory (the combination doesn't seem to be allowed) in 'locust/contrib/fasthttp.py'
```
self.client = LocustUserAgent(
cookiejar=self.cookiejar,
ssl_context_factory=gevent.ssl.create_default_context,
**kwargs
)
````
Only this way, it seem to trigger to set the server_hostname, see
if ssl_context_factory is not None:
requested_hostname = headers.get('host', self.host)
ssl_options.setdefault('server_hostname', requested_hostname)
from https://github.com/gwik/geventhttpclient/blob/master/src/geventhttpclient/client.py#L97
The ssl_options was added because of let's encrypt certificates, I'm not sure if this is broken again.
Hope this helps, I'm not sure what the right fix is (started with locust today)......
@tljdebrouwer Thanks for debugging! I've pushed a fix (0f6f2170331a10f6e0427e947bf91aab6a797b91) which I believe solves it.
Thanks. Fix looking good!
Op 4 mei 2020 om 22:02 heeft Jonatan Heyman notifications@github.com het volgende geschreven:
@tljdebrouwer Thanks for debugging! I've pushed a fix which I believe solves it.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
Most helpful comment
Found the same issue today, resolved this locally by changing the ssl_options to ssl_context_factory (the combination doesn't seem to be allowed) in 'locust/contrib/fasthttp.py'
```
self.client = LocustUserAgent(
cookiejar=self.cookiejar,
ssl_context_factory=gevent.ssl.create_default_context,
**kwargs
)
````
Only this way, it seem to trigger to set the server_hostname, see
if ssl_context_factory is not None: requested_hostname = headers.get('host', self.host) ssl_options.setdefault('server_hostname', requested_hostname)from https://github.com/gwik/geventhttpclient/blob/master/src/geventhttpclient/client.py#L97
The ssl_options was added because of let's encrypt certificates, I'm not sure if this is broken again.
Hope this helps, I'm not sure what the right fix is (started with locust today)......