aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe <rbo@gmx.us>2024-01-31 20:20:20 +0100
committerJoe <rbo@gmx.us>2024-01-31 20:20:20 +0100
commit98bc232593015bb368635da0a3716c61850695a2 (patch)
tree43910c482bdcb24702a75e9daece7432443fe015
parentgood start (diff)
downloadhardflip-98bc232593015bb368635da0a3716c61850695a2.tar.gz
hardflip-98bc232593015bb368635da0a3716c61850695a2.tar.bz2
hardflip-98bc232593015bb368635da0a3716c61850695a2.tar.xz
hardflip-98bc232593015bb368635da0a3716c61850695a2.tar.zst
hardflip-98bc232593015bb368635da0a3716c61850695a2.zip
qwe
Diffstat (limited to '')
-rw-r--r--src/c_hardflip.go2
-rw-r--r--src/c_init.go12
-rw-r--r--src/c_parse.go3
-rw-r--r--src/c_utils.go18
4 files changed, 31 insertions, 4 deletions
diff --git a/src/c_hardflip.go b/src/c_hardflip.go
index fc6ca69..02433ce 100644
--- a/src/c_hardflip.go
+++ b/src/c_hardflip.go
@@ -64,6 +64,6 @@ type HardData struct {
func main() {
data_dir := c_get_data_dir(nil)
- opts := HardOpts{true, true, "plain", false, ""}
+ opts := HardOpts{true, true, "plainq", false, ""}
i_ui(data_dir, opts)
}
diff --git a/src/c_init.go b/src/c_init.go
index 8981099..85eb9c8 100644
--- a/src/c_init.go
+++ b/src/c_init.go
@@ -52,6 +52,8 @@
package main
import (
+ "errors"
+ "fmt"
"os"
"path/filepath"
)
@@ -96,6 +98,16 @@ func c_recurse_data_dir(dir, root string, opts HardOpts,
} else if host_node != nil {
host_node.Filename = filename
host_node.Parent = &dir_node
+ if len(opts.GPG) == 0 {
+ host_node.Pass = ""
+ } else if opts.GPG != "plain" && len(host_node.Pass) > 0 {
+ host_node.Pass, err = c_decrypt_str(host_node.Pass)
+ if err != nil {
+ str := fmt.Sprintf("%s%s: password decryption: %v\n",
+ dir, filename, err)
+ *load_err = append(*load_err, errors.New(str))
+ }
+ }
dir_node.lhost.add_back(host_node)
}
i_draw_load_ui(ui)
diff --git a/src/c_parse.go b/src/c_parse.go
index 3a58558..2a7b881 100644
--- a/src/c_parse.go
+++ b/src/c_parse.go
@@ -69,9 +69,6 @@ func c_read_yaml_file(file string,
if err := yaml.Unmarshal(yaml_file, &host); err != nil {
return nil, err
}
- if len(opts.GPG) == 0 {
- host.Pass = ""
- }
if len(host.Name) == 0 {
return nil, nil
}
diff --git a/src/c_utils.go b/src/c_utils.go
index df49a4f..01c8665 100644
--- a/src/c_utils.go
+++ b/src/c_utils.go
@@ -54,6 +54,8 @@ package main
import (
"fmt"
"os"
+ "os/exec"
+ "strings"
)
// this function will go get the data folder and try to create it if it does
@@ -117,3 +119,19 @@ func c_error_mode(msg string, err error, ui *HardUI) {
ui.err[ERROR_MSG] = msg
ui.err[ERROR_ERR] = err_str
}
+
+// c_encrypt_str encrypts a string with the given gpgkey
+func c_encrypt_str(str string, gpg string) (string, error) {
+ cmd := exec.Command("gpg", "-r", gpg, "-a", "-e")
+ cmd.Stdin = strings.NewReader(str)
+ out, err := cmd.Output()
+ return string(out), err
+}
+
+// c_decrypt_str will try to decrypt the given str
+func c_decrypt_str(str string) (string, error) {
+ cmd := exec.Command("gpg", "-q", "-d")
+ cmd.Stdin = strings.NewReader(str)
+ out, err := cmd.Output()
+ return string(out), err
+}