Embed and unpack the key if it's not present either

This commit is contained in:
idk
2022-01-23 13:40:14 -05:00
parent 5bc7752255
commit 2ee490a077
3 changed files with 25 additions and 6 deletions

View File

@ -2,10 +2,12 @@ package tbget
import ( import (
"archive/tar" "archive/tar"
"embed"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"log"
"net/http" "net/http"
"os" "os"
"os/exec" "os/exec"
@ -37,12 +39,13 @@ type TBDownloader struct {
Lang string Lang string
OS, ARCH string OS, ARCH string
Verbose bool Verbose bool
Profile *embed.FS
} }
var OS = "linux" var OS = "linux"
var ARCH = "64" var ARCH = "64"
func NewTBDownloader(lang string, os, arch string) *TBDownloader { func NewTBDownloader(lang string, os, arch string, content *embed.FS) *TBDownloader {
return &TBDownloader{ return &TBDownloader{
Lang: lang, Lang: lang,
DownloadPath: DOWNLOAD_PATH, DownloadPath: DOWNLOAD_PATH,
@ -50,6 +53,7 @@ func NewTBDownloader(lang string, os, arch string) *TBDownloader {
OS: os, OS: os,
ARCH: arch, ARCH: arch,
Verbose: false, Verbose: false,
Profile: content,
} }
} }
@ -96,14 +100,25 @@ func (t *TBDownloader) GetUpdaterForLangFromJson(body io.ReadCloser, ietf string
if err != nil { if err != nil {
return "", "", fmt.Errorf("t.GetUpdaterForLangFromJson: %s", err) return "", "", fmt.Errorf("t.GetUpdaterForLangFromJson: %s", err)
} }
t.MakeTBDirectory()
if err = ioutil.WriteFile(filepath.Join(t.DownloadPath, "downloads.json"), jsonBytes, 0644); err != nil { if err = ioutil.WriteFile(filepath.Join(t.DownloadPath, "downloads.json"), jsonBytes, 0644); err != nil {
return "", "", fmt.Errorf("t.GetUpdaterForLangFromJson: %s", err) return "", "", fmt.Errorf("t.GetUpdaterForLangFromJson: %s", err)
} }
return t.GetUpdaterForLangFromJsonBytes(jsonBytes, ietf) 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) 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{} var dat map[string]interface{}
if err := json.Unmarshal(jsonBytes, &dat); err != nil { if err := json.Unmarshal(jsonBytes, &dat); err != nil {
return "", "", fmt.Errorf("func (t *TBDownloader)Name: %s", err) 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) { func (t *TBDownloader) SingleFileDownload(url, name string) (string, error) {
os.MkdirAll(t.DownloadPath, 0755) t.MakeTBDirectory()
path := filepath.Join(t.DownloadPath, name) path := filepath.Join(t.DownloadPath, name)
if !t.BotherToDownload(url, name) { if !t.BotherToDownload(url, name) {
fmt.Printf("No updates required, skipping download of %s\n", name) fmt.Printf("No updates required, skipping download of %s\n", name)

View File

@ -10,6 +10,7 @@ import (
) )
//go:embed tor-browser/unpack/i2p.firefox/* //go:embed tor-browser/unpack/i2p.firefox/*
//go:embed tor-browser/TPO-signing-key.pub
var content embed.FS var content embed.FS
//var runtimePair = tbget.GetRuntimePair() //var runtimePair = tbget.GetRuntimePair()
@ -37,10 +38,11 @@ func main() {
} }
log.Println("Using auto-detected language", *lang) 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 { if err != nil {
log.Fatal("Couldn't create client", err) log.Fatal("Couldn't create client", err)
} }
//client.TBD.Profile = &content
client.TBS.Profile = &content client.TBS.Profile = &content
if *i2pbrowser { if *i2pbrowser {
client.TBS.RunI2PBWithLang() client.TBS.RunI2PBWithLang()

View File

@ -1,6 +1,7 @@
package tbserve package tbserve
import ( import (
"embed"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
@ -20,11 +21,12 @@ type Client struct {
TBS *TBSupervise.Supervisor 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{ m := &Client{
hostname: hostname, 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) tgz, sig, err := m.TBD.DownloadUpdaterForLang(lang)
if err != nil { if err != nil {
panic(err) panic(err)