97 lines
2.1 KiB
Go
97 lines
2.1 KiB
Go
package main
|
|
|
|
import (
|
|
"crypto/rsa"
|
|
encrypt "fckeuspy-go/lib"
|
|
"html/template"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
"path/filepath"
|
|
"time"
|
|
|
|
"fyne.io/fyne/v2"
|
|
"fyne.io/fyne/v2/dialog"
|
|
"fyne.io/fyne/v2/widget"
|
|
)
|
|
|
|
var (
|
|
priv *rsa.PrivateKey
|
|
pubPEM []byte
|
|
certPEM []byte // self-signed cert jen pro sdílení identity (volitelné)
|
|
tmpl *template.Template
|
|
)
|
|
|
|
type envelope struct {
|
|
// Encrypted AES key, Nonce, Ciphertext (GCM)
|
|
EK string `json:"ek"` // base64(RSA-OAEP(aesKey))
|
|
N string `json:"n"` // base64(nonce 12B)
|
|
CT string `json:"ct"` // base64(GCM(ciphertext||tag))
|
|
}
|
|
|
|
func main() {
|
|
if err := rootCmd.Execute(); err != nil {
|
|
log.Printf("Chyba: %v", err)
|
|
os.Exit(1)
|
|
}
|
|
// Malé zpoždění pro případné async logy
|
|
time.Sleep(50 * time.Millisecond)
|
|
}
|
|
|
|
func runFyne() {
|
|
storageDir, w := NewUI()
|
|
vaultPath := filepath.Join(storageDir, "vault.enc")
|
|
placeholder := widget.NewLabel("Inicializace trezoru…")
|
|
w.SetContent(placeholder)
|
|
|
|
showDialog := func() {
|
|
ShowPasswordVaultDialog(w, func(create bool, password string) {
|
|
if password == "" {
|
|
return
|
|
}
|
|
var store encrypt.SecureJSONStore
|
|
var err error
|
|
if create {
|
|
store, err = encrypt.CreateEncryptedStore(vaultPath, password, true)
|
|
} else {
|
|
store, err = encrypt.OpenEncryptedStore(vaultPath, password)
|
|
if err != nil {
|
|
dialog.NewError(err, w).Show()
|
|
return
|
|
}
|
|
}
|
|
if err != nil {
|
|
dialog.NewError(err, w).Show()
|
|
return
|
|
}
|
|
vs, err := NewVaultService(store)
|
|
if err != nil {
|
|
dialog.NewError(err, w).Show()
|
|
return
|
|
}
|
|
parts := buildEntries()
|
|
fyne.CurrentApp().Driver().AllWindows()[0].SetTitle("Encryptor (Vault)")
|
|
w.SetContent(buildTabbedUI(parts, vs))
|
|
})
|
|
}
|
|
|
|
// Pokud soubor neexistuje, dialog v režimu vytvořit (default). Pokud existuje, uživatel může přepnout.
|
|
showDialog()
|
|
w.ShowAndRun()
|
|
}
|
|
|
|
func RunWebApp() {
|
|
var err error
|
|
// 2) inicializuj šifrovací službu
|
|
_, err = encrypt.NewService("")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
// 2) šablony
|
|
tmpl = template.Must(template.ParseGlob("templates/*.html"))
|
|
|
|
muxServer := NewServer()
|
|
log.Fatal(http.ListenAndServe(":8080", muxServer))
|
|
}
|