Ssl optioneel gemaakt

This commit is contained in:
Marcel Nijenhof
2019-02-12 22:00:49 +01:00
parent 46302706bf
commit 79042070b3

View File

@@ -82,25 +82,29 @@ Opens the connection and logs in
connects to lmw with tcp using the values of the object creation. connects to lmw with tcp using the values of the object creation.
""" """
self._context = ssl.create_default_context()
self._context.check_hostname = self.check_ssl
self._tcp = socket.create_connection((self.host, self.port)) self._tcp = socket.create_connection((self.host, self.port))
self._ssl = self._context.wrap_socket(self._tcp, if (self.ssl):
self._context = ssl.create_default_context()
self._context.check_hostname = self.check_ssl
self._ssl = self._context.wrap_socket(self._tcp,
server_hostname=self.host) server_hostname=self.host)
self._socket = self._ssl
else:
self._socket = self._tcp
def send(self, sipcmd): def send(self, sipcmd):
"""send(sipcmd) """send(sipcmd)
send a sip command to the server send a sip command to the server
""" """
self._ssl.sendall(sipcmd.encode('ascii')) self._socket.sendall(sipcmd.encode('ascii'))
def recv(self): def recv(self):
"""recv() """recv()
recieve a answer from the sip server recieve a answer from the sip server
""" """
return(self._ssl.recv()) return(self._socket.recv())
def login(self): def login(self):
"""login() """login()