-
Notifications
You must be signed in to change notification settings - Fork 3
/
mumble_client.py
48 lines (34 loc) · 1.31 KB
/
mumble_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from twisted.internet import ssl, reactor, protocol
class MumbleClientFactory(protocol.ClientFactory):
protocol = None
def __init__(self, protocol, nickname, password):
self.nickname = nickname
self.password = password
self.protocol = protocol
def clientConnectionFailed(self, connector, reason):
print "Connection failed"
reactor.stop()
def clientConnectionLost(self, connector, reason):
print "Connection lost"
reactor.stop()
def load_certificate(cert_file):
from OpenSSL import crypto, SSL
p12 = crypto.load_pkcs12(file(cert_file, 'rb').read())
class CtxFactory(ssl.ClientContextFactory):
def getContext(self):
self.method = SSL.SSLv23_METHOD
ctx = ssl.ClientContextFactory.getContext(self)
ctx.use_certificate(p12.get_certificate())
ctx.use_privatekey(p12.get_privatekey())
return ctx
return CtxFactory
def create_client(protocol, user, pw=""):
return MumbleClientFactory(protocol, user, pw)
def start_client(factory, ip, port, certificate=None):
# Loads certificate if available
if certificate:
ctx = load_certificate(certificate)
else:
ctx = ssl.ClientContextFactory
reactor.connectSSL(ip, port, factory, ctx())
reactor.run()