[elbe-devel] [PATCH 07/10] egpg: use gpg executable to export keys

Manuel Traut manut at linutronix.de
Wed Apr 3 12:34:55 CEST 2019


The python-gpg bindings return the exported key in the keybox format.
python-pyme seemed to return it in gpg format.

The key is needed in gpg format for apt-key add.

I see now method to export the key in gpg format with python-gpg.
Therefore call the 'gpg' command to export they key.

Signed-off-by: Manuel Traut <manut at linutronix.de>
---
 elbepack/egpg.py        | 15 ++-------------
 elbepack/repomanager.py | 10 +++++-----
 2 files changed, 7 insertions(+), 18 deletions(-)

diff --git a/elbepack/egpg.py b/elbepack/egpg.py
index 6b66b004..86da1e00 100644
--- a/elbepack/egpg.py
+++ b/elbepack/egpg.py
@@ -220,17 +220,6 @@ def generate_elbe_internal_key():
 
 
 def export_key(fingerprint, outfile):
-    os.environ['GNUPGHOME'] = "/var/cache/elbe/gnupg"
-    ctx = core.Context()
-    ctx.set_armor(True)
-
-    try:
-        outdata = core.Data()
-        ctx.op_export(fingerprint, 0, outdata)
-        outdata.seek(0, os.SEEK_SET)
-        key = outdata.read()
-        outfile.write(key)
-    except Exception:
-        print("Error exporting key %s" % (fingerprint))
-
+    run(["/usr/bin/gpg", "-a", "-o", outfile,
+         "--export", fingerprint], env={"GNUPGHOME": "/var/cache/elbe/gnupg"})
     return '/var/cache/elbe/gnupg/pubring.kbx'
diff --git a/elbepack/repomanager.py b/elbepack/repomanager.py
index 19a481ab..4fb9361d 100644
--- a/elbepack/repomanager.py
+++ b/elbepack/repomanager.py
@@ -159,11 +159,11 @@ class RepoBase(object):
             fp.write("\n")
         fp.close()
 
-        with self.fs.open("repo.pub", "w") as pubkey_fp:
-            keyring = export_key(self.keyid, pubkey_fp)
-            if keyring:
-                shutil.copyfile(keyring, os.path.join(self.fs.path,
-                                                      "elbe-keyring.gpg"))
+        keyring = export_key(self.keyid, os.path.join(self.fs.path,
+                                                      "repo.pub"))
+        if keyring:
+            shutil.copyfile(keyring, os.path.join(self.fs.path,
+                                                  "elbe-keyring.gpg"))
 
         if need_update:
             self.log.do(
-- 
2.20.1




More information about the elbe-devel mailing list