From d58745ca2e2700a7489b190a2c514ef4d019a798 Mon Sep 17 00:00:00 2001 From: BJ Dweck Date: Mon, 5 Oct 2020 13:18:22 +0200 Subject: [PATCH] Added support for tor / onion broker hostname --- install-ubuntu2004.sh | 2 +- torch-pub.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/install-ubuntu2004.sh b/install-ubuntu2004.sh index cf41d9b..2685302 100755 --- a/install-ubuntu2004.sh +++ b/install-ubuntu2004.sh @@ -2,7 +2,7 @@ apt update apt install -y tor python3-pip -sudo -H pip3 install stem paho-mqtt +sudo -H pip3 install stem paho-mqtt PySocks sed -i '/^#ControlPort 9051/s/^#//' /etc/tor/torrc sed -i '/^#CookieAuthentication 1/s/^#//' /etc/tor/torrc diff --git a/torch-pub.py b/torch-pub.py index b3db69e..b46c894 100644 --- a/torch-pub.py +++ b/torch-pub.py @@ -2,6 +2,7 @@ from stem.control import Controller import stem.connection import paho.mqtt.client as mqtt import ssl +import socks import configparser configPath = "/etc/torch/" @@ -9,6 +10,7 @@ configPath = "/etc/torch/" config = configparser.ConfigParser() config.read(configPath + "torch.conf") +torProxyPort = config['tor'].getint('ProxyPort', fallback = 9050) torControllerPort = config['tor'].getint('ControllerPort', fallback = 9051) sshPort = config['ssh'].getint('Port', fallback = 22) mqttConfig = config['mqtt'] @@ -47,6 +49,10 @@ if mqttRequireCertificate: keyfile = mqttKeyFile, cert_reqs=ssl.CERT_REQUIRED) +if mqttBrokerHost.endswith(".onion"): + client.proxy_set(proxy_type=socks.SOCKS5, proxy_addr="localhost", proxy_port=torProxyPort) + client.tls_insecure_set(True) + client.connect(mqttBrokerHost, mqttBrokerPort, 60) client.publish(mqttTopic, onionAddress) client.disconnect()