Browse Source

LND behind TOR

#146
rootzoll 7 years ago
parent
commit
d358a7bbab
  1. 9
      build.sdcard/raspbianStretchDesktop.sh
  2. 2
      home.admin/50downloadHDD.sh
  3. 119
      home.admin/96addTorService.sh
  4. 2
      home.admin/assets/lnd.tor.service

9
build.sdcard/raspbianStretchDesktop.sh

@ -198,7 +198,14 @@ cat > ./getpublicip.sh <<EOF
echo 'getpublicip.sh started, writing public IP address every 10 minutes into /run/publicip' echo 'getpublicip.sh started, writing public IP address every 10 minutes into /run/publicip'
while [ 0 ]; while [ 0 ];
do do
printf "PUBLICIP=\$(curl -vv ipinfo.io/ip 2> /run/publicip.log)\n" > /run/publicip; torExists=$(sudo ls /mnt/hdd/tor/lnd9735/hostname 2>/dev/null | grep hostname -c)
if [ ${torExists} -eq 1 ]; then
# use tor onion address
printf "PUBLICIP=$(sudo cat /mnt/hdd/tor/lnd9735/hostname)\n" > /run/publicip;
else
# get public IP
printf "PUBLICIP=$(curl -vv ipinfo.io/ip 2> /run/publicip.log)\n" > /run/publicip;
fi
sleep 600 sleep 600
done; done;
EOF EOF

2
home.admin/50downloadHDD.sh

@ -28,7 +28,7 @@ fi
name="Download" name="Download"
targetDir="/mnt/hdd/download/" targetDir="/mnt/hdd/download/"
targetSize=$size targetSize=$size
maxTimeoutLoops=500 maxTimeoutLoops=10000
command="sudo wget -c -r -P ${targetDir} -q --show-progress ${url}" command="sudo wget -c -r -P ${targetDir} -q --show-progress ${url}"
# starting session if needed # starting session if needed

119
home.admin/96addTorService.sh

