Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FastHttpUser doesn't use the SNI TLS extension #1360

Closed
gileri opened this issue Apr 30, 2020 · 7 comments
Closed

FastHttpUser doesn't use the SNI TLS extension #1360

gileri opened this issue Apr 30, 2020 · 7 comments
Labels

Comments

@gileri
Copy link

gileri commented Apr 30, 2020

Describe the bug

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.

Expected behavior

The FastHttpUser client send the SNI extension as host, and the TLS connection succeed.

Actual behavior

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.

Steps to reproduce

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

Environment

  • OS: Archlinux up to date as of 2020-04-30
  • Python version: 3.8.2
  • Locust version: git master @5cad1cb5921ff84298d357e0a5ba42bdc0390acc
  • Locust command line that you ran: locust -H 'https://locust.io' --headless
@gileri gileri added the bug label Apr 30, 2020
@cyberw
Copy link
Collaborator

cyberw commented Apr 30, 2020

Does it work if you set ApiUser.insecure = False ?

@gileri
Copy link
Author

gileri commented Apr 30, 2020

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("/")

@heyman
Copy link
Member

heyman commented Apr 30, 2020

geventhttpclient is supposed to have SNI support (geventhttpclient/geventhttpclient#109) but I can confirm that I can reproduce this bug.

Would definitely be interested in a fix.

@heyman
Copy link
Member

heyman commented Apr 30, 2020

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)

@tljdebrouwer
Copy link

tljdebrouwer commented May 1, 2020

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)......

@heyman
Copy link
Member

heyman commented May 4, 2020

@tljdebrouwer Thanks for debugging! I've pushed a fix (0f6f217) which I believe solves it.

@heyman heyman closed this as completed May 4, 2020
@tljdebrouwer
Copy link

tljdebrouwer commented May 4, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants