add a bunch of requested features, tor disablement, fix static builds

This commit is contained in:
idk
2022-03-15 20:33:01 -04:00
parent 0c2cb7c11d
commit c57734d65c
6 changed files with 60 additions and 13 deletions

View File

@ -8,7 +8,7 @@ GOARCH?="amd64"
ARG=-v -tags netgo -ldflags '-w' # -extldflags "-static"'
#FLAGS=/usr/lib/x86_64-linux-gnu/libboost_system.a /usr/lib/x86_64-linux-gnu/libboost_date_time.a /usr/lib/x86_64-linux-gnu/libboost_filesystem.a /usr/lib/x86_64-linux-gnu/libboost_program_options.a /usr/lib/x86_64-linux-gnu/libssl.a /usr/lib/x86_64-linux-gnu/libcrypto.a /usr/lib/x86_64-linux-gnu/libz.a
#ARG=-ldflags '-w -linkmode=external -extldflags "-static -ldl $(FLAGS)"'
STATIC=-v -tags netgo -ldflags '-w -extldflags "-static"'
#NOSTATIC=-v -tags netgo -ldflags '-w -extldflags "-ldl $(FLAGS)"'
WINGUI=-ldflags '-H=windowsgui'
@ -29,7 +29,7 @@ winbinary:
GOOS=windows go build $(WINGUI) -tags="netgo osusergo systray" -o $(BINARY)-$(GOOS)-$(GOARCH) .
nosystray:
go build $(NOSTATIC) -tags="netgo osusergo nosystray" -o $(BINARY)-$(GOOS)-$(GOARCH) .
CGO_ENABLED=0 go build $(STATIC) -tags="netgo osusergo nosystray" -o $(BINARY)-$(GOOS)-$(GOARCH)-static .
lint:
golint supervise/*.go
@ -347,3 +347,10 @@ docker: xhost
-e DISPLAY=unix$(DISPLAY) \
-v /tmp/.X11-unix:/tmp/.X11-unix \
--rm eyedeekay/i2p.plugins.tor-manager
torrents:
./i2p.plugins.tor-manager -nounpack -notor -os win
./i2p.plugins.tor-manager -nounpack -notor -os osx
./i2p.plugins.tor-manager -nounpack -notor -os linux
./i2p.plugins.tor-manager -nounpack -notor -os win -arch 32
./i2p.plugins.tor-manager -nounpack -notor -os linux -arch 32

View File

@ -72,7 +72,7 @@ The plugin will not start a Tor instance if a SOCKS proxy is open on port 9050.
3. Set up an onion site which announces an I2P mirror exists
- Works on Windows, Linux, OSX
4. Use Bittorrent-over-I2P to download the Tor Browser software
- Not Done, but pretty trivial. Fetch it from "somewhere", and drop it in the Snark directory.
- Worksish. Still a little janky. Usable on any platform if you're a little patient.
5. Embed jpackaged I2P routers and manage them internally
- Works on Windows and Linux. Can be done on OSX but needs to be different. AMD64 only.
6. Encrypt the "Working directory" with all the plugin data using a password.

View File

@ -80,6 +80,7 @@ type TBDownloader struct {
OS, ARCH string
Mirror string
Verbose bool
NoUnpack bool
Profile *embed.FS
listener net.Listener
}
@ -608,6 +609,24 @@ func (t *TBDownloader) DownloadUpdaterForLang(ietf string) (string, string, stri
}
version := t.GetVersion()
if strings.Contains(t.Mirror, "i2psnark") {
if !TorrentDownloaded() {
//t.Log("DownloadUpdaterForLang()", "Downloading torrent")
//Download the torrent files from their static locations.
i2psnark, err := FindSnarkDirectory()
if err != nil {
return "", "", "", err
}
asctorrent := filepath.Join(t.NamePerPlatform(ietf, version)+".asc", ".torrent")
_, err = t.SingleFileDownload("http://idk.i2p/torbrowser/"+asctorrent, filepath.Join(i2psnark, asctorrent), 0)
if err != nil {
return "", "", "", fmt.Errorf("DownloadUpdaterForLang: %s", err)
}
bintorrent := filepath.Join(t.NamePerPlatform(ietf, version), ".torrent")
_, err = t.SingleFileDownload("http://idk.i2p/torbrowser/"+bintorrent, filepath.Join(i2psnark, bintorrent), 0)
if err != nil {
return "", "", "", fmt.Errorf("DownloadUpdaterForLang: %s", err)
}
}
for !TorrentDownloaded() {
time.Sleep(time.Second * 10)
log.Println("DownloadUpdaterForLang:", "Waiting for torrent to download")
@ -641,6 +660,9 @@ func (t *TBDownloader) BrowserDir() string {
// UnpackUpdater unpacks the updater to the given path.
// it returns the path or an erorr if one is encountered.
func (t *TBDownloader) UnpackUpdater(binpath string) (string, error) {
if t.NoUnpack {
return binpath, nil
}
t.Log("UnpackUpdater()", fmt.Sprintf("Unpacking %s", binpath))
if t.OS == "win" {
installPath := t.BrowserDir()
@ -748,7 +770,11 @@ func (t *TBDownloader) CheckSignature(binpath, sigpath string) (string, error) {
var err error
if err = Verify(pk, sigpath, binpath); err == nil {
log.Println("CheckSignature: signature", "verified successfully")
return t.UnpackUpdater(binpath)
if !t.NoUnpack {
return t.UnpackUpdater(binpath)
}
log.Printf("CheckSignature: %s", "NoUnpack set, skipping unpack")
return t.BrowserDir(), nil
}
return "", fmt.Errorf("CheckSignature: %s", err)
}

View File

@ -179,6 +179,7 @@ func TorrentPath() (string, string) {
func TorrentDownloaded() bool {
cmpsize := 8661000
found := false
if dir, err := FindSnarkDirectory(); err == nil {
err := filepath.Walk(dir,
func(path string, info os.FileInfo, err error) error {
@ -189,12 +190,18 @@ func TorrentDownloaded() bool {
if strings.HasPrefix(path, prefix) && strings.HasSuffix(path, suffix) {
if info.Size() > int64(cmpsize) {
log.Println("TorrentDownloaded: Torrent Download found:", path)
found = true
return nil
} else {
return fmt.Errorf("TorrentDownloaded: Torrent Download found but size is too small: %s", path)
}
}
return nil
})
return err == nil
if found {
return err == nil
}
return false
}
return false
}

16
main.go
View File

@ -93,6 +93,7 @@ var (
password = flag.String("password", Password(), "Password to encrypt the working directory with. Implies -destruct, only the encrypted container will be saved.")
chat = flag.Bool("chat", false, "Open a WebChat client")
notor = flag.Bool("notor", false, "Do not automatically start Tor")
nounpack = flag.Bool("nounpack", false, "Do not unpack the Tor Browser")
ptop = flag.Bool("p2p", tbget.TorrentDownloaded(), "Use bittorrent over I2P to download the initial copy of Tor Browser")
)
@ -137,7 +138,6 @@ func Mirror() string {
if mir := os.Getenv("TOR_MANAGER_MIRROR"); mir != "" {
return mir
}
log.Println("No mirror specified, using default")
if runtime.GOOS == "linux" && runtime.GOARCH == "arm64" {
log.Println("Using arm64 mirror")
return "https://sourceforge.net/projects/tor-browser-ports/files"
@ -287,7 +287,7 @@ func main() {
}
}
var err error
client, err = tbserve.NewClient(*verbose, *lang, *system, *arch, *mirror, &content)
client, err = tbserve.NewClient(*verbose, *lang, *system, *arch, *mirror, &content, *nounpack)
if err != nil {
log.Fatal("Couldn't create client", err)
}
@ -337,15 +337,21 @@ func main() {
}
return
}
client.TBS.UnpackI2PAppData()
client.TBS.UnpackI2PData()
if *torrent {
log.Println("Generating I2P torrents of Tor packages")
if err := client.TBD.GenerateMissingTorrents(); err != nil {
log.Fatal(err)
}
}
if !*clearnet && !*notor {
client.TBS.UnpackI2PAppData()
client.TBS.UnpackI2PData()
if *nounpack {
log.Println("not unpacking, cannot continue")
os.Exit(0)
}
if !(*clearnet || *notor) {
log.Println("CLEARNET", *clearnet)
log.Println("NOTOR", *notor)
client.TBS.RunTorWithLang()
}

View File

@ -37,12 +37,13 @@ type Client struct {
}
// NewClient creates a new Client.
func NewClient(verbose bool, lang, OS, arch, mirror string, content *embed.FS) (*Client, error) {
func NewClient(verbose bool, lang, OS, arch, mirror string, content *embed.FS, nounpack bool) (*Client, error) {
m := &Client{
TBD: tbget.NewTBDownloader(lang, OS, arch, content),
}
m.TBD.Mirror = mirror
m.TBD.Verbose = verbose
m.TBD.NoUnpack = nounpack
m.TBD.MakeTBDirectory()
var err error
m.Onion, err = i2pdotonion.NewOnionService(m.TBD.DownloadPath)
@ -91,7 +92,7 @@ func NewClient(verbose bool, lang, OS, arch, mirror string, content *embed.FS) (
log.Printf("Signature check passed: %s %s", tgz, sig)
}
m.TBS = TBSupervise.NewSupervisor(home, lang)
go m.TBS.RunTorWithLang()
//go m.TBS.RunTorWithLang()
return m, nil
}
var home string
@ -105,7 +106,7 @@ func NewClient(verbose bool, lang, OS, arch, mirror string, content *embed.FS) (
log.Printf("Signature check passed: %s %s", tgz, sig)
}
m.TBS = TBSupervise.NewSupervisor(home, lang)
go m.TBS.RunTorWithLang()
//go m.TBS.RunTorWithLang()
return m, nil
}