@ -45,19 +45,52 @@ echo "*** Updating System ***"
sudo apt-get update sudo apt-get update
echo "" echo ""
echo "*** Install Tor & Config ***" echo "*** Install Tor ***"
sudo apt install tor tor-arm -y sudo apt install tor tor-arm -y
echo "uncommenting #RunAsDaemon 1"
sudo sed -i "s/^#RunAsDaemon 1/RunAsDaemon 1/g" $torrc echo ""
echo "adding PortForward 1 & ControlPort 9051 after RunAsDaemon 1" echo "*** Tor Config ***"
sudo sed -i '\|RunAsDaemon 1| {N;s|\n$|\nPortForwarding 1\nControlPort 9051\n|}' $torrc sudo mkdir /mnt/hdd/tor
echo "uncommenting #CookieAuthentication 1" sudo mkdir /mnt/hdd/tor/sys
sudo sed -i "s/^#CookieAuthentication 1/CookieAuthentication 1/g" $torrc sudo mkdir /mnt/hdd/tor/web80
echo "adding CookieAuthFileGroupReadable 1 after CookieAuthentication 1" sudo mkdir /mnt/hdd/tor/lnd9735
sudo sed -i '\|CookieAuthentication 1| {N;s|\n$|\nCookieAuthFileGroupReadable 1\n|}' $torrc sudo chmod -R 700 /mnt/hdd/tor
echo "*** enabling logs of tor to /var/log/tor/notices.log ***" sudo chown -R debian-tor:debian-tor /mnt/hdd/tor
sudo sed -i "s/^#Log notice file/Log notice file/g" $torrc cat > ./torrc <<EOF
echo "OK - configured tor" ### See 'man tor', or https://www.torproject.org/docs/tor-manual.html
DataDirectory /mnt/hdd/tor/sys
PidFile /mnt/hdd/tor/sys/tor.pid
SafeLogging 0
Log notice stdout
Log notice file /mnt/hdd/tor/notice.log
Log info file /mnt/hdd/tor/info.log
RunAsDaemon 1
PortForwarding 1
ControlPort 905
SocksPort 9050
CookieAuthFile /mnt/hdd/tor/sys/control_auth_cookie
CookieAuthentication 1
CookieAuthFileGroupReadable 1
# Hidden Service v2 for WEB ADMIN INTERFACE
HiddenServiceDir /mnt/hdd/tor/web80/
HiddenServicePort 80 127.0.0.1:80
# Hidden Service v3 for LND incomming connections
# https://trac.torproject.org/projects/tor/wiki/doc/NextGenOnions#Howtosetupyourownprop224service
HiddenServiceDir /mnt/hdd/tor/lnd9735
HiddenServiceVersion 3
HiddenServicePort 9735 127.0.0.1:9735
# NOTE: bitcoind get tor service automatically - see /mnt/hdd/bitcoin for onion key
EOF
sudo rm $torrc
sudo mv ./torrc $torrc
sudo chmod 644 $torrc
echo "" echo ""
# NYX - Tor monitor tool # NYX - Tor monitor tool
@ -79,22 +112,12 @@ sudo cp /home/bitcoin/.${network}/${network}.conf /home/admin/.${network}/${netw
sudo chown admin:admin /home/admin/.${network}/${network}.conf sudo chown admin:admin /home/admin/.${network}/${network}.conf
echo "" echo ""
#echo "*** Changing LND Config ***"
#echo "tor.active" | sudo tee --append /home/bitcoin/.lnd/lnd.conf
#echo "tor.streamisolation" | sudo tee --append /home/bitcoin/.lnd/lnd.conf
#echo "tor.v2" | sudo tee --append /home/bitcoin/.lnd/lnd.conf
#echo "tor.privatekeypath=/home/bitcoin/.bitcoin/onion_private_key" | sudo tee --append /home/bitcoin/.lnd/lnd.conf
#sudo cp /home/bitcoin/.lnd/lnd.conf /home/admin/.lnd/lnd.conf
#sudo chown admin:admin /home/admin/.lnd/lnd.conf
#echo "OK"
#echo ""
echo "*** Activating TOR system service ***" echo "*** Activating TOR system service ***"
sudo systemctl restart tor@default sudo systemctl restart tor@default
echo "" echo ""
echo "*** Setting Permissions ***" echo "*** Setting Permissions ***"
# so that Bitcoind can create Tor hidden service # so that chain network can create Tor hidden service
echo "setting bitcoind permissions" echo "setting bitcoind permissions"
sudo usermod -a -G debian-tor bitcoin sudo usermod -a -G debian-tor bitcoin
# so that you can run `arm` as user # so that you can run `arm` as user
@ -123,25 +146,27 @@ sudo systemctl restart ${network}d
sleep 8 sleep 8
onionAddress="" onionAddress=""
while [ ${#onionAddress} -eq 0 ] while [ ${#onionAddress} -eq 0 ]
do
echo "--- Checking ---" echo "--- Checking ---"
date +%s date +%s
sudo cat /mnt/hdd/${network}/debug.log | grep "tor" | tail -n 10 sudo cat /mnt/hdd/${network}/debug.log | grep "tor" | tail -n 10
onionAddress=$(${network}-cli getnetworkinfo | grep '"address"' | cut -d '"' -f4) onionAddress=$(${network}-cli getnetworkinfo | grep '"address"' | cut -d '"' -f4)
echo "If this takes too long --> CTRL+c, reboot and check manually" echo "If this takes too long --> CTRL+c, reboot and check manually"
sleep 5 sleep 5
do done
echo "" echo ""
echo "*** Setting your Onion Address ***" echo "*** Setting your Onion Address ***"
onionPort=$(${network}-cli getnetworkinfo | grep '"port"' | tr -dc '0-9') onionPort=$(${network}-cli getnetworkinfo | grep '"port"' | tr -dc '0-9')
echo "Your Onion Address is: ${onionAddress}:${onionPort}" echo "Your Chain Network Onion Address is: ${onionAddress}:${onionPort}"
echo "TODO: Make LND reachable over TOR when compiled for ARM with TOR support" onionLND=$(sudo cat /mnt/hdd/tor/lnd9735/hostname)
echo "Your Lightning Tor Onion Address is: ${onionLND}:9735"
echo ""
# ACTIVATE LND OVER TOR LATER ... see DEV NOTES AT END OF FILE # ACTIVATE LND OVER TOR LATER ... see DEV NOTES AT END OF FILE
sudo systemctl disable lnd sudo systemctl disable lnd
echo "Writing Public Onion Address to /run/publicip" echo "Writing Public Onion Address to /run/publicip"
echo "PUBLICIP=${onionAddress}" | sudo tee /run/publicip printf "PUBLICIP=${onionLND}\n" > /run/publicip;
sed -i "5s/.*/Wants=${network}d.service/" ./assets/lnd.tor.service sed -i "5s/.*/Wants=${network}d.service/" ./assets/lnd.tor.service
sed -i "6s/.*/After=${network}d.service/" ./assets/lnd.tor.service sed -i "6s/.*/After=${network}d.service/" ./assets/lnd.tor.service
sudo cp /home/admin/assets/lnd.tor.service /etc/systemd/system/lnd.service sudo cp /home/admin/assets/lnd.tor.service /etc/systemd/system/lnd.service
@ -149,7 +174,6 @@ sudo chmod +x /etc/systemd/system/lnd.service
sudo systemctl enable lnd sudo systemctl enable lnd
echo "OK" echo "OK"
echo "*** Finshing Setup / REBOOT ***" echo "*** Finshing Setup / REBOOT ***"
echo "OK - all should be set" echo "OK - all should be set"
echo "" echo ""
@ -158,40 +182,3 @@ read key
sudo shutdown -r now sudo shutdown -r now
exit 0 exit 0
DEV NOTES ---> maybe use this /etc/tor/torrc to have all toor config on HDD
--> needs /mnt/hdd/tor & with dirs: sys, lnd9735, web80
--> all with chown debian-tor:debian-tor & chmod 700
--> update getpublicip script to use if available: cat /mnt/hdd/tor/lnd9735/hostname
--> Above activate LND tor service when LND is compiled for ARM with TOR service
### See 'man tor', or https://www.torproject.org/docs/tor-manual.html
DataDirectory /mnt/hdd/tor/sys
PidFile /mnt/hdd/tor/sys/tor.pid
SafeLogging 0
Log notice stdout
Log notice file /mnt/hdd/tor/notice.log
Log info file /mnt/hdd/tor/info.log
RunAsDaemon 1
PortForwarding 1
ControlPort 905
SocksPort 9050
CookieAuthFile /mnt/hdd/tor/sys/control_auth_cookie
CookieAuthentication 1
CookieAuthFileGroupReadable 1
# Hidden Service v2 for WEB ADMIN INTERFACE
HiddenServiceDir /mnt/hdd/tor/web80/
HiddenServicePort 80 127.0.0.1:80
# Hidden Service v3 for LND incomming connections
# https://trac.torproject.org/projects/tor/wiki/doc/NextGenOnions#Howtosetupyourownprop224service
HiddenServiceDir /mnt/hdd/tor/lnd9735
HiddenServiceVersion 3
HiddenServicePort 9735 127.0.0.1:9735
# NOTE: bitcoind get tor service automatically - see /mnt/hdd/bitcoin for onion key

2
home.admin/assets/lnd.tor.service

@ -12,7 +12,7 @@ After=bitcoind.service
# get var PUBIP from file # get var PUBIP from file
EnvironmentFile=/run/publicip EnvironmentFile=/run/publicip
ExecStart=/usr/local/gocode/bin/lnd --tor.active --tor.v2 ExecStart=/usr/local/gocode/bin/lnd --tor.active --tor.v3 --externalip=${PUBLICIP} --listen=127.0.0.1:9735
PIDFile=/home/bitcoin/.lnd/lnd.pid PIDFile=/home/bitcoin/.lnd/lnd.pid
User=bitcoin User=bitcoin
Group=bitcoin Group=bitcoin

Loading…
Cancel
Save