mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-08-30 22:06:30 -04:00
Allow automatic generation of GPG keys
This commit is contained in:
+18
-7
@@ -12,13 +12,7 @@ func TempInit(configFileMap map[string]string) {
|
||||
dirInit()
|
||||
|
||||
// remove existing config file
|
||||
err := os.Remove(ConfigPath)
|
||||
if err != nil {
|
||||
// ignore error if file does not exist
|
||||
if !os.IsNotExist(err) {
|
||||
fmt.Println(AnsiError + "Failed to remove existing libmutton.ini:" + err.Error() + AnsiReset)
|
||||
}
|
||||
}
|
||||
removeFile(ConfigPath)
|
||||
|
||||
// ensure textEditor is set
|
||||
if configFileMap["textEditor"] == "" {
|
||||
@@ -54,3 +48,20 @@ func GpgUIDListGen() []string {
|
||||
}
|
||||
return uidSlice
|
||||
}
|
||||
|
||||
// GpgKeyGen generates a new GPG key and returns the key ID as a string
|
||||
func GpgKeyGen() string {
|
||||
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
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Run()
|
||||
|
||||
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)
|
||||
return uid
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user