Working directory encryption!

This commit is contained in:
idk
2022-03-05 00:08:13 -05:00
parent 63e76a6a12
commit 9e4d33fb13
4 changed files with 32 additions and 29 deletions

View File

@ -9,7 +9,7 @@ import (
"io/ioutil"
"log"
"os"
"strings"
"path/filepath"
"crypto/aes"
"crypto/cipher"
@ -59,11 +59,11 @@ func EncryptTarXZip(source, password string) error {
}
file, err := os.OpenFile(source+".tar.xz", os.O_RDWR, 0)
if err != nil {
log.Println("Error:", err)
log.Println("Open File Error:", err)
}
info, err := file.Stat()
if err != nil {
log.Println("Error:", err)
log.Println("File Stat Error:", err)
}
bytes := info.Size()
file.Truncate(0)
@ -76,7 +76,7 @@ func EncryptTarXZip(source, password string) error {
}
func UnTarXzip(source string) error {
target := strings.Replace(source, ".tar.xz", "", 1)
target := filepath.Dir(source)
txz := archiver.NewTarXz()
txz.Tar.OverwriteExisting = true
txz.Tar.ContinueOnError = true

18
main.go
View File

@ -118,15 +118,6 @@ func main() {
usage()
}
flag.Parse()
if *clearnet {
*mirror = "http://dist.torproject.org/torbrowser/"
}
if *snowflake {
go Snowflake()
}
if *destruct {
defer OverwriteDirectoryContents(*directory)
}
if *password != "" {
log.Println("Looking for directory with password")
DecryptTarXZifThere(*directory, *password)
@ -144,6 +135,15 @@ func main() {
}
}()
}
if *clearnet {
*mirror = "http://dist.torproject.org/torbrowser/"
}
if *snowflake {
go Snowflake()
}
if *destruct {
defer OverwriteDirectoryContents(*directory)
}
tbget.WORKING_DIR = *directory
if filename == "i2pbrowser" {
log.Println("Starting I2P in Tor Browser")

View File

@ -1,7 +1,6 @@
package main
import (
"log"
"os"
"path/filepath"
)
@ -11,22 +10,20 @@ func OverwriteDirectoryContents(directory string) {
//and zero-out the files to the length of the file
filepath.Walk(directory, func(path string, info os.FileInfo, err error) error {
go func() {
if err != nil {
log.Println("Error:", err)
}
if info.IsDir() {
log.Println("Error:", err)
}
if err == nil {
if !info.IsDir() {
file, err := os.OpenFile(path, os.O_RDWR, 0)
if err != nil {
log.Println("Error:", err)
}
} else {
defer file.Close()
bytes := info.Size()
file.Truncate(0)
file.Write(make([]byte, bytes))
log.Println("Error:", err)
}
}
}
}()
return nil
})
os.RemoveAll(directory)
}

View File

@ -22,6 +22,9 @@ var shutdown = false
func Password() string {
require_password := os.Getenv("TOR_MANAGER_REQUIRE_PASSWORD")
if !PluginStat() {
require_password = "true"
}
if require_password == "true" || require_password == "1" {
passwd, err := zenity.Entry(
"Enter a password if you want to encrypt the working directory",
@ -103,9 +106,12 @@ func onReady() {
}
func onExit() {
onSnowflakeExit()
if *snowflake {
snowflakeProxy.Stop()
}
if *password != "" {
log.Println("Encrypting directory with password")
os.Remove(*directory + ".tar.xz")
EncryptTarXZip(*directory, *password)
}
if shutdown {