summaryrefslogtreecommitdiff
path: root/lib/crypto/gpg
diff options
context:
space:
mode:
Diffstat (limited to 'lib/crypto/gpg')
-rw-r--r--lib/crypto/gpg/gpg.go4
-rw-r--r--lib/crypto/gpg/gpgbin/keys.go23
2 files changed, 26 insertions, 1 deletions
diff --git a/lib/crypto/gpg/gpg.go b/lib/crypto/gpg/gpg.go
index fe32468..00125ba 100644
--- a/lib/crypto/gpg/gpg.go
+++ b/lib/crypto/gpg/gpg.go
@@ -59,6 +59,10 @@ func (m *Mail) GetKeyId(s string) (string, error) {
return gpgbin.GetKeyId(s)
}
+func (m *Mail) ExportKey(k string) (io.Reader, error) {
+ return gpgbin.ExportPublicKey(k)
+}
+
func handleSignatureError(e string) models.SignatureValidity {
if e == "gpg: missing public key" {
return models.UnknownEntity
diff --git a/lib/crypto/gpg/gpgbin/keys.go b/lib/crypto/gpg/gpgbin/keys.go
index 9c8b233..bef90cf 100644
--- a/lib/crypto/gpg/gpgbin/keys.go
+++ b/lib/crypto/gpg/gpgbin/keys.go
@@ -1,6 +1,12 @@
package gpgbin
-import "fmt"
+import (
+ "bytes"
+ "fmt"
+ "io"
+ "os/exec"
+ "strings"
+)
// GetPrivateKeyId runs gpg --list-secret-keys s
func GetPrivateKeyId(s string) (string, error) {
@@ -21,3 +27,18 @@ func GetKeyId(s string) (string, error) {
}
return id, nil
}
+
+// ExportPublicKey exports the public key identified by k in armor format
+func ExportPublicKey(k string) (io.Reader, error) {
+ cmd := exec.Command("gpg", "--export", "--armor", k)
+
+ var outbuf bytes.Buffer
+ var stderr strings.Builder
+ cmd.Stdout = &outbuf
+ cmd.Stderr = &stderr
+ cmd.Run()
+ if strings.Contains(stderr.String(), "gpg") {
+ return nil, fmt.Errorf("gpg: error exporting key")
+ }
+ return &outbuf, nil
+}