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 support for websocket and http requests #307

Merged
merged 9 commits into from
Jun 19, 2024
Merged

ssl support for websocket and http requests #307

merged 9 commits into from
Jun 19, 2024

Conversation

nlef
Copy link
Owner

@nlef nlef commented Mar 5, 2024

Added ssl support

#273
new configuration params in [bot] section:

  • ssl: False by default
  • ssl_validate: False by default
  • port: 80 by default

@nlef nlef added the bug Something isn't working label Mar 5, 2024
@nlef nlef linked an issue Mar 5, 2024 that may be closed by this pull request
1 task
@nlef
Copy link
Owner Author

nlef commented Mar 5, 2024

@HinataKato
pls check this pr. SSL now should work correctly.

@HinataKato
Copy link

@HinataKato pls check this pr. SSL now should work correctly.

Sorry for being this late, haven't had time lately

Looks like disabled certificates aren't working correctly? If ssl_validate=true, I get

urllib3.connection - WARNING - Certificate did not match expected hostname blablabla

Seems pretty normal right? But when I set it to false, I get

/moonraker-telegram-bot-env/lib/python3.11/site-packages/urllib3/connectionpool.py:1061: InsecureRequestWarning: Unverified HTTPS request is being made to host '127.0.0.1'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
websocket - ERROR - [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: IP address mismatch, certificate is not valid for '127.0.0.1'. (_ssl.c:992) - goodbye

And the SSL part seems didn't work either. I set the server to my domain and got this

websocket_helper - ERROR - Handshake status 502 Bad Gateway
websocket - ERROR - Handshake status 502 Bad Gateway - goodbye
websocket_helper - INFO - WebSocket closed

(My moonraker is working normally btw, I can access the info page for the SSL enabled port)

@nlef
Copy link
Owner Author

nlef commented Apr 4, 2024

@HinataKato
I fixed errors related to certificate settings.
Please check again

@krawa
Copy link

krawa commented Apr 24, 2024

Current Moonraker telegram bot config
[bot]
server = 192.168.0.107
port = 443
ssl = true
ssl_validate = false
user = kkkk
password = tkertdfgdfg
debug = true

2024-04-24 15:01:33,136 - apscheduler.scheduler - INFO - base.py:166 - Scheduler started
2024-04-24 15:01:33,138 - apscheduler.scheduler - DEBUG - base.py:940 - Looking for jobs to run
2024-04-24 15:01:33,141 - apscheduler.scheduler - DEBUG - base.py:1016 - No jobs; waiting until a job is added
2024-04-24 15:01:34,151 - klippy - ERROR - klippy.py:154 - Unauthorized
2024-04-24 15:01:34,158 - apscheduler.scheduler - INFO - base.py:166 - Scheduler started
2024-04-24 15:01:34,163 - apscheduler.scheduler - DEBUG - base.py:940 - Looking for jobs to run
2024-04-24 15:01:34,173 - apscheduler.scheduler - DEBUG - base.py:1016 - No jobs; waiting until a job is added
2024-04-24 15:01:34,539 - klippy - DEBUG - klippy.py:249 - JWT token expired, refreshing...
2024-04-24 15:01:34,958 - klippy - ERROR - klippy.py:253 - Unauthorized
2024-04-24 15:01:36,033 - klippy - DEBUG - klippy.py:249 - JWT token expired, refreshing...
2024-04-24 15:01:36,442 - klippy - ERROR - klippy.py:253 - Unauthorized
2024-04-24 15:01:36,448 - klippy - WARNING - klippy.py:485 - Failed adding announcements bot feed.

Unauthorized
2024-04-24 15:01:37,146 - apscheduler.scheduler - INFO - base.py:881 - Added job "WebSocketHelper.reshedule" to job store "default"
2024-04-24 15:01:37,149 - apscheduler.scheduler - DEBUG - base.py:940 - Looking for jobs to run
2024-04-24 15:01:37,153 - apscheduler.scheduler - DEBUG - base.py:1019 - Next wakeup is due at 2024-04-24 15:01:39.144630+03:00 (in 1.992009 seconds)
2024-04-24 15:01:37,183 - websocket_helper - ERROR - websocket_helper.py:80 - Handshake status 401 Unauthorized -+-+- {'server': 'nginx/1.22.1', 'date': 'Wed, 24 Apr 2024 12:01:37 GMT', 'content-type': 'text/html', 'content-length': '179', 'connection': 'keep-alive', 'www-authenticate': 'Basic realm="Go away!"'} -+-+- b'<html>\r\n<head><title>401 Authorization Required</title></head>\r\n<body>\r\n<center><h1>401 Authorization Required</h1></center>\r\n<hr><center>nginx/1.22.1</center>\r\n</body>\r\n</html>\r\n'
2024-04-24 15:01:37,185 - websocket_helper - INFO - websocket_helper.py:73 - WebSocket closed
2024-04-24 15:01:37,187 - __main__ - INFO - main.py:1221 - Exiting! Moonraker connection lost!
2024-04-24 15:01:37,189 - apscheduler.scheduler - INFO - base.py:198 - Scheduler has been shut down

@krawa
Copy link

krawa commented Apr 26, 2024

Current Moonraker telegram bot config
[bot]
server = 192.168.0.107
port = 443
ssl = true
ssl_validate = false
user = kkkk
password = tkertdfgdfg
debug = true

2024-04-24 15:01:33,136 - apscheduler.scheduler - INFO - base.py:166 - Scheduler started
2024-04-24 15:01:33,138 - apscheduler.scheduler - DEBUG - base.py:940 - Looking for jobs to run
2024-04-24 15:01:33,141 - apscheduler.scheduler - DEBUG - base.py:1016 - No jobs; waiting until a job is added
2024-04-24 15:01:34,151 - klippy - ERROR - klippy.py:154 - Unauthorized
2024-04-24 15:01:34,158 - apscheduler.scheduler - INFO - base.py:166 - Scheduler started
2024-04-24 15:01:34,163 - apscheduler.scheduler - DEBUG - base.py:940 - Looking for jobs to run
2024-04-24 15:01:34,173 - apscheduler.scheduler - DEBUG - base.py:1016 - No jobs; waiting until a job is added
2024-04-24 15:01:34,539 - klippy - DEBUG - klippy.py:249 - JWT token expired, refreshing...
2024-04-24 15:01:34,958 - klippy - ERROR - klippy.py:253 - Unauthorized
2024-04-24 15:01:36,033 - klippy - DEBUG - klippy.py:249 - JWT token expired, refreshing...
2024-04-24 15:01:36,442 - klippy - ERROR - klippy.py:253 - Unauthorized
2024-04-24 15:01:36,448 - klippy - WARNING - klippy.py:485 - Failed adding announcements bot feed.

Unauthorized
2024-04-24 15:01:37,146 - apscheduler.scheduler - INFO - base.py:881 - Added job "WebSocketHelper.reshedule" to job store "default"
2024-04-24 15:01:37,149 - apscheduler.scheduler - DEBUG - base.py:940 - Looking for jobs to run
2024-04-24 15:01:37,153 - apscheduler.scheduler - DEBUG - base.py:1019 - Next wakeup is due at 2024-04-24 15:01:39.144630+03:00 (in 1.992009 seconds)
2024-04-24 15:01:37,183 - websocket_helper - ERROR - websocket_helper.py:80 - Handshake status 401 Unauthorized -+-+- {'server': 'nginx/1.22.1', 'date': 'Wed, 24 Apr 2024 12:01:37 GMT', 'content-type': 'text/html', 'content-length': '179', 'connection': 'keep-alive', 'www-authenticate': 'Basic realm="Go away!"'} -+-+- b'<html>\r\n<head><title>401 Authorization Required</title></head>\r\n<body>\r\n<center><h1>401 Authorization Required</h1></center>\r\n<hr><center>nginx/1.22.1</center>\r\n</body>\r\n</html>\r\n'
2024-04-24 15:01:37,185 - websocket_helper - INFO - websocket_helper.py:73 - WebSocket closed
2024-04-24 15:01:37,187 - __main__ - INFO - main.py:1221 - Exiting! Moonraker connection lost!
2024-04-24 15:01:37,189 - apscheduler.scheduler - INFO - base.py:198 - Scheduler has been shut down

Error due to nginx authorization
With a different config, the bot connects to the Moonraker but cannot connect to WebSocket. There need to specify the authorization header

Current Moonraker telegram bot config
[bot]
server = user:[email protected]
api_token: 5f551389d9c94627ab9c
port = 443
ssl = true
ssl_validate = false
debug = true

2024-04-26 12:47:25,898 - __main__ - ERROR - main.py:1196 - Config errors in section [bot]:
  Protocol must be specified in other configuration parameters

2024-04-26 12:47:25,948 - apscheduler.scheduler - INFO - base.py:166 - Scheduler started
2024-04-26 12:47:25,951 - apscheduler.scheduler - DEBUG - base.py:940 - Looking for jobs to run
2024-04-26 12:47:25,955 - apscheduler.scheduler - DEBUG - base.py:1016 - No jobs; waiting until a job is added
2024-04-26 12:47:27,012 - apscheduler.scheduler - INFO - base.py:166 - Scheduler started
2024-04-26 12:47:27,020 - apscheduler.scheduler - DEBUG - base.py:940 - Looking for jobs to run
2024-04-26 12:47:27,029 - apscheduler.scheduler - DEBUG - base.py:1016 - No jobs; waiting until a job is added
2024-04-26 12:47:29,816 - apscheduler.scheduler - INFO - base.py:881 - Added job "WebSocketHelper.reshedule" to job store "default"
2024-04-26 12:47:29,819 - apscheduler.scheduler - DEBUG - base.py:940 - Looking for jobs to run
2024-04-26 12:47:29,821 - apscheduler.scheduler - DEBUG - base.py:1019 - Next wakeup is due at 2024-04-26 12:47:31.815184+03:00 (in 1.993883 seconds)
2024-04-26 12:47:29,849 - websocket_helper - ERROR - websocket_helper.py:80 - Handshake status 401 Unauthorized -+-+- {'server': 'nginx/1.22.1', 'date': 'Fri, 26 Apr 2024 09:47:29 GMT', 'content-type': 'text/html', 'content-length': '179', 'connection': 'keep-alive', 'www-authenticate': 'Basic realm="Go away!"'} -+-+- b'<html>\r\n<head><title>401 Authorization Required</title></head>\r\n<body>\r\n<center><h1>401 Authorization Required</h1></center>\r\n<hr><center>nginx/1.22.1</center>\r\n</body>\r\n</html>\r\n'
2024-04-26 12:47:29,851 - websocket_helper - INFO - websocket_helper.py:73 - WebSocket closed
2024-04-26 12:47:29,853 - __main__ - INFO - main.py:1221 - Exiting! Moonraker connection lost!

@nlef
Copy link
Owner Author

nlef commented Jun 13, 2024

@krawa
nginx authorization together with moonraker authorization is not supported at the moment.
If there is a need for this (although I don't really understand why there are two authorization options at the same time), then please create a separate ticket.
I made a minor fix in parsing json which could lead to problems with authorization.

@nlef nlef merged commit 02df373 into development Jun 19, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Working on dev
Development

Successfully merging this pull request may close these issues.

[Bug]: Moonraker with HTTPS doesn't work
3 participants