Added support for tor / onion broker hostname

This commit is contained in:
B.J. Dweck 2020-10-05 13:18:22 +02:00
parent de6ac8a1ff
commit d58745ca2e
2 changed files with 7 additions and 1 deletions

View File

@ -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

View File

@ -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()