7 Commits
Author SHA1 Message Date
bj 16bbe738a7 Tightened build script 2020-10-08 15:16:53 +02:00
bj 2792dc5e68 Simplfied debian files 2020-10-08 14:51:29 +02:00
bj 03f415499c Migrated over to dh_python and it builds! 2020-10-08 14:30:00 +02:00
bj 005f9b060d Added requirements to setup.py 2020-10-08 12:47:29 +02:00
bj 8c6309eff9 Updated .gitignore 2020-10-08 12:41:50 +02:00
bj fe28ab3246 BUGFIX: main() not found 2020-10-08 12:30:55 +02:00
bj 156370a586 Implemented Python setuptools build structure 2020-10-08 12:22:52 +02:00
17 changed files with 144 additions and 154 deletions
-1
View File
@@ -6,4 +6,3 @@ venv
/*.egg-info /*.egg-info
*.pyc *.pyc
__pycache__ __pycache__
.idea
+8 -16
View File
@@ -13,19 +13,7 @@ A TORch solution consists of 3 processes:
* MQTT broker - Any MQTT broker, reachable via IPv4 or Tor, through TLS or insecure communications * MQTT broker - Any MQTT broker, reachable via IPv4 or Tor, through TLS or insecure communications
* `torch-subscriber` - Listens for and handles onion hostname publications * `torch-subscriber` - Listens for and handles onion hostname publications
## Installation ## Build Debian Package
### Install Package from Rudefox Debian Repo
1. Add the [Rudefox Repo](https://rudefox.io/repo/) as an `apt` source
2. Install the `torch-agent` package
```bash
sudo apt install torch-agent
```
### Build Debian Package from Source
If you don't already have a GPG key, generate one: If you don't already have a GPG key, generate one:
@@ -33,11 +21,11 @@ If you don't already have a GPG key, generate one:
gpg --full-generate-key gpg --full-generate-key
``` ```
Using the e-mail address you provided during GPG key generation, run `build-deb.sh` to build a Debian package and install it Using the e-mail address you provided during GPG key generation, run `make-pkg.sh` to build a Debian package and install it
```bash ```bash
./build-deb.sh [email protected] ./make-pkg.sh [email protected]
apt update && apt install build/torch-agent_0.0.5-1_all.deb apt update && apt install build/torch-agent_0.0.1-1_all.deb
``` ```
This will: This will:
@@ -57,3 +45,7 @@ The configuation directory can be specified by
A fully configured example can be found [here](example) A fully configured example can be found [here](example)
See the sample [`torch.conf`](torch.conf) file for additional configuration options and details See the sample [`torch.conf`](torch.conf) file for additional configuration options and details
## Roadmap
[ ] Utilize [dh_python3](https://www.debian.org/doc/manuals/debmake-doc/ch08.en.html#setup-py) in Debian package build
+17 -18
View File
@@ -1,34 +1,33 @@
#!/bin/bash #!/bin/bash
if [[ -z "${DEB_EMAIL}" ]]; then TORCH_VERSION=$(git describe --tags --abbrev=0)
DEB_EMAIL="$1" PROJECT=torch-agent-$TORCH_VERSION
if [[ -z "${DEBEMAIL}" ]]; then
DEBEMAIL="$1"
fi fi
if [[ -z "${DEB_EMAIL}" ]]; then if [[ -z "${DEBEMAIL}" ]]; then
echo "E-mail address required for packaging signing with gpg key!" echo "E-mail address required for packaging signing with gpg key!"
echo "Usage: ./build-deb.sh EMAIL" echo "Usage: ./build-deb.sh EMAIL"
exit 1 exit 1
fi fi
TORCH_VERSION=$(git describe --tags --abbrev=0)
PROJECT=torch-agent-$TORCH_VERSION
BUILD_DIR=dist BUILD_DIR=dist
DEB_DIR=$BUILD_DIR/$PROJECT DEB_DIR=$BUILD_DIR/$PROJECT
rm -rf "${BUILD_DIR:?}" rm -rf $BUILD_DIR/*
mkdir -p "$DEB_DIR/src/etc/torch"
cp -r debian "$DEB_DIR/"
cp torch.conf "$DEB_DIR/src/etc/torch/"
pip3 install -r requirements.txt
python3 setup.py sdist python3 setup.py sdist
cd $BUILD_DIR || exit mkdir -p $DEB_DIR/src/etc/torch
tar -xzmf "$PROJECT.tar.gz" cp -r debian $DEB_DIR/
cp torch.conf $DEB_DIR/src/etc/torch/
cd "$PROJECT" || exit cd $BUILD_DIR
export USER tar -xzmf $PROJECT.tar.gz
USER=$(whoami)
dh_make --createorig -e "$DEB_EMAIL" -s -y cd $PROJECT
dpkg-buildpackage -k"$DEB_EMAIL" export USER=`whoami`
dh_make --createorig -e $DEBEMAIL -s -y
dpkg-buildpackage -k$DEBEMAIL
+3 -3
View File
@@ -1,5 +1,5 @@
torch-agent (0.0.5-1) stable; urgency=medium torch-agent (0.0.1-1) unstable; urgency=medium
* Update * Initial release
-- Benjamin Dweck <[email protected]> Tue, 08 Oct 2020 19:46:22 +0200 -- Benjamin Dweck <[email protected]> Tue, 06 Oct 2020 15:53:02 +0200
+2
View File
@@ -0,0 +1,2 @@
torch-agent_0.0.1-1_all.deb net optional
torch-agent_0.0.1-1_amd64.buildinfo net optional
-2
View File
@@ -53,8 +53,6 @@ case "$1" in
useradd -r -g $GROUP $USER useradd -r -g $GROUP $USER
fi fi
sudo -H pip3 install 'paho-mqtt>=1.5.1'
chown $USER /etc/torch chown $USER /etc/torch
chown $USER /etc/torch/torch.conf chown $USER /etc/torch/torch.conf
-1
View File
@@ -1 +0,0 @@
OthermoduleName python-othermodule; PEP386
+9
View File
@@ -35,6 +35,15 @@ In a separate terminal window, run the subscriber:
#### Run TORch Agent in Vagrant #### Run TORch Agent in Vagrant
[Build](..) the latest source into a Debian package and copy it to `example/`
```bash
cd ..
./make-pkg.sh [email protected]
cp -f build/torch-agent_0.0.1-1_all.deb example/
cd example
```
Run the Vagrant box in a third terminal window: Run the Vagrant box in a third terminal window:
```bash ```bash
+2 -4
View File
@@ -64,6 +64,7 @@ Vagrant.configure("2") do |config|
# Ansible, Chef, Docker, Puppet and Salt are also available. Please see the # Ansible, Chef, Docker, Puppet and Salt are also available. Please see the
# documentation for more information about their specific syntax and use. # documentation for more information about their specific syntax and use.
config.vm.provision "file", source: "torch-agent_0.0.1-1_all.deb", destination: "~/"
config.vm.provision "file", source: "agent-config", destination: "~/torch-conf" config.vm.provision "file", source: "agent-config", destination: "~/torch-conf"
config.vm.provision "shell", inline: <<-SHELL config.vm.provision "shell", inline: <<-SHELL
@@ -71,10 +72,7 @@ Vagrant.configure("2") do |config|
sudo -- sh -c "echo '10.0.2.2 mqtt.example.com' >> /etc/hosts" sudo -- sh -c "echo '10.0.2.2 mqtt.example.com' >> /etc/hosts"
sudo apt update sudo apt update
wget -qO - https://rudefox.io/repo/gpg | sudo apt-key add sudo apt install -y ./torch-agent_0.0.1-1_all.deb
sudo add-apt-repository "deb https://repo.rudefox.io/repository/apt-release focal main"
sudo apt update
sudo apt install -y torch-agent
sudo cp -f torch-conf/* /etc/torch/ sudo cp -f torch-conf/* /etc/torch/
sudo chown -R torch /etc/torch sudo chown -R torch /etc/torch
Binary file not shown.
-3
View File
@@ -1,3 +0,0 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
+4 -5
View File
@@ -1,6 +1,5 @@
pip~=20.2.4 wheel>=0.35.1
setuptools~=50.3.2 setuptools>=44.0.0
stdeb3~=0.9.0.post2
paho-mqtt~=1.5.1
stem>=1.8.0 stem>=1.8.0
PySocks paho-mqtt>=1.5.1
PySocks>=1.7.1
-25
View File
@@ -1,25 +0,0 @@
[metadata]
name = torch-agent
version = attr: torch_agent.__version__
author = Benjamin Dweck
author_email = [email protected]
description = TORch: Illuminate the Way to your Node
url = https://git.rudefox.io/bj/torch-agent
classifiers =
Programming Language :: Python :: 3
License :: OSI Approved :: MIT License
[options]
packages = find:
install_requires =
paho-mqtt~=1.5.1
setuptools~=50.3.1
pip~=20.2.3
stem
PySocks
[options.entry_points]
console_scripts = torch-agent=torch_agent.torch_agent:main
[options.packages.find]
exclude=test
+28 -1
View File
@@ -1,4 +1,31 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import setuptools import setuptools
setuptools.setup() with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name="torch-agent",
version="0.0.1",
author="B.J. Dweck",
author_email="[email protected]",
description="TORch: Iluminate the Way to your Node",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://git.rudefox.io/bj/torch-agent",
packages=setuptools.find_packages(),
install_requires=[
'stem',
'paho-mqtt',
'PySocks',
],
entry_points = {
'console_scripts': ['torch-agent=torch_agent.torch_agent:main'],
},
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
],
python_requires='>=3.6',
)
+1 -4
View File
@@ -6,10 +6,7 @@ ControllerPort = 9051
Port = 22 Port = 22
[mqtt] [mqtt]
BrokerHost = mqtt.example.com # OR example1i3uyrbfoi3fi.onion
BrokerHost = mqtt.example.com
#BrokerHost = example1i3uyrbfoi3fi.onion
BrokerPort = 1883 BrokerPort = 1883
ClientID = my-client ClientID = my-client
Topic = example/topic Topic = example/topic
+1 -1
View File
@@ -1 +1 @@
__version__ = "0.0.5" __version__ = "0.0.1"
+38 -39
View File
@@ -1,8 +1,8 @@
from stem.control import Controller from stem.control import Controller
import stem.connection import stem.connection
import paho.mqtt.client as mqtt import paho.mqtt.client as mqtt
import socks
import ssl import ssl
import socks
import socket import socket
import json import json
import configparser import configparser
@@ -10,7 +10,6 @@ import argparse
from datetime import datetime from datetime import datetime
from os import environ from os import environ
def main(): def main():
parser = argparse.ArgumentParser(description='Broadcast SSH hidden service hostname via MQTT') parser = argparse.ArgumentParser(description='Broadcast SSH hidden service hostname via MQTT')
@@ -19,79 +18,79 @@ def main():
args = parser.parse_args() args = parser.parse_args()
config_path = args.configPath configPath = args.configPath
if "TORCH_CONFIG_DIR" in environ: if "TORCH_CONFIG_DIR" in environ:
config_path = environ.get("TORCH_CONFIG_DIR") configPath = environ.get("TORCH_CONFIG_DIR")
if not config_path.endswith("/"): if not configPath.endswith("/"):
config_path = config_path + "/" configPath = configPath + "/"
print("Using torch configuration path: " + config_path) print("Using torch configuration path: " + configPath)
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read(config_path + "torch.conf") config.read(configPath + "torch.conf")
tor_proxy_port = config['tor'].getint('ProxyPort', fallback=9050) torProxyPort = config['tor'].getint('ProxyPort', fallback = 9050)
tor_controller_port = config['tor'].getint('ControllerPort', fallback=9051) torControllerPort = config['tor'].getint('ControllerPort', fallback = 9051)
ssh_port = config['ssh'].getint('Port', fallback=22) sshPort = config['ssh'].getint('Port', fallback = 22)
mqtt_config = config['mqtt'] mqttConfig = config['mqtt']
mqtt_broker_host = mqtt_config.get('BrokerHost', fallback="localhost") mqttBrokerHost = mqttConfig.get('BrokerHost', fallback = "localhost")
mqtt_broker_port = mqtt_config.getint('BrokerPort', fallback=1883) mqttBrokerPort = mqttConfig.getint('BrokerPort', fallback = 1883)
client_id = mqtt_config.get('ClientID', fallback=socket.gethostname()) clientID = mqttConfig.get('ClientID', fallback = socket.gethostname())
mqtt_topic = mqtt_config.get('Topic', fallback="torch/%s/onion_url" % client_id) mqttTopic = mqttConfig.get('Topic', fallback = "torch/%s/onion_url" % (clientID))
mqtt_require_certificate = mqtt_config.getboolean( mqttRequireCertificate = mqttConfig.getboolean(
'RequireCertificate', 'RequireCertificate',
fallback = False) fallback = False)
mqtt_ca_file = config_path + mqtt_config.get('CaFile') mqttCaFile = configPath + mqttConfig.get('CaFile')
mqtt_cert_file = config_path + mqtt_config.get('CertFile') mqttCertFile = configPath + mqttConfig.get('CertFile')
mqtt_key_file = config_path + mqtt_config.get('KeyFile') mqttKeyFile = configPath + mqttConfig.get('KeyFile')
with Controller.from_port(port=tor_controller_port) as controller: with Controller.from_port(port = torControllerPort) as controller:
protocol_info = stem.connection.get_protocolinfo(controller) protocolInfo = stem.connection.get_protocolinfo(controller)
stem.connection.authenticate_safecookie( stem.connection.authenticate_safecookie(
controller, controller,
protocol_info.cookie_path) protocolInfo.cookie_path)
print("Connected to Tor on port %s" % tor_controller_port) print("Connected to Tor on port %s" % (torControllerPort))
service = controller.create_ephemeral_hidden_service(ssh_port, detached=True) service = controller.create_ephemeral_hidden_service(sshPort, detached = True)
onion_address = "%s.onion" % service.service_id onionAddress = "%s.onion" % (service.service_id)
print("Created Tor Hidden Service for local port %s at %s" % (ssh_port, onion_address)) print("Created Tor Hidden Service for local port %s at %s" % (sshPort, onionAddress))
payload = { payload = {
'clientId': client_id, 'clientId': clientID,
'timestamp': datetime.now().strftime("%d-%b-%Y (%H:%M:%S.%f)"), 'timestamp': datetime.now().strftime("%d-%b-%Y (%H:%M:%S.%f)"),
'onionAddress': onion_address, 'onionAddress': onionAddress,
'sshPort': ssh_port 'sshPort': sshPort
} }
client = mqtt.Client() client = mqtt.Client()
protocol = "mqtt" protocol = "mqtt"
if mqtt_require_certificate: if mqttRequireCertificate:
client.tls_set( client.tls_set(
ca_certs=mqtt_ca_file, ca_certs = mqttCaFile,
certfile=mqtt_cert_file, certfile = mqttCertFile,
keyfile=mqtt_key_file, keyfile = mqttKeyFile,
cert_reqs=ssl.CERT_REQUIRED) cert_reqs=ssl.CERT_REQUIRED)
protocol = "mqtts" protocol = "mqtts"
if mqtt_broker_host.endswith(".onion"): if mqttBrokerHost.endswith(".onion"):
client.proxy_set(proxy_type=socks.SOCKS5, proxy_addr="localhost", proxy_port=tor_proxy_port) client.proxy_set(proxy_type=socks.SOCKS5, proxy_addr="localhost", proxy_port=torProxyPort)
client.tls_insecure_set(True) client.tls_insecure_set(True)
client.connect(mqtt_broker_host, mqtt_broker_port, 60) client.connect(mqttBrokerHost, mqttBrokerPort, 60)
client.publish(mqtt_topic, json.dumps(payload)) client.publish(mqttTopic, json.dumps(payload))
print("Connected to MQTT Broker at %s://%s:%s/%s" % (protocol, mqtt_broker_host, mqtt_broker_port, mqtt_topic)) print("Connected to MQTT Broker at %s://%s:%s/%s" % (protocol, mqttBrokerHost, mqttBrokerPort, mqttTopic))
print("Published payload: " + json.dumps(payload)) print("Published payload: " + json.dumps(payload))
client.disconnect() client.disconnect()