Skip to content

Commit 2c2650b

Browse files
author
standard
committed
Utilize direct bind options instead of tor control port per boldsuck's suggestion
Create a script to automatically generate a new hidden service address for haveno to utilize Update README.md
1 parent f4d2481 commit 2c2650b

File tree

3 files changed

+91
-40
lines changed

3 files changed

+91
-40
lines changed

scripts/install_qubes/README.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
# Haveno AppVM install on Qubes
1+
# qubes-haveno-appvm
2+
dom0 script to create a haveno appvm
23

3-
1. Download haveno-qubes-install.sh to dom0
4-
2. chmod +x haveno-qubes-install.sh
5-
3. ./haveno-qubes-install.sh [options]
6-
7-
### If you wish to trade on mainnet make sure to specify a unoffical git repo url with -r
84
# Usage
95
./haveno-qubes-install.sh [options]
6+
107
-c : Reinstall template if already exists
118
-s : Build haveno from source instead of deb package
129
-r [git repo url] : Install an unoffical haveno fork hosted at the suppplied web url
1310
-u : Do not harden appVM
1411
-f [compressed haveno deb] : Specify release asset that contains zipped haveno deb (default: haveno-linux-deb.zip)
1512
-n [appVM name] : Name of haveno appvm (default: haveno)
13+
`
14+
# Functionality
15+
Allows for automatic creation of a haveno AppVM based on debian-12-minimal template. Ensures tor over tor is not occuring when using haveno, instead utilizing haveno's direct bind address option. Performs hardening and minimzes the attack surface of the vm by default. Allows for install of unoffical haveno clients for easy access to mainnet trading.
16+
17+
# Changing hidden service address used by haveno
18+
./refresh-haveno-address.sh
19+
20+
-n [HAVENOVM_NAME] : (optional: default haveno)
21+
-h : print help message
1622

1723
# Functionality
18-
Allows for automatic creation of a haveno AppVM based on debian-12-minimal template. Ensures tor over tor is not occuring when using haveno. Performs hardening and minimzes the attack surface of the vm by default. Allows for install of unoffical haveno clients for easy access to mainnet trading.
24+
This script will cause sys-whonix to generate a new hidden service address for haveno to utilize and automatically update the haveno vm to utilize it.

scripts/install_qubes/haveno-qubes-install.sh

Lines changed: 56 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#!/bin/bash
22

3-
#set -e
3+
set -e
44
APPVM_NAME="haveno"
5-
TPL_ROOT="qvm-run --pass-io -u root -- $APPVM_NAME"
65

76
#Options
87
clean=1
@@ -45,8 +44,7 @@ while getopts 'csauhn:r:f:' flag; do
4544
exit 1
4645
fi
4746
;;
48-
n) APPVM_NAME=${OPTARG}
49-
TPL_ROOT="qvm-run --pass-io -u root -- $APPVM_NAME" ;;
47+
n) APPVM_NAME=${OPTARG} ;;
5048
*) print_usage
5149
exit 1 ;;
5250
esac
@@ -58,6 +56,8 @@ if ! [[ $unoffical -eq 0 ]] ; then
5856
log "WARNING : you are installing the main haveno-dex repo but have no enabled build from source, as such this setting has been automatically toggled"
5957
fi
6058

59+
TPL_ROOT="qvm-run --pass-io -u root -- $APPVM_NAME"
60+
6161
if [ "$(hostname)" != "dom0" ]; then
6262
echo "This script must be ran on dom0 to function"
6363
exit 1;
@@ -80,13 +80,14 @@ log "cloning the template"
8080
qvm-clone debian-12-minimal "$APPVM_NAME"
8181
log "Installing necessary packages on template"
8282
$TPL_ROOT "apt-get update && apt-get full-upgrade -y"
83-
$TPL_ROOT "apt-get install --no-install-recommends qubes-core-agent-networking qubes-core-agent-nautilus nautilus zenity curl -y && poweroff" || true
83+
$TPL_ROOT "apt-get install --no-install-recommends qubes-core-agent-networking qubes-core-agent-passwordless-root qubes-core-agent-nautilus nautilus zenity curl -y && poweroff" || true
8484
log "Setting $APPVM_NAME network to sys-whonix"
8585
qvm-prefs $APPVM_NAME netvm sys-whonix
8686

8787
#prevents qrexec error by sleeping
8888
sleep 5
8989
SYS_WHONIX_IP="$(qvm-prefs sys-whonix ip)"
90+
9091
$TPL_ROOT "echo 'nameserver $SYS_WHONIX_IP' > /etc/resolv.conf"
9192

9293
log "Testing for successful sys-whonix config"
@@ -97,13 +98,34 @@ else
9798
log "sys-whonix connection success, traffic is being routed through tor"
9899
fi
99100

101+
log "Cleaning any previous haveno hidden service on sys-whonix"
102+
qvm-run --pass-io -u root -- sys-whonix "rm -rf /var/lib/tor/haveno_service"
103+
log "Creating a hidden service for haveno on whonix gateway"
104+
read -p "Warning by default 50_user.conf on sys-whonix will be overwritten (baseline is empty
105+
Enter any character to append instead (may require cleaning if you reinstall haveno later" -n 1 cont
106+
if ! [[ "$key" = "" ]];then
107+
log "Appending to 50_user.conf instead of overwriting"
108+
out=">>"
109+
else
110+
log "Overwriting 50_user.conf"
111+
out=">"
112+
fi
113+
qvm-run --pass-io -u root -- sys-whonix "echo -e 'ConnectionPadding 1\nHiddenServiceDir /var/lib/tor/haveno_service/\nHiddenServicePort 9999 $(qvm-prefs $APPVM_NAME ip):9999' $out /usr/local/etc/torrc.d/50_user.conf && service tor@default reload"
114+
115+
log "Open port 9999 on $APPVM_NAME to allow incoming peer data"
116+
$TPL_ROOT "echo -e 'nft add rule ip qubes input tcp dport 9999 counter accept\necho nameserver $SYS_WHONIX_IP > /etc/resolv.conf' > /rw/config/rc.local"
117+
118+
sleep 1
119+
SERVICE="$(qvm-run --pass-io -u root -- sys-whonix 'cat /var/lib/tor/haveno_service/hostname')"
120+
121+
$TPL_ROOT "echo $SERVICE > /root/haveno-service-address"
100122

101123
version="$($TPL_ROOT curl -Ls -o /dev/null -w %{url_effective} $HAVENO_REPO/releases/latest)"
102124
version=${version##*/}
103125

104126
if [[ $from_source -eq 1 ]]; then
105127
log "Downloading haveno release version $version"
106-
$TPL_ROOT "curl -Ls --remote-name-all $HAVENO_REPO/releases/download/$version/{$TARGET_DEB,$TARGET_DEB.sig,$version-hashes.txt}"
128+
$TPL_ROOT "curl -L --remote-name-all $HAVENO_REPO/releases/download/$version/{$TARGET_DEB,$TARGET_DEB.sig,$version-hashes.txt}"
107129
read -p "Enter url to verify signatures or anything else to skip:" key
108130
if [[ $key =~ $regex ]]; then
109131
$TPL_ROOT "apt-get install --no-install-recommends gnupg2 -y"
@@ -114,18 +136,18 @@ if [[ $from_source -eq 1 ]]; then
114136
log "Signature invalid, exiting"
115137
exit 1;
116138
fi
117-
fi
118139

119140
log "Verifying SHA-512"
120141
release_sum=$($TPL_ROOT grep -A 1 "$TARGET_DEB" $version-hashes.txt | tail -n1 | tr -d '\n\r')
121142
log "sha512sum of $TARGET_DEB according to release: $release_sum"
122143
formated="$release_sum $TARGET_DEB"
123144
check=$($TPL_ROOT "echo $formated | sha512sum -c")
124-
if [[ "$check" =~ "OK" ]]; then
125-
log "sha512sums match, continuing"
126-
else
127-
log "sha512sums don't match, exiting"
128-
exit 1;
145+
if [[ "$check" =~ "OK" ]]; then
146+
log "sha512sums match, continuing"
147+
else
148+
log "sha512sums don't match, exiting"
149+
exit 1;
150+
fi
129151
fi
130152
# xdg-utils workaround
131153
$TPL_ROOT "mkdir /usr/share/desktop-directories/"
@@ -138,14 +160,28 @@ if [[ $from_source -eq 1 ]]; then
138160
patched_app_entry="[Desktop Entry]
139161
Name=Haveno
140162
Comment=Haveno through sys-whonix
141-
Exec=/usr/local/sbin/Haveno
163+
Exec=sudo /bin/Haveno
142164
Icon=/opt/haveno/lib/Haveno.png
143165
Terminal=false
144166
Type=Application
145167
Categories=Network
146168
MimeType="
147-
$TPL_ROOT "echo -e '#\x21/bin/sh\n\n/opt/haveno/bin/Haveno --useTorForXmr=OFF --torControlPort=9051 --torControlHost=$SYS_WHONIX_IP' > /usr/local/sbin/Haveno && chmod +x /usr/local/sbin/Haveno && chmod u+s /usr/local/sbin/Haveno"
169+
$TPL_ROOT "echo -e '#\x21/bin/sh\n\n#Proxying to gateway (anon-ws-disable-stacked-tor)\nsocat TCP-LISTEN:9050,fork,bind=127.0.0.1 TCP:$SYS_WHONIX_IP:9050 &\nPID=\x24\x21\nSERVICE=\x24\x28cat /root/haveno-service-address\x29\n\n/opt/haveno/bin/Haveno --useTorForXmr=OFF --nodePort=9999 --hiddenServiceAddress=\x24SERVICE\nkill \x24PID' > /bin/Haveno && chmod +x /bin/Haveno && chmod u+s /bin/Haveno"
148170

171+
elif [[ $from_source -eq 0 ]]; then
172+
log "Installing required packages for build"
173+
$TPL_ROOT "apt-get install --no-install-recommends make wget git zip unzip libxtst6 qubes-core-agent-passwordless-root -y"
174+
log "Installing jdk 21"
175+
$TPL_ROOT "curl -s https://get.sdkman.io | bash"
176+
$TPL_ROOT "source /root/.sdkman/bin/sdkman-init.sh && sdk install java 21.0.2.fx-librca"
177+
log "Checking out haveno repo"
178+
CODE_DIR="$(basename $HAVENO_REPO)"
179+
$TPL_ROOT "git clone $HAVENO_REPO"
180+
$TPL_ROOT "source ~/.sdkman/bin/sdkman-init.sh && cd $CODE_DIR && git checkout master"
181+
log "Making binary"
182+
$TPL_ROOT "source ~/.sdkman/bin/sdkman-init.sh && cd $CODE_DIR && make skip-tests"
183+
log "Compilation successful, creating a script to run compiled binary securly"
184+
$TPL_ROOT "echo -e '#\x21/bin/sh\n\n#Proxying to gateway (anon-ws-disable-stacked-tor)\nsocat TCP-LISTEN:9050,fork,bind=127.0.0.1 TCP:$SYS_WHONIX_IP:9050 &\nPID=\x24\x21\nSERVICE=\x24\x28cat /root/haveno-service-address\x29\n\nsource /root/.sdkman/bin/sdkman-init.sh\n/root/$CODE_DIR/haveno-desktop --useTorForXmr=OFF --nodePort=9999 --hiddenServiceAddress=\x24SERVICE\nkill \x24PID' > /bin/Haveno && chmod +x /bin/Haveno && chmod u+s /bin/Haveno"
149185

150186
elif [[ $from_source -eq 0 ]]; then
151187
log "Installing required packages for build"
@@ -160,13 +196,13 @@ elif [[ $from_source -eq 0 ]]; then
160196
log "Making binary"
161197
$TPL_ROOT "source ~/.sdkman/bin/sdkman-init.sh && cd $CODE_DIR && make skip-tests"
162198
log "Compilation successful, creating a script to run compiled binary securly"
163-
$TPL_ROOT "echo -e '#\x21/bin/bash\nsource /root/.sdkman/bin/sdkman-init.sh\n/root/$CODE_DIR/haveno-desktop --torControlPort=9051 --useTorForXmr=OFF --torControlHost=$SYS_WHONIX_IP' > /usr/local/sbin/Haveno && chmod +x /usr/local/sbin/Haveno && chmod u+s /usr/local/sbin/Haveno"
199+
$TPL_ROOT "echo -e '#\x21/bin/bash\nsource /root/.sdkman/bin/sdkman-init.sh\n/root/$CODE_DIR/haveno-desktop --nodePort=9999 --useTorForXmr=OFF --hiddenServiceAddress=$SERVICE' > /usr/sbin/Haveno && chmod +x /usr/sbin/Haveno && chmod u+s /usr/sbin/Haveno"
164200
#Fix icon permissions
165201
$TPL_ROOT "cp '/root/$CODE_DIR/desktop/package/linux/haveno.png' /opt/haveno.png && chmod 644 /opt/haveno.png"
166202
patched_app_entry="[Desktop Entry]
167203
Name=Haveno
168204
Comment=Haveno through sys-whonix
169-
Exec=sudo /usr/local/sbin/Haveno
205+
Exec=sudo /usr/sbin/Haveno
170206
Icon=/opt/haveno.png
171207
Terminal=false
172208
Type=Application
@@ -192,30 +228,17 @@ else
192228
# Remove unneeded packages
193229
log "Removing unneeded packages to lessen attack surface"
194230
if [ $from_source -eq 0 ]; then
195-
$TPL_ROOT "apt-get purge git wget make zip unzip curl -y"
231+
$TPL_ROOT "apt purge git wget make zip unzip curl -y"
196232
else
197-
$TPL_ROOT "apt-get purge curl unzip gnupg2 -y"
233+
$TPL_ROOT "apt purge curl unzip gnupg2 -y"
198234
fi
199235
#Whonix-gateway hardening
200-
log "Hardening whonix-gateway template"
201-
qvm-run --pass-io -u root -- whonix-gateway-17 "echo -e 'Sandbox 1\nConnectionPadding 1\n' > /usr/local/etc/torrc.d/50_user.conf"
202236
log "Hardening Completed"
203237
log "Remeber technical controls are only part of the battle, robust security is reliant on how you utilize the system"
204238
fi
205239

206-
log "Enabling onion grater config on sys-whonix"
207-
if [[ "$(qvm-run -u root --pass-io -- whonix-gateway-17 'sudo onion-grater-add 40_haveno')" =~ "OK" ]]; then
208-
log "Succesfully configured grater on sys-whonix"
209-
else
210-
log "Failed to configure grater on sys-whonix, updating whonix gateway template and trying again"
211-
qubes-vm-update -r --targets whonix-gateway-17
212-
if [[ "$(qvm-run -u root --pass-io -- whonix-gateway-17 'sudo onion-grater-add 40_haveno')" =~ "OK" ]]; then
213-
log "Succeeded in configuring onion grater"
214-
else
215-
log "Failed for unkown reason, exiting"
216-
exit 1;
217-
fi
218-
fi
240+
241+
219242
log "Restarting sys-whonix and $APPVM_NAME"
220243
qvm-shutdown --wait $APPVM_NAME
221244
qvm-shutdown --wait sys-whonix
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
APPVM_NAME=haveno
4+
5+
while getopts 'n:h' flag; do
6+
case "${flag}" in
7+
n) APPVM_NAME=${OPTARG} ;;
8+
h) printf "Usage: refresh-haveno-address.sh [options
9+
-n APPVM_NAME : (optional) name of haveno appvm
10+
-h : print this message
11+
"
12+
esac
13+
done
14+
15+
## This script creates a new hiddenservice address on sys-whonix
16+
## Also updates haveno-service-address file
17+
qvm-run -u root --pass-io -- sys-whonix "rm -rf /var/lib/tor/haveno_service/ && service tor@default restart"
18+
19+
SERVICE="$(qvm-run -u root --pass-io -- sys-whonix 'cat /var/lib/tor/haveno_service/hostname')"
20+
21+
qvm-run -u root --pass-io -- $APPVM_NAME "echo $SERVICE > /root/haveno-service-address"
22+

0 commit comments

Comments
 (0)