/
sex_chat.py
executable file
·90 lines (70 loc) · 2.53 KB
/
sex_chat.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python
import logging
import getpass
import ssl
from optparse import OptionParser
from sleekxmpp import ClientXMPP
from sleekxmpp.xmlstream import JID
from xmpp_sex import XMMPPSex
from box import Box
class SexSnd(ClientXMPP):
def __init__(self, jid, password, recipient):
ClientXMPP.__init__(self, jid, password)
self.recipient = recipient
self.add_event_handler("session_start", self.session_start, threaded=True)
self.add_event_handler("message", self.message)
self.ssl_version = ssl.PROTOCOL_TLS
self.xmppSex = XMMPPSex(jid)
def session_start(self, event):
self.send_presence()
while (True):
message = input("Message: ")
stanza = self.make_message(mto=self.recipient, mbody='Voulez vous coucher avec moi?', mtype='chat')
nonce, box = self.xmppSex.encryptTo(self.recipient, "<body>{}</body>".format(message));
stanza['box'].set_nonce(nonce)
stanza['box'].set_box(box)
stanza.send()
def message(self, msg):
if msg['type'] in ('chat', 'normal'):
print(msg)
print("Body: {}".format(msg['body']))
jid = JID(msg['from']).bare
nonce = msg['box'].get_nonce()
box = msg['box'].get_box()
print("Nonce: {}".format(nonce))
print("Box: {}".format(box))
cleartext = self.xmppSex.decryptFrom(jid, box, nonce)
print("Cleartext: {}\n".format(cleartext))
if __name__ == '__main__':
optp = OptionParser()
# Output verbosity options.
optp.add_option('-q', '--quiet', help='set logging to ERROR',
action='store_const', dest='loglevel',
const=logging.ERROR, default=logging.INFO)
optp.add_option('-d', '--debug', help='set logging to DEBUG',
action='store_const', dest='loglevel',
const=logging.DEBUG, default=logging.INFO)
optp.add_option('-v', '--verbose', help='set logging to COMM',
action='store_const', dest='loglevel',
const=5, default=logging.INFO)
# JID and password options.
optp.add_option("-j", "--jid", dest="jid",
help="JID to use")
optp.add_option("-p", "--password", dest="password",
help="password to use")
# recipient option
optp.add_option("-r", "--recipient", dest="recipient",
help="JID of recipient")
opts, args = optp.parse_args()
# Setup logging.
logging.basicConfig(level=opts.loglevel,
format='%(levelname)-8s %(message)s')
if opts.jid is None:
opts.jid = input("Username: ")
if opts.password is None:
opts.password = getpass.getpass("Password: ")
if opts.recipient is None:
opts.recipient = input("Recipient: ")
xmpp = SexSnd(opts.jid, opts.password, opts.recipient)
xmpp.connect()
xmpp.process(block=True)