From 2ee490a0776ecc9e2bec2c7d759ef2b9e5a651c7 Mon Sep 17 00:00:00 2001 From: idk Date: Sun, 23 Jan 2022 13:40:14 -0500 Subject: [PATCH] Embed and unpack the key if it's not present either --- get/get.go | 21 ++++++++++++++++++--- main.go | 4 +++- serve/serve.go | 6 ++++-- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/get/get.go b/get/get.go index 3ec94e5..d971c05 100644 --- a/get/get.go +++ b/get/get.go @@ -2,10 +2,12 @@ package tbget import ( "archive/tar" + "embed" "encoding/json" "fmt" "io" "io/ioutil" + "log" "net/http" "os" "os/exec" @@ -37,12 +39,13 @@ type TBDownloader struct { Lang string OS, ARCH string Verbose bool + Profile *embed.FS } var OS = "linux" var ARCH = "64" -func NewTBDownloader(lang string, os, arch string) *TBDownloader { +func NewTBDownloader(lang string, os, arch string, content *embed.FS) *TBDownloader { return &TBDownloader{ Lang: lang, DownloadPath: DOWNLOAD_PATH, @@ -50,6 +53,7 @@ func NewTBDownloader(lang string, os, arch string) *TBDownloader { OS: os, ARCH: arch, Verbose: false, + Profile: content, } } @@ -96,14 +100,25 @@ func (t *TBDownloader) GetUpdaterForLangFromJson(body io.ReadCloser, ietf string if err != nil { return "", "", fmt.Errorf("t.GetUpdaterForLangFromJson: %s", err) } + t.MakeTBDirectory() if err = ioutil.WriteFile(filepath.Join(t.DownloadPath, "downloads.json"), jsonBytes, 0644); err != nil { return "", "", fmt.Errorf("t.GetUpdaterForLangFromJson: %s", err) } return t.GetUpdaterForLangFromJsonBytes(jsonBytes, ietf) } -func (t *TBDownloader) GetUpdaterForLangFromJsonBytes(jsonBytes []byte, ietf string) (string, string, error) { +func (t *TBDownloader) MakeTBDirectory() { os.MkdirAll(t.DownloadPath, 0755) + path := filepath.Join("", "tor-browser", "TPO-signing-key.pub") + bytes, err := t.Profile.ReadFile(path) + if err != nil { + log.Fatal(err) + } + ioutil.WriteFile(filepath.Join(t.DownloadPath, "TPO-signing-key.pub"), bytes, 0644) +} + +func (t *TBDownloader) GetUpdaterForLangFromJsonBytes(jsonBytes []byte, ietf string) (string, string, error) { + t.MakeTBDirectory() var dat map[string]interface{} if err := json.Unmarshal(jsonBytes, &dat); err != nil { return "", "", fmt.Errorf("func (t *TBDownloader)Name: %s", err) @@ -129,7 +144,7 @@ func (t *TBDownloader) GetUpdaterForLangFromJsonBytes(jsonBytes []byte, ietf str } func (t *TBDownloader) SingleFileDownload(url, name string) (string, error) { - os.MkdirAll(t.DownloadPath, 0755) + t.MakeTBDirectory() path := filepath.Join(t.DownloadPath, name) if !t.BotherToDownload(url, name) { fmt.Printf("No updates required, skipping download of %s\n", name) diff --git a/main.go b/main.go index ffcd8fd..55167b8 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,7 @@ import ( ) //go:embed tor-browser/unpack/i2p.firefox/* +//go:embed tor-browser/TPO-signing-key.pub var content embed.FS //var runtimePair = tbget.GetRuntimePair() @@ -37,10 +38,11 @@ func main() { } log.Println("Using auto-detected language", *lang) } - client, err := tbserve.NewClient("", *lang, *os, *arch) + client, err := tbserve.NewClient("", *lang, *os, *arch, &content) if err != nil { log.Fatal("Couldn't create client", err) } + //client.TBD.Profile = &content client.TBS.Profile = &content if *i2pbrowser { client.TBS.RunI2PBWithLang() diff --git a/serve/serve.go b/serve/serve.go index d350e89..97e08ad 100644 --- a/serve/serve.go +++ b/serve/serve.go @@ -1,6 +1,7 @@ package tbserve import ( + "embed" "encoding/json" "fmt" "io/ioutil" @@ -20,11 +21,12 @@ type Client struct { TBS *TBSupervise.Supervisor } -func NewClient(hostname string, lang string, os string, arch string) (*Client, error) { +func NewClient(hostname string, lang string, os string, arch string, content *embed.FS) (*Client, error) { m := &Client{ hostname: hostname, - TBD: tbget.NewTBDownloader(lang, os, arch), + TBD: tbget.NewTBDownloader(lang, os, arch, content), } + m.TBD.MakeTBDirectory() tgz, sig, err := m.TBD.DownloadUpdaterForLang(lang) if err != nil { panic(err)