Skip to content
This repository was archived by the owner on May 13, 2022. It is now read-only.

Commit 616eaa6

Browse files
committed
newnym on every reconnect and assorted config options
further obfuscate the long term identity of a bot
1 parent 816242d commit 616eaa6

2 files changed

Lines changed: 42 additions & 3 deletions

File tree

joinmarket/configure.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,16 @@ def jm_single():
116116
socks5_host = localhost
117117
socks5_port = 9050
118118
#for tor
119-
#host = 6dvj6v5imhny3anf.onion
119+
#newnym = true
120+
#newnym_delay = 60
121+
#tor_host = localhost
122+
#tor_port = 9051
123+
#tor_pass =
120124
#port = 6697
121125
#usessl = true
122126
#socks5 = true
123127
maker_timeout_sec = 30
128+
reconnect_delay = 30
124129
125130
[POLICY]
126131
# for dust sweeping, try merge_algorithm = gradual

joinmarket/irc.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import time
99
import Queue
1010

11+
from ConfigParser import NoOptionError
1112
from joinmarket.configure import jm_single, get_config_irc_channel
1213
from joinmarket.message_channel import MessageChannel, CJPeerError
1314
from joinmarket.enc_wrapper import encrypt_encode, decode_decrypt
@@ -497,8 +498,9 @@ def __handle_line(self, line):
497498
if self.on_nick_leave:
498499
self.on_nick_leave(nick)
499500
elif _chunks[1] == '433': # nick in use
500-
# self.nick = random_nick()
501501
self.nick += '_' # helps keep identity constant if just _ added
502+
if self.newnyms:
503+
self.nick = random_nick()
502504
self.send_raw('NICK ' + self.nick)
503505
if self.password:
504506
if _chunks[1] == 'CAP':
@@ -583,13 +585,39 @@ def __init__(self,
583585
self.socks5_port = int(config.get("MESSAGING", "socks5_port"))
584586
self.channel = get_config_irc_channel()
585587
self.userrealname = (username, realname)
588+
self.reconnect_delay = 30
589+
self.newnyms = False
590+
try:
591+
self.reconnect_delaty = int(config.get("MESSAGING", "reconnect_delay"))
592+
self.newnyms = (config.get("MESSAGING", "newnym").lower() == 'true')
593+
self.tor_host = config.get("MESSAGING", "tor_host")
594+
self.tor_port = int(config.get("MESSAGING", "tor_port"))
595+
self.tor_pass = config.get("MESSAGING", "tor_pass")
596+
self.newnym_delay = int(config.get("MESSAGING", "newnym_delay"))
597+
except NoOptionError as ex:
598+
log.debug('The following newnym option is missing:')
599+
log.debug(ex)
600+
log.debug('.. disabling the feature.')
601+
self.newnyms = False
586602
if password and len(password) == 0:
587603
password = None
588604
self.given_password = password
589605
self.pingQ = Queue.Queue()
590606
self.throttleQ = Queue.Queue()
591607
self.obQ = Queue.Queue()
592608

609+
def newnym(self):
610+
ctrl = socket.create_connection((self.tor_host, self.tor_port))
611+
ctrl.send('AUTHENTICATE "%s"\r\n'%self.tor_pass)
612+
resp = ctrl.recv(1024)
613+
if resp.startswith('250'):
614+
ctrl.send("signal NEWNYM\r\n")
615+
if resp.startswith('250'):
616+
ctrl.close()
617+
return
618+
ctrl.close()
619+
raise IOError("newnym failed "+resp)
620+
593621
def run(self):
594622
self.waiting = {}
595623
self.built_privmsg = {}
@@ -604,6 +632,10 @@ def run(self):
604632
try:
605633
config = jm_single().config
606634
log.debug('connecting')
635+
if self.newnyms:
636+
log.debug("Grabbing new Tor identity")
637+
self.newnym()
638+
self.nick = random_nick()
607639
if config.get("MESSAGING", "socks5").lower() == 'true':
608640
log.debug("Using socks5 proxy %s:%d" %
609641
(self.socks5_host, self.socks5_port))
@@ -649,6 +681,8 @@ def run(self):
649681
self.on_disconnect()
650682
log.debug('disconnected irc')
651683
if not self.give_up:
652-
time.sleep(30)
684+
time.sleep(self.reconnect_delay)
685+
if self.newnyms:
686+
time.sleep(random.randint(0,self.newnym_delay))
653687
log.debug('ending irc')
654688
self.give_up = True

0 commit comments

Comments
 (0)