浏览代码

In amnesic mode store mesh qtox settings in a tomb

Bob Mottram 8 年前
父节点
当前提交
45b8c85fd7
共有 1 个文件被更改,包括 46 次插入13 次删除
  1. 46
    13
      src/freedombone-image-mesh

+ 46
- 13
src/freedombone-image-mesh 查看文件

52
 MESH_INSTALL_SETUP=/root/.initial_mesh_setup
52
 MESH_INSTALL_SETUP=/root/.initial_mesh_setup
53
 MESH_AMNESIC=/root/.amnesic
53
 MESH_AMNESIC=/root/.amnesic
54
 
54
 
55
+# size of the tomb used to store qtox settings
56
+TOMB_TOX_SIZE_MB=64
57
+
55
 function create_ram_disk {
58
 function create_ram_disk {
56
 	ramdisk_size_mb=$1
59
 	ramdisk_size_mb=$1
57
 	if [ ! -d /mnt/ramdisk ]; then
60
 	if [ ! -d /mnt/ramdisk ]; then
465
 	echo $'Update of ZeroID completed' >> $INSTALL_LOG
468
 	echo $'Update of ZeroID completed' >> $INSTALL_LOG
466
 }
469
 }
467
 
470
 
468
-function amnesic_remove_tox {
469
-	echo $'Clearing qtox client settings' >> $INSTALL_LOG
470
-	if [ -d /home/${MY_USERNAME}/.config/tox ]; then
471
-		shred -zu /home/${MY_USERNAME}/.config/tox/*.tox
472
-		shred -zu /home/${MY_USERNAME}/.config/tox/*.db
473
-		shred -zu /home/${MY_USERNAME}/.config/tox/*.ini
474
-		rm -rf /home/${MY_USERNAME}/.config/tox
475
-	fi
476
-}
477
-
478
 function configure_toxcore {
471
 function configure_toxcore {
479
 	echo $'Configuring toxcore' >> $INSTALL_LOG
472
 	echo $'Configuring toxcore' >> $INSTALL_LOG
480
 
473
 
500
 	# save the public key for later reference
493
 	# save the public key for later reference
501
 	echo "$TOX_PUBLIC_KEY" > $TOX_BOOTSTRAP_ID_FILE
494
 	echo "$TOX_PUBLIC_KEY" > $TOX_BOOTSTRAP_ID_FILE
502
 	echo $'Configured toxcore' >> $INSTALL_LOG
495
 	echo $'Configured toxcore' >> $INSTALL_LOG
503
-
504
-	amnesic_remove_tox
505
-	echo $'toxic client configured' >> $INSTALL_LOG
506
 }
496
 }
507
 
497
 
508
 function disable_password_logins {
498
 function disable_password_logins {
541
 
531
 
542
 	echo '#!/bin/bash' > /usr/bin/amnesic
532
 	echo '#!/bin/bash' > /usr/bin/amnesic
543
 	echo '' >> /usr/bin/amnesic
533
 	echo '' >> /usr/bin/amnesic
534
+	echo 'tomb slam all' >> /usr/bin/amnesic
535
+	echo '' >> /usr/bin/amnesic
536
+	echo "if [ -d /home/${MY_USERNAME}/.config/tox ]; then" >> /usr/bin/amnesic
537
+	echo "    rm -rf /home/${MY_USERNAME}/.config/tox" >> /usr/bin/amnesic
538
+	echo 'fi' >> /usr/bin/amnesic
539
+	echo '' >> /usr/bin/amnesic
540
+	echo 'if [ -f /tmp/tox.tomb ]; then' >> /usr/bin/amnesic
541
+	echo '    rm -f /tmp/tox.tomb' >> /usr/bin/amnesic
542
+	echo 'fi' >> /usr/bin/amnesic
543
+	echo '' >> /usr/bin/amnesic
544
 	echo "shred -zu /var/log/${PROJECT_NAME}*" >> /usr/bin/amnesic
544
 	echo "shred -zu /var/log/${PROJECT_NAME}*" >> /usr/bin/amnesic
545
 	echo '' >> /usr/bin/amnesic
545
 	echo '' >> /usr/bin/amnesic
546
 	echo 'MY_USERNAME=$1' >> /usr/bin/amnesic
546
 	echo 'MY_USERNAME=$1' >> /usr/bin/amnesic
579
 	echo $'Daemons restarted' >> $INSTALL_LOG
579
 	echo $'Daemons restarted' >> $INSTALL_LOG
580
 }
580
 }
581
 
581
 
582
+function setup_amnesic_tox_data {
583
+	if [ ! -f $MESH_AMNESIC ]; then
584
+		return
585
+	fi
586
+	if [ ! -d /mnt/ramdisk ]; then
587
+		return
588
+	fi
589
+
590
+	TOMB_TOX_PASSWORD="$(openssl rand -base64 32 | cut -c1-30)"
591
+	tomb dig -s $TOMB_TOX_SIZE_MB /tmp/tox.tomb
592
+	tomb forge /mnt/ramdisk/tox.tomb.key --tomb-pwd "${TOMB_TOX_PASSWORD}" --unsafe
593
+	tomb lock /tmp/tox.tomb -k /mnt/ramdisk/tox.tomb.key --tomb-pwd "${TOMB_TOX_PASSWORD}" --unsafe
594
+	tomb open /tmp/tox.tomb -k /mnt/ramdisk/tox.tomb.key --tomb-pwd "${TOMB_TOX_PASSWORD}" --unsafe
595
+	TOMB_TOX_PASSWORD=
596
+	if [ -d /media/tox ]; then
597
+		if [ ! -d /home/$MY_USERNAME/.config ]; then
598
+			mkdir -p /home/$MY_USERNAME/.config
599
+		fi
600
+		if [ -d /home/$MY_USERNAME/.config/tox ]; then
601
+			cp -r /home/$MY_USERNAME/.config/tox/* /media/tox
602
+			rm -rf /home/$MY_USERNAME/.config/tox
603
+			ln -s /media/tox /home/$MY_USERNAME/.config/tox
604
+		fi
605
+		chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.config
606
+		chown -R $MY_USERNAME:$MY_USERNAME /media/tox
607
+		echo "Tox Tomb created" >> /var/log/${PROJECT_NAME}.log
608
+	else
609
+		echo "WARNING: Tox Tomb not found" >> /var/log/${PROJECT_NAME}.log
610
+	fi
611
+}
612
+
582
 # whether to reset the identity
613
 # whether to reset the identity
583
 set_new_identity=
614
 set_new_identity=
584
 if [ $2 ]; then
615
 if [ $2 ]; then
615
 	fi
646
 	fi
616
 
647
 
617
 	echo $'Beginning mesh node setup' >> $INSTALL_LOG
648
 	echo $'Beginning mesh node setup' >> $INSTALL_LOG
649
+	tomb slam all
618
 	enable_batman_daemon
650
 	enable_batman_daemon
619
 	create_ram_disk 1
651
 	create_ram_disk 1
620
 	change_avahi_name
652
 	change_avahi_name
623
 	configure_zeronet_mail
655
 	configure_zeronet_mail
624
 	configure_zeronet_forum
656
 	configure_zeronet_forum
625
 	configure_zeronet_id
657
 	configure_zeronet_id
658
+	setup_amnesic_tox_data
626
 	configure_toxcore
659
 	configure_toxcore
627
 	configure_zeronet
660
 	configure_zeronet
628
 	disable_password_logins
661
 	disable_password_logins