mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-12-22 22:45:09 +01:00
raise error instead of quietly exiting on bad SSL cert
This commit is contained in:
parent
15501e185b
commit
65177e791f
1 changed files with 10 additions and 5 deletions
|
@ -6,6 +6,7 @@ This module contains the class BotEventHandler, which tries to make creating
|
|||
Telegram Bots intuitive!
|
||||
"""
|
||||
import logging
|
||||
import os
|
||||
import ssl
|
||||
from threading import Thread
|
||||
from time import sleep
|
||||
|
@ -180,8 +181,11 @@ class BotEventHandler:
|
|||
|
||||
# Check SSL-Certificate with openssl, if possible
|
||||
try:
|
||||
DEVNULL = open(os.devnull, 'wb')
|
||||
exit_code = subprocess.call(["openssl", "x509", "-text", "-noout",
|
||||
"-in", cert])
|
||||
"-in", cert],
|
||||
stdout=DEVNULL,
|
||||
stderr=subprocess.STDOUT)
|
||||
except OSError:
|
||||
exit_code = 0
|
||||
|
||||
|
@ -191,12 +195,13 @@ class BotEventHandler:
|
|||
certfile=cert,
|
||||
keyfile=key,
|
||||
server_side=True)
|
||||
self.httpd.serve_forever(poll_interval=1)
|
||||
except ssl.SSLError as error:
|
||||
self.logger.error(str(error))
|
||||
return
|
||||
|
||||
self.httpd.serve_forever(poll_interval=1)
|
||||
self.logger.info('Event Handler thread stopped')
|
||||
finally:
|
||||
self.logger.info('Event Handler thread stopped')
|
||||
else:
|
||||
raise TelegramError('SSL Certificate invalid')
|
||||
|
||||
def stop(self):
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue