Remove the gpg-gen file after use

This commit is contained in:
2024-03-07 23:40:35 -05:00
parent 5a12eaf4cf
commit 31bc17cb0d
5 changed files with 11 additions and 2 deletions
+7 -2
View File
@@ -1,12 +1,12 @@
package offline
import (
"fmt"
"os"
"os/exec"
"strings"
)
// TempInit ensures libmutton directories exist and writes the libmutton configuration file
func TempInit(configFileMap map[string]string) {
// create EntryRoot and ConfigDir
dirInit()
@@ -51,6 +51,7 @@ func GpgUIDListGen() []string {
// GpgKeyGen generates a new GPG key and returns the key ID as a string
func GpgKeyGen() string {
// create and write gpg-gen file
createFile(ConfigDir+"/gpg-gen", []string{"Key-Type: eddsa", "Key-Curve: ed25519", "Key-Usage: sign", "Subkey-Type: ecdh", "Subkey-Curve: cv25519", "Subkey-Usage: encrypt", "Name-Real: libmutton", "Name-Comment: gpg-libmutton", "Name-Email: github.com/rwinkhart/libmutton", "Expire-Date: 0"})
cmd := exec.Command("gpg", "-q", "--batch", "--generate-key", ConfigDir+"/gpg-gen")
cmd.Stdout = os.Stdout
@@ -58,10 +59,14 @@ func GpgKeyGen() string {
cmd.Stdin = os.Stdin
cmd.Run()
// generate GPG key based on gog-gen file
cmd = exec.Command("gpg", "-k", "--with-colons")
gpgOutputBytes, _ := cmd.Output()
gpgOutputLines := strings.Split(string(gpgOutputBytes), "\n")
uid := strings.Split(gpgOutputLines[len(gpgOutputLines)-4], ":")[9]
fmt.Println(uid)
// remove gpg-gen file
removeFile(ConfigDir + "/gpg-gen")
return uid
}