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

18
main.go
View File

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

View File

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

View File

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