Добавление поддержки SSL в SocketServerPython

Программы на Python
Гость
Добавление поддержки SSL в SocketServer

Сообщение Гость »


У меня есть Сервер на базе

Код: Выделить всё

ThreadingTCPServer
. Now Ii want to add SSL Support to that Server.
Without SSL it works fine but with SSLv3 I cant connect a Client to the Server, it always throws an exception:

Код: Выделить всё

Error 111 Connection Refused
. The error mens there's no SSL Server on that port.

I added the SSL Support based on an example I found here at Stackoverflow.
Here's my code:

Server:

Код: Выделить всё

class BeastServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):

def __init__(self, server_address, RequestHandlerClass, bind_and_activate=True):
SocketServer.BaseServer.__init__(self, server_address,
RequestHandlerClass)
ctx = SSL.Context(SSL.SSLv3_METHOD)
cert = 'server.pem'
key = 'key.pem'
ctx.use_privatekey_file(key)
ctx.use_certificate_file(cert)
self.socket = SSL.Connection(ctx, socket.socket(self.address_family,
self.socket_type))
if bind_and_activate:
#self.server_bind()
#self.server_a
Client:

Код: Выделить всё

class Client(object) :

def verbinden (self, ip_) :

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ssl_sock = ssl.wrap_socket(s, cert_reqs=ssl.CERT_REQUIRED,
ssl_version=ssl.PROTOCOL_SSLv3, ca_certs='server.pem')
ssl_sock.connect((ip_, 10012))

return ssl_sock
The key and certificate file is created using open SSL.
I hope somebody can tell me what the problem is.

thanks for your help

best regards patrick


Источник: https://stackoverflow.com/questions/858 ... cketserver

Вернуться в «Python»