secure socket wieder in try-except; finally-klauses wieder raus

This commit is contained in:
example 2022-08-03 17:58:27 +02:00
parent 991eeea9f8
commit 6bd34360a6

View file

@ -379,9 +379,9 @@ def main():
ClientSocket, ClientAddress = MySocket.accept() ClientSocket, ClientAddress = MySocket.accept()
logging.info('Client connected: {}:{}'.format(ClientAddress[0], ClientAddress[1])) logging.info('Client connected: {}:{}'.format(ClientAddress[0], ClientAddress[1]))
# die verbindung in den ssl-context verpacken => Connection # die verbindung in den ssl-context verpacken => Connection
with context.wrap_socket(ClientSocket, server_side=True) as Connection:
logging.info('SSL Connection established')
try: try:
Connection = context.wrap_socket(ClientSocket, server_side=True)
logging.info('SSL Connection established')
Connection.settimeout(float(config['general']['timeout'])) Connection.settimeout(float(config['general']['timeout']))
logging.debug('Connection timeout set to {}'.format(config['general']['timeout'])) logging.debug('Connection timeout set to {}'.format(config['general']['timeout']))
cert = Connection.getpeercert(binary_form=False) cert = Connection.getpeercert(binary_form=False)
@ -410,13 +410,16 @@ def main():
Connection.close() Connection.close()
except KeyboardInterrupt: except KeyboardInterrupt:
logging.info('Keyboard interrupt received') logging.info('Keyboard interrupt received')
sys.exit(255)
except Exception as e:
logging.error('{}'.format(e))
finally:
if MySocket: if MySocket:
MySocket.close() MySocket.close()
logging.debug('TCP socket closed') logging.debug('TCP socket closed')
sys.exit(255)
except Exception as e:
logging.error('{}'.format(e))
if MySocket:
MySocket.close()
logging.debug('TCP socket closed')
sys.exit(254)
if __name__ == '__main__': if __name__ == '__main__':