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

SSL (wss://) support for HTTPS pages #4

Closed
x25 opened this issue Oct 2, 2017 · 10 comments
Closed

SSL (wss://) support for HTTPS pages #4

x25 opened this issue Oct 2, 2017 · 10 comments

Comments

@x25
Copy link
Owner

x25 commented Oct 2, 2017

There is an error on the https pages in the browser:

Mixed Content: The page at 'xxxxxxxxxxx' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'ws://poolhost:8892/proxy'. This request has been blocked; this endpoint must be available over WSS.

There is two solutions:

  1. Implement TLS: secure WebSocket bindings in proxy
    https://github.com/crossbario/autobahn-python/tree/master/examples/twisted/websocket/echo_tls
contextFactory = ssl.DefaultOpenSSLContextFactory('server.key', 'server.crt')
autobahn.twisted.websocket.listenWS(ws, contextFactory)
twisted.internet.reactor.listenSSL(8892, site, contextFactory)
  1. Use reverse proxy to forward wss:// requests to the local proxy port
    https://stackoverflow.com/questions/12102110/nginx-to-reverse-proxy-websockets-and-enable-ssl-wss

Sample nginx configuration:

location /proxy {
    proxy_pass ​http://localhost:8892;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_read_timeout 86400;
}
@vphelipe
Copy link

vphelipe commented Oct 4, 2017

My solution, change to your key and crt:

from twisted.internet import ssl

root = Root('./static')
root.putChild(b"proxy", autobahn.twisted.resource.WebSocketResource(ws))
site = twisted.web.server.Site(root)
twisted.internet.reactor.listenSSL(9992,site,ssl.DefaultOpenSSLContextFactory('x.key', 'x.crt'))   
twisted.internet.reactor.run()

@kiezpr0grammer
Copy link

kiezpr0grammer commented Oct 5, 2017

@vphelipe

when i use your solution i'l# get the following error:
File "/coinhive-stratum-mining-proxy.py", line 39, in <module> from twisted.internet import ssl File "/usr/lib/python2.7/site-packages/twisted/internet/ssl.py", line 59, in <module> from OpenSSL import SSL ImportError: No module named OpenSSL
How can i solve this error?

@vphelipe
Copy link

vphelipe commented Oct 5, 2017

@kiezpr0grammer hello! Solution if you use ubuntu or debian:
apt-get install python-openssl

@kiezpr0grammer
Copy link

@vphelipe i already have installed it, but still no success -.-

python-openssl is already the newest version (16.2.0-1).
0 upgraded, 0 newly installed, 0 to remove and 79 not upgraded.

@vphelipe
Copy link

vphelipe commented Oct 5, 2017

@kiezpr0grammer ok, try: pip install pyOpenSSL

@kiezpr0grammer
Copy link

@vphelipe sorry, to bother you, but i'm new to that whole docker python thing

where do i have to put it in the dockerfile? would be

Install dependencies

RUN apk add --no-cache python python-dev openssl-dev gcc musl-dev git &&
python -m ensurepip &&
rm -r /usr/lib/python*/ensurepip &&
pip install --upgrade pip setuptools pip install pyOpenSSL &&
rm -r /root/.cache

correct?

@kiezpr0grammer
Copy link

okay, i mangend to install it, but the build process exits with an error :(

Command "/usr/bin/python -u -c "import setuptools, tokenize;file='/tmp/pip-build-DzQvvg/cffi/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-xTrgvg-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-DzQvvg/cffi/

@vphelipe
Copy link

vphelipe commented Oct 5, 2017

Sorry but I do not use docker :(

@kiezpr0grammer
Copy link

@vphelipe thanks for your help, i just used the python way and not the dockerway and it works like a charm 👯‍♂️

@x25 x25 mentioned this issue Oct 7, 2017
@x25 x25 mentioned this issue Oct 20, 2017
@x25
Copy link
Owner Author

x25 commented Oct 25, 2017

SSL support is implemented! Thanks to @zatarra

@x25 x25 closed this as completed Oct 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants