2021-08-04 00:18:30 +02:00
#!/bin/bash
2021-09-26 10:30:09 +01:00
# keeps the password in memory between restarts: /dev/shm/.${netprefix}cl.pw
2021-08-04 00:18:30 +02:00
# see the reasoning: https://github.com/ElementsProject/lightning#hd-wallet-encryption
# does not store the password on disk unless auto-unlock is enabled
2021-12-18 02:29:57 +00:00
# autounlock password is in /home/bitcoin/.${netprefix}cl.pw
2021-08-04 00:18:30 +02:00
# command info
if [ $# -lt 1 ] || [ " $1 " = "-h" ] || [ " $1 " = "-help" ] || \
! echo " $@ " | grep -Eq "new|seed|unlock|lock|encrypt|decrypt|autounlock-on|autounlock-off|change-password" ; then
echo
2021-09-22 16:06:37 +01:00
echo "Create new wallet or import seed"
echo "Unlock/lock, encrypt, decrypt, set autounlock or change password for the hsm_secret"
2021-08-04 00:18:30 +02:00
echo
2021-09-22 16:06:37 +01:00
echo "Usage:"
echo "Create new wallet:"
2022-05-23 12:57:14 +01:00
echo "cl.hsmtool.sh [new] [mainnet|testnet|signet] [?seedpassword]"
echo "cl.hsmtool.sh [new-force] [mainnet|testnet|signet] [?seedpassword]"
2022-01-25 12:07:11 +01:00
echo "There will be no seedpassword(passphrase) used by default"
2021-12-18 22:07:37 +00:00
echo "new-force will backup the old wallet and will work without interaction"
2021-08-04 00:18:30 +02:00
echo
2022-05-23 12:57:14 +01:00
echo "cl.hsmtool.sh [seed] [mainnet|testnet|signet] [\"space-separated-seed-words\"] [?seedpassword]"
echo "cl.hsmtool.sh [seed-force] [mainnet|testnet|signet] [\"space-separated-seed-words\"] [?seedpassword]"
2021-09-22 16:06:37 +01:00
echo "The new hsm_secret will be not encrypted if no NewPassword is given"
echo "seed-force will delete any old wallet and will work without dialog"
2021-08-04 00:18:30 +02:00
echo
2022-07-07 08:54:29 +01:00
echo "cl.hsmtool.sh [unlock] <mainnet|testnet|signet> <password>"
echo " success: exit 0"
echo " wrong password: exit 2"
echo " fail to unlock after 1 minute + show logs: exit 3"
echo "cl.hsmtool.sh [lock] <mainnet|testnet|signet>"
2021-09-26 10:30:09 +01:00
echo "cl.hsmtool.sh [encrypt|decrypt] <mainnet|testnet|signet>"
echo "cl.hsmtool.sh [autounlock-on|autounlock-off] <mainnet|testnet|signet>"
2021-08-04 00:18:30 +02:00
echo
2022-05-23 12:57:14 +01:00
echo "cl.hsmtool.sh [change-password] <mainnet|testnet|signet> <NewPassword>"
2021-08-04 00:18:30 +02:00
echo
exit 1
fi
2022-07-07 08:54:29 +01:00
echo " # Running 'cl.hsmtool.sh $* ' "
2021-08-04 00:18:30 +02:00
source /mnt/hdd/raspiblitz.conf
2021-09-26 10:30:09 +01:00
source <( /home/admin/config.scripts/network.aliases.sh getvars cl $2 )
2021-08-04 00:18:30 +02:00
hsmSecretPath = " /home/bitcoin/.lightning/ ${ CLNETWORK } /hsm_secret "
# password file is on the disk if encrypted and auto-unlock is enabled
2022-01-25 12:07:11 +01:00
passwordFile = " /dev/shm/. ${ netprefix } cl.pw "
2021-09-26 10:30:09 +01:00
if grep -Eq " ${ netprefix } clEncryptedHSM=on " /mnt/hdd/raspiblitz.conf; then
if grep -Eq " ${ netprefix } clAutoUnlock=on " /mnt/hdd/raspiblitz.conf; then
2021-12-18 02:52:25 +00:00
passwordFile = /home/bitcoin/.${ netprefix } cl.pw
2021-08-04 00:18:30 +02:00
fi
fi
#############
# Functions #
#############
function passwordToFile( ) {
if [ $# -gt 0 ] ; then
text = " $1 "
else
2022-07-07 08:54:29 +01:00
text = " Type or paste the decryption passwordC for the $CHAIN Core Lightning wallet "
2021-08-04 00:18:30 +02:00
fi
# write password into a file in memory
2021-09-02 11:34:30 +01:00
# trap to delete on any exit
trap 'rm -f $data' EXIT
2021-08-04 00:18:30 +02:00
# get password
data = $( mktemp -p /dev/shm/)
2021-09-02 11:34:30 +01:00
2021-08-04 00:18:30 +02:00
dialog --clear \
--backtitle "Enter password" \
--title "Enter password" \
--insecure \
--passwordbox " $text " 8 52 2> " $data "
# make decison
pressed = $?
case $pressed in
0)
sudo touch $passwordFile
sudo chmod 600 $passwordFile
sudo chown bitcoin:bitcoin $passwordFile
2021-12-18 02:29:57 +00:00
sudo -u bitcoin tee $passwordFile 1>/dev/null < " $data "
2021-08-04 00:18:30 +02:00
shred " $data " ; ;
1)
shred " $data "
shred -uvz $passwordFile
echo "# Cancelled"
exit 1; ;
255)
shred " $data "
shred -uvz $passwordFile
[ -s " $data " ] && cat " $data " || echo "# ESC pressed."
exit 1; ;
esac
}
function shredPasswordFile( ) {
echo
echo "# Shredding the passwordFile"
echo
2021-09-26 10:30:09 +01:00
if [ -f /dev/shm/.${ netprefix } cl.pw ] ; then
sudo shred -uvz /dev/shm/.${ netprefix } cl.pw
2021-09-02 19:49:23 +01:00
fi
2021-12-18 02:52:25 +00:00
if [ -f /home/bitcoin/.${ netprefix } cl.pw ] ; then
sudo shred -uvz /home/bitcoin/.${ netprefix } cl.pw
2021-09-02 19:49:23 +01:00
fi
2021-08-04 00:18:30 +02:00
}
function encryptHSMsecret( ) {
2022-05-09 19:02:29 +02:00
walletPassword = $1
2021-08-04 00:18:30 +02:00
if [ ${# walletPassword } -eq 0 ] ; then
2022-05-05 10:59:50 +02:00
sudo /home/admin/config.scripts/blitz.passwords.sh set x \
2022-07-07 08:54:29 +01:00
"Enter the password C to encrypt the Core Lightning wallet file (hsm_secret)" \
2021-09-12 17:59:44 +01:00
" $passwordFile "
2021-08-31 13:51:53 +01:00
sudo chown bitcoin:bitcoin $passwordFile
2021-08-04 00:18:30 +02:00
sudo chmod 600 $passwordFile
walletPassword = $( sudo cat $passwordFile )
2022-05-23 12:57:14 +01:00
fi
2021-09-12 17:59:44 +01:00
( echo $walletPassword ; echo $walletPassword ) | \
sudo -u bitcoin lightning-hsmtool encrypt $hsmSecretPath || exit 1
2021-09-02 19:49:23 +01:00
# setting value in raspiblitz.conf
2021-12-14 23:34:35 +01:00
/home/admin/config.scripts/blitz.conf.sh set ${ netprefix } clEncryptedHSM "on"
2022-07-07 08:54:29 +01:00
echo " # Encrypted the hsm_secret for Core Lightning $CHAIN "
2021-08-04 00:18:30 +02:00
}
function decryptHSMsecret( ) {
2022-05-23 12:57:14 +01:00
2022-05-09 19:02:29 +02:00
# optional to give this function the decrypt password
password = $1
2021-09-02 19:49:23 +01:00
# check if encrypted
2021-09-02 16:28:04 +01:00
trap 'rm -f "$output"' EXIT
output = $( mktemp -p /dev/shm/)
2021-09-12 17:59:44 +01:00
echo "test" | sudo -u bitcoin lightning-hsmtool decrypt " $hsmSecretPath " \
2> " $output "
2021-09-02 16:28:04 +01:00
if [ " $( grep -c "hsm_secret is not encrypted" < " $output " ) " -gt 0 ] ; then
echo "# The hsm_secret is not encrypted"
2021-09-02 19:49:23 +01:00
shredPasswordFile
echo "# Continue to record in the raspiblitz.conf"
2021-09-02 16:28:04 +01:00
else
2021-09-02 19:49:23 +01:00
# setting value in raspiblitz.conf
2021-12-14 23:34:35 +01:00
/home/admin/config.scripts/blitz.conf.sh set ${ netprefix } clEncryptedHSM "on"
2022-05-09 19:02:29 +02:00
if [ " ${ password } " != "" ] ; then
echo "# using the password from parameter"
elif [ -f $passwordFile ] ; then
2021-09-02 19:49:23 +01:00
echo " # Getting the password from $passwordFile "
2022-05-09 19:02:29 +02:00
password = $( cat sudo cat $passwordFile )
2021-09-02 19:49:23 +01:00
else
passwordToFile
2022-05-09 19:02:29 +02:00
password = $( cat sudo cat $passwordFile )
2021-09-02 19:49:23 +01:00
fi
2022-05-09 19:02:29 +02:00
if echo " ${ password } " | sudo -u bitcoin lightning-hsmtool decrypt \
2021-09-12 17:59:44 +01:00
" $hsmSecretPath " ; then
2021-09-02 19:49:23 +01:00
echo "# Decrypted successfully"
else
# unlock manually
2021-09-26 10:30:09 +01:00
/home/admin/config.scripts/cl.hsmtool.sh unlock
2021-09-02 19:49:23 +01:00
# attempt to decrypt again
2021-09-12 17:59:44 +01:00
sudo cat $passwordFile | sudo -u bitcoin lightning-hsmtool decrypt \
2021-09-02 19:49:23 +01:00
" $hsmSecretPath " || echo "# Couldn't decrypt" ; exit 1
fi
2021-09-02 16:28:04 +01:00
fi
2021-08-04 00:18:30 +02:00
shredPasswordFile
# setting value in raspiblitz config
2021-12-14 23:34:35 +01:00
/home/admin/config.scripts/blitz.conf.sh set ${ netprefix } clEncryptedHSM "off"
2022-07-07 08:54:29 +01:00
echo " # Decrypted the hsm_secret for Core Lightning $CHAIN "
2021-08-04 00:18:30 +02:00
}
###########
# Options #
2022-05-23 12:57:14 +01:00
###########
2021-08-04 00:18:30 +02:00
if [ " $1 " = "new" ] || [ " $1 " = "new-force" ] || [ " $1 " = "seed" ] || [ " $1 " = "seed-force" ] ; then
# make sure /home/bitcoin/.lightning/bitcoin exists (when lightningd was not run yet)
2022-01-25 12:07:11 +01:00
if ! sudo ls /home/bitcoin/.lightning/bitcoin 1>/dev/null; then
echo "# Create /home/bitcoin/.lightning/bitcoin/"
2021-08-04 00:18:30 +02:00
sudo -u bitcoin mkdir -p /home/bitcoin/.lightning/bitcoin/
fi
# check/delete existing wallet
if [ " $1 " = "new-force" ] || [ " $1 " = "seed-force" ] ; then
2021-12-18 22:07:37 +00:00
if sudo ls $hsmSecretPath 2>1 1>/dev/null; then
echo "# Moving the old wallet to backup"
now = $( date +"%Y_%m_%d_%H%M%S" )
sudo mv $hsmSecretPath $hsmSecretPath .backup.${ now } 2>/dev/null || exit 1
fi
2021-08-04 00:18:30 +02:00
else
if sudo ls $hsmSecretPath 2>1 1>/dev/null; then
echo " # The hsm_secret is already present at $hsmSecretPath . "
2021-12-18 22:07:37 +00:00
if [ ${ CHAIN } = "mainnet" ] ; then
2022-05-23 12:57:14 +01:00
if sudo ls /home/bitcoin/.lightning/${ CLNETWORK } /seedwords.info 2>1 1>/dev/null; then
2021-12-18 22:07:37 +00:00
echo " # There is a /home/bitcoin/.lightning/ ${ CLNETWORK } /seedwords.info so don't create new "
# show seed
sudo /home/admin/config.scripts/cl.install.sh display-seed mainnet
exit 0
else
# there should be no hsm_secret without seedwords.info, but protect this edge-case
whiptail --title " An hsm_secret is present " \
--yes-button "New wallet" \
--no-button "Keep no seed" \
--yesno "The wallet was autogenerated by lightningd and there is no seedwords.info file.\nDo you want to generate a new wallet from seedwords?" 9 60
if [ $? -eq 0 ] ; then
echo "# yes-button -> New wallet"
echo "# Moving the old wallet to backup"
now = $( date +"%Y_%m_%d_%H%M%S" )
sudo mv $hsmSecretPath $hsmSecretPath .backup.${ now } 2>/dev/null || exit 1
else
echo "# no-button -> Keep the hsm_secret"
exit 0
fi
fi
fi
2021-08-04 00:18:30 +02:00
fi
fi
# check for https://github.com/trezor/python-mnemonic
if [ $( pip list | grep -c mnemonic) -eq 0 ] ; then
pip install mnemonic = = 0.19 1>/dev/null
fi
if [ " $1 " = "new" ] ; then
2022-01-25 12:07:11 +01:00
seedpassword = " $3 "
2021-08-04 00:18:30 +02:00
# get 24 words
source <( python /home/admin/config.scripts/blitz.mnemonic.py generate)
2021-09-26 10:30:09 +01:00
#TODO seedwords to cl.backup.sh seed-export-gui
/home/admin/config.scripts/cl.backup.sh seed-export-gui " ${ seedwords6x4 } "
2021-08-04 00:18:30 +02:00
elif [ " $1 " = "new-force" ] ; then
# get 24 words
source <( python /home/admin/config.scripts/blitz.mnemonic.py generate)
echo " seedwords=' ${ seedwords } ' "
echo " seedwords6x4=' ${ seedwords6x4 } ' "
elif [ " $1 " = "seed" ] || [ " $1 " = "seed-force" ] ; then
2021-09-26 10:30:09 +01:00
#TODO get seedwords from cl.backup.sh seed-import-gui [$RESULTFILE]
2021-08-04 00:18:30 +02:00
seedwords = " $3 "
2021-12-23 17:25:17 +00:00
# get seedwords6x4
source <( python /home/admin/config.scripts/blitz.mnemonic.py add6x4 " ${ seedwords } " )
2021-08-04 00:18:30 +02:00
seedpassword = " $4 "
fi
2022-01-17 09:57:27 +00:00
if [ " ${ seedwords } " = "" ] ; then
echo "# No seedwords - exiting"
exit 14
fi
2021-08-31 14:26:49 +01:00
# place the seedwords to /home/bitcoin/.lightning/${CLNETWORK}/seedwords.info
sudo touch /home/bitcoin/.lightning/${ CLNETWORK } /seedwords.info
sudo chown bitcoin:bitcoin /home/bitcoin/.lightning/${ CLNETWORK } /seedwords.info
sudo chmod 600 /home/bitcoin/.lightning/${ CLNETWORK } /seedwords.info
echo "
2022-02-09 09:53:13 +00:00
# This file was placed by cl.hsmtool.sh
# Contains the seed words from which the hsm_secret in the same directory was generated from
2021-08-31 14:26:49 +01:00
seedwords = '${seedwords}'
seedwords6x4 = '${seedwords6x4}'
2021-08-31 14:54:33 +01:00
# Will be removed safely when the hsm_secret is encrypted.
2021-08-31 14:26:49 +01:00
" | sudo -u bitcoin tee /home/bitcoin/.lightning/ ${ CLNETWORK } /seedwords.info
2021-08-04 00:18:30 +02:00
# pass to 'hsmtool generatehsm hsm_secret'
if [ ${# seedpassword } -eq 0 ] ; then
2021-09-12 17:59:44 +01:00
( echo "0" ; echo " ${ seedwords } " ; echo ) | sudo -u bitcoin lightning-hsmtool \
"generatehsm" $hsmSecretPath 1>& 2
2021-08-04 00:18:30 +02:00
else
2022-01-25 12:07:11 +01:00
# pass to 'hsmtool generatehsm hsm_secret' - confirm seedpassword
2021-09-12 17:59:44 +01:00
( echo "0" ; echo " ${ seedwords } " ; echo " $seedpassword " ; echo " $seedpassword " ) \
| sudo -u bitcoin lightning-hsmtool "generatehsm" $hsmSecretPath 1>& 2
2021-08-04 00:18:30 +02:00
fi
echo "# Re-init the backup plugin with the new wallet"
2021-09-26 10:30:09 +01:00
/home/admin/config.scripts/cl-plugin.backup.sh on $CHAIN
2021-08-04 00:18:30 +02:00
exit 0
2022-07-07 08:54:29 +01:00
# cl.hsmtool.sh [unlock] <mainnet|testnet|signet> <password>
2021-09-02 19:49:23 +01:00
elif [ " $1 " = "unlock" ] ; then
2021-08-04 00:18:30 +02:00
# check if unlocked
attempt = 0
2021-09-20 19:36:01 +01:00
justUnlocked = 0
while [ $( $lightningcli_alias getinfo 2>& 1 | grep -c '"id":' ) -eq 0 ] ; do
2021-09-26 10:30:09 +01:00
clError = $( sudo journalctl -n5 -u ${ netprefix } lightningd)
2022-05-23 12:57:14 +01:00
clLog = $( sudo tail -n 5 /home/bitcoin/.lightning/${ CLNETWORK } /cl.log)
2022-02-07 20:28:47 +00:00
# check passwordfile
if [ " $( eval echo \$ ${ netprefix } clEncryptedHSM) " = "on" ] && [ ! -f $passwordFile ] ; then
2022-07-07 08:54:29 +01:00
if [ $# -lt 3 ] ; then
passwordToFile
else
echo " $3 " | sudo -u bitcoin tee $passwordFile 1>/dev/null
fi
2022-02-07 20:28:47 +00:00
sudo systemctl restart ${ netprefix } lightningd
2021-09-02 19:49:23 +01:00
# getpassword
2022-02-07 20:28:47 +00:00
elif [ $( echo " ${ clError } " | \
2021-09-02 19:49:23 +01:00
grep -c 'encrypted-hsm: Could not read pass from stdin.' ) -gt 0 ] ; then
2022-05-23 12:57:14 +01:00
if [ ${ justUnlocked } -eq 0 ] ; then
2021-09-20 19:36:01 +01:00
if [ -f $passwordFile ] ; then
echo "# Wrong passwordFile is present"
else
echo "# No passwordFile is present"
fi
2022-07-07 08:54:29 +01:00
if [ $# -lt 3 ] ; then
passwordToFile
else
echo " $3 " | sudo -u bitcoin tee $passwordFile 1>/dev/null
fi
2021-09-20 19:36:01 +01:00
sudo systemctl restart ${ netprefix } lightningd
justUnlocked = 1
2021-09-02 19:49:23 +01:00
else
2022-02-09 14:31:23 +00:00
echo "# waiting to unlock wallet (2) ... "
2021-09-20 19:36:01 +01:00
sleep 5
2021-09-02 19:49:23 +01:00
fi
2021-09-20 19:36:01 +01:00
2022-05-23 12:57:14 +01:00
# configure --encrypted-hsm
2021-09-26 10:30:09 +01:00
elif [ $( echo " ${ clError } " | \
2021-09-02 19:49:23 +01:00
grep -c 'hsm_secret is encrypted, you need to pass the --encrypted-hsm startup option.' ) -gt 0 ] ; then
2021-09-20 19:36:01 +01:00
echo "# The hsm_secret is encrypted, but unlock is not configured"
2022-07-07 08:54:29 +01:00
if [ $# -lt 3 ] ; then
passwordToFile
else
echo " $3 " | sudo -u bitcoin tee $passwordFile 1>/dev/null
fi
2021-09-20 19:36:01 +01:00
# setting value in raspiblitz config
2021-12-14 23:34:35 +01:00
/home/admin/config.scripts/blitz.conf.sh set ${ netprefix } clEncryptedHSM "on"
2021-09-26 10:30:09 +01:00
/home/admin/config.scripts/cl.install-service.sh $CHAIN
2022-05-23 12:57:14 +01:00
# get new password
2021-09-26 10:30:09 +01:00
elif [ $( echo " ${ clError } " | \
2021-08-04 00:18:30 +02:00
grep -c 'Wrong password for encrypted hsm_secret.' ) -gt 0 ] ; then
echo "# Wrong password"
2022-07-07 08:54:29 +01:00
if [ $# -lt 3 ] ; then
sudo rm -f $passwordFile
passwordToFile " Wrong password - type the decryption password for the $CHAIN Core Lightning wallet "
sudo systemctl restart ${ netprefix } lightningd
else
echo "# Wrong password, try again or sign in with ssh to unlock"
exit 2
fi
2022-05-23 12:57:14 +01:00
# check if the backup plugin is needing to be reinitialized
elif [ $( echo " ${ clLog } " | \
grep -c 'Backup is out of date, we cannot continue safely. Emergency shutdown.' ) -gt 0 ] ; then
echo "# Backup is out of date, reinitiliazng and saving a copy in /home/bitcoin/ (on the SDcard / OS disk)"
/home/admin/config.scripts/cl-plugin.backup.sh on
2021-09-02 19:49:23 +01:00
# fail
2021-08-04 00:18:30 +02:00
elif [ $attempt -eq 12 ] ; then
echo " # Failed to unlock the ${ netprefix } lightningd wallet - giving up after 1 minute "
2022-01-16 19:53:31 +00:00
echo
echo " # The last lines of the ${ netprefix } lightningd logs ('sudo tail -n 5 /home/bitcoin/.lightning/ ${ CLNETWORK } /cl.log'): "
sudo tail -n 5 /home/bitcoin/.lightning/${ CLNETWORK } /cl.log
echo
echo " # The last lines of the ${ netprefix } lightningd journal ('sudo journalctl -u ${ netprefix } lightningd'): "
sudo journalctl -n 5 -u ${ netprefix } lightningd
echo
2022-07-07 08:54:29 +01:00
exit 3
2021-08-04 00:18:30 +02:00
fi
2022-02-09 14:48:27 +00:00
echo " # waiting to unlock wallet ( $(( attempt*5)) ) ... "
2021-09-20 19:36:01 +01:00
sleep 5
2021-08-04 00:18:30 +02:00
attempt = $(( attempt+1))
done
echo " # Ok the ${ netprefix } lightningd wallet is unlocked "
exit 0
2022-02-09 14:31:23 +00:00
2021-08-04 00:18:30 +02:00
elif [ " $1 " = "lock" ] ; then
shredPasswordFile
sudo systemctl restart ${ netprefix } lightningd
exit 0
2022-02-09 14:31:23 +00:00
2021-08-04 00:18:30 +02:00
elif [ " $1 " = "encrypt" ] ; then
2022-02-09 09:53:13 +00:00
# check if sudo
if [ " $EUID " -ne 0 ] ; then
echo "Please run as root (with sudo)"
exit 1
fi
if [ -f /home/bitcoin/.lightning/${ CLNETWORK } /seedwords.info ] ; then
source /home/bitcoin/.lightning/${ CLNETWORK } /seedwords.info
2021-08-31 20:41:04 +01:00
if [ ${# seedwords6x4 } -gt 0 ] ; then
# show the words one last time
ack = 0
while [ ${ ack } -eq 0 ]
do
whiptail --title "IMPORTANT SEED WORDS - PLEASE WRITE DOWN" --msgbox " The backup of seedwords will be deleted, make sure you wrote them down. Store these numbered 24 words in a safe location:\n\n ${ seedwords6x4 } " 13 76
whiptail --title "Please Confirm" --yes-button "Show Again" --no-button "CONTINUE" --yesno " Are you sure that you wrote down the word list?" 8 55
if [ $? -eq 1 ] ; then
ack = 1
fi
done
deletedWhen = "deleted when the hsm_secret was encrypted"
else
deletedWhen = "not available any more"
fi
2022-02-09 09:53:13 +00:00
# shred seedwords.info
shred /home/bitcoin/.lightning/${ CLNETWORK } /seedwords.info
2021-08-31 14:54:33 +01:00
fi
2021-08-31 14:26:49 +01:00
echo "
2022-02-09 10:17:41 +00:00
# This file was placed by cl.hsmtool.sh
2022-02-09 09:53:13 +00:00
# The seed words from which the hsm_secret in the same directory was generated from
2021-08-31 14:54:33 +01:00
# were $deletedWhen.
# The words cannot be generated from the hsm_secret (one way function).
2022-02-09 10:17:41 +00:00
# If you don't have the words the hsm_secret can be still backed up as a file or in hex:
2022-05-23 12:57:14 +01:00
# https://lightning.readthedocs.io/BACKUP.html#hsm-secret
2022-02-09 10:17:41 +00:00
# https://github.com/rootzoll/raspiblitz/blob/dev/FAQ.cl.md#seed
2021-08-31 14:26:49 +01:00
" | sudo -u bitcoin tee /home/bitcoin/.lightning/ ${ CLNETWORK } /seedwords.info
# encrypt
2022-05-09 19:02:29 +02:00
walletPassword = $4
encryptHSMsecret " $walletPassword "
2021-08-04 00:18:30 +02:00
2022-02-09 14:31:23 +00:00
2021-08-04 00:18:30 +02:00
elif [ " $1 " = "decrypt" ] ; then
decryptHSMsecret
2022-02-09 14:31:23 +00:00
2021-08-04 00:18:30 +02:00
elif [ " $1 " = "autounlock-on" ] ; then
2021-09-26 10:30:09 +01:00
if grep -Eq " ${ netprefix } clEncryptedHSM=on " /mnt/hdd/raspiblitz.conf; then
2021-12-18 02:29:57 +00:00
echo " # Moving the password from $passwordFile to /home/bitcoin/. ${ netprefix } cl.pw "
sudo -u bitcoin mv /dev/shm/.${ netprefix } cl.pw /home/bitcoin/.${ netprefix } cl.pw
2021-08-04 00:18:30 +02:00
else
2021-12-18 02:29:57 +00:00
passwordFile = /home/bitcoin/.${ netprefix } cl.pw
2021-08-04 00:18:30 +02:00
passwordToFile
fi
# setting value in raspiblitz config
2021-12-14 23:34:35 +01:00
/home/admin/config.scripts/blitz.conf.sh set ${ netprefix } clAutoUnlock "on"
2022-07-07 08:54:29 +01:00
echo " # Autounlock is on for Core Lightning $CHAIN "
2021-08-04 00:18:30 +02:00
2022-02-09 14:31:23 +00:00
2021-08-04 00:18:30 +02:00
elif [ " $1 " = "autounlock-off" ] ; then
2021-12-18 02:52:25 +00:00
if [ -f /home/bitcoin/.${ netprefix } cl.pw ] ; then
2021-12-18 02:29:57 +00:00
sudo cp /home/bitcoin/.${ netprefix } cl.pw /dev/shm/.${ netprefix } cl.pw
sudo shred -uzv /home/bitcoin/.${ netprefix } cl.pw
2021-09-26 10:30:09 +01:00
sudo chmod 600 /dev/shm/.${ netprefix } cl.pw
sudo chown bitcoin:bitcoin /dev/shm/.${ netprefix } cl.pw
2021-09-02 19:49:23 +01:00
fi
2021-08-04 00:18:30 +02:00
# setting value in raspiblitz config
2021-12-14 23:34:35 +01:00
/home/admin/config.scripts/blitz.conf.sh set ${ netprefix } clAutoUnlock "off"
2022-07-07 08:54:29 +01:00
echo " # Autounlock is off for Core Lightning $CHAIN "
2021-08-04 00:18:30 +02:00
2022-02-09 14:31:23 +00:00
2021-08-04 00:18:30 +02:00
elif [ " $1 " = "change-password" ] ; then
2022-05-09 19:02:29 +02:00
decryptHSMsecret " $3 " || exit 1
walletPassword = $4
2021-08-04 00:18:30 +02:00
if ! encryptHSMsecret " $walletPassword " ; then
echo "# Warning: the hsm_secret is left unencrypted."
echo "# To fix run:"
2022-02-09 09:53:13 +00:00
echo " sudo /home/admin/config.scripts/cl.hsmtool encrypt $2 "
2021-08-04 00:18:30 +02:00
exit 1
fi
exit 0
2022-02-09 14:31:23 +00:00
2021-08-04 00:18:30 +02:00
elif [ " $1 " = "check" ] ; then
2022-02-09 09:53:13 +00:00
# TODO https://github.com/rootzoll/raspiblitz/issues/2897
2021-08-04 00:18:30 +02:00
# dumponchaindescriptors <path/to/hsm_secret> [network]
# get current descriptors
sudo -u bitcoin /home/bitcoin/lightning/tools/hsmtool dumponchaindescriptors \
2021-09-02 19:49:23 +01:00
/home/bitcoin/.lightning/${ CLNETWORK } /hsm_secret $CLNETWORK
2021-08-04 00:18:30 +02:00
# get seed to compare
else
echo "# Unknown option - exiting script"
exit 1
fi
2021-09-02 16:28:04 +01:00
# set the lightningd service file after all choices unless exited before
2021-09-26 10:30:09 +01:00
/home/admin/config.scripts/cl.install-service.sh $CHAIN