|
|
72d647 |
diff --git a/dnf/crypto.py b/dnf/crypto.py
|
|
|
72d647 |
index a1839eefe..24a13ed6f 100644
|
|
|
72d647 |
--- a/dnf/crypto.py
|
|
|
72d647 |
+++ b/dnf/crypto.py
|
|
|
72d647 |
@@ -26,12 +26,64 @@
|
|
|
72d647 |
import dnf.pycomp
|
|
|
72d647 |
import dnf.util
|
|
|
72d647 |
import dnf.yum.misc
|
|
|
72d647 |
-import gpg
|
|
|
72d647 |
import io
|
|
|
72d647 |
import logging
|
|
|
72d647 |
import os
|
|
|
72d647 |
import tempfile
|
|
|
72d647 |
|
|
|
72d647 |
+try:
|
|
|
72d647 |
+ from gpg import Context
|
|
|
72d647 |
+ from gpg import Data
|
|
|
72d647 |
+except ImportError:
|
|
|
72d647 |
+ import gpgme
|
|
|
72d647 |
+
|
|
|
72d647 |
+
|
|
|
72d647 |
+ class Context(object):
|
|
|
72d647 |
+ def __init__(self):
|
|
|
72d647 |
+ self.__dict__["ctx"] = gpgme.Context()
|
|
|
72d647 |
+
|
|
|
72d647 |
+ def __enter__(self):
|
|
|
72d647 |
+ return self
|
|
|
72d647 |
+
|
|
|
72d647 |
+ def __exit__(self, type, value, tb):
|
|
|
72d647 |
+ pass
|
|
|
72d647 |
+
|
|
|
72d647 |
+ @property
|
|
|
72d647 |
+ def armor(self):
|
|
|
72d647 |
+ return self.ctx.armor
|
|
|
72d647 |
+
|
|
|
72d647 |
+ @armor.setter
|
|
|
72d647 |
+ def armor(self, value):
|
|
|
72d647 |
+ self.ctx.armor = value
|
|
|
72d647 |
+
|
|
|
72d647 |
+ def op_import(self, key_fo):
|
|
|
72d647 |
+ if isinstance(key_fo, basestring):
|
|
|
72d647 |
+ key_fo = io.BytesIO(key_fo)
|
|
|
72d647 |
+ self.ctx.import_(key_fo)
|
|
|
72d647 |
+
|
|
|
72d647 |
+ def op_export(self, pattern, mode, keydata):
|
|
|
72d647 |
+ self.ctx.export(pattern, keydata)
|
|
|
72d647 |
+
|
|
|
72d647 |
+ def __getattr__(self, name):
|
|
|
72d647 |
+ return getattr(self.ctx, name)
|
|
|
72d647 |
+
|
|
|
72d647 |
+
|
|
|
72d647 |
+ class Data(object):
|
|
|
72d647 |
+ def __init__(self):
|
|
|
72d647 |
+ self.__dict__["buf"] = io.BytesIO()
|
|
|
72d647 |
+
|
|
|
72d647 |
+ def __enter__(self):
|
|
|
72d647 |
+ return self
|
|
|
72d647 |
+
|
|
|
72d647 |
+ def __exit__(self, type, value, tb):
|
|
|
72d647 |
+ pass
|
|
|
72d647 |
+
|
|
|
72d647 |
+ def read(self):
|
|
|
72d647 |
+ return self.buf.getvalue()
|
|
|
72d647 |
+
|
|
|
72d647 |
+ def __getattr__(self, name):
|
|
|
72d647 |
+ return getattr(self.buf, name)
|
|
|
72d647 |
+
|
|
|
72d647 |
|
|
|
72d647 |
GPG_HOME_ENV = 'GNUPGHOME'
|
|
|
72d647 |
logger = logging.getLogger('dnf')
|
|
|
72d647 |
@@ -67,7 +119,7 @@ def keyids_from_pubring(gpgdir):
|
|
|
72d647 |
if not os.path.exists(gpgdir):
|
|
|
72d647 |
return []
|
|
|
72d647 |
|
|
|
72d647 |
- with pubring_dir(gpgdir), gpg.Context() as ctx:
|
|
|
72d647 |
+ with pubring_dir(gpgdir), Context() as ctx:
|
|
|
72d647 |
keyids = []
|
|
|
72d647 |
for k in ctx.keylist():
|
|
|
72d647 |
subkey = _extract_signing_subkey(k)
|
|
|
72d647 |
@@ -101,7 +153,7 @@ def pubring_dir(pubring_dir):
|
|
|
72d647 |
def rawkey2infos(key_fo):
|
|
|
72d647 |
pb_dir = tempfile.mkdtemp()
|
|
|
72d647 |
keyinfos = []
|
|
|
72d647 |
- with pubring_dir(pb_dir), gpg.Context() as ctx:
|
|
|
72d647 |
+ with pubring_dir(pb_dir), Context() as ctx:
|
|
|
72d647 |
ctx.op_import(key_fo)
|
|
|
72d647 |
for key in ctx.keylist():
|
|
|
72d647 |
subkey = _extract_signing_subkey(key)
|
|
|
72d647 |
@@ -110,7 +162,7 @@ def rawkey2infos(key_fo):
|
|
|
72d647 |
keyinfos.append(Key(key, subkey))
|
|
|
72d647 |
ctx.armor = True
|
|
|
72d647 |
for info in keyinfos:
|
|
|
72d647 |
- with gpg.Data() as sink:
|
|
|
72d647 |
+ with Data() as sink:
|
|
|
72d647 |
ctx.op_export(info.id_, 0, sink)
|
|
|
72d647 |
sink.seek(0, os.SEEK_SET)
|
|
|
72d647 |
info.raw_key = sink.read()
|
|
|
72d647 |
diff --git a/dnf/yum/misc.py b/dnf/yum/misc.py
|
|
|
72d647 |
index 97f8be94d..248bff884 100644
|
|
|
72d647 |
--- a/dnf/yum/misc.py
|
|
|
72d647 |
+++ b/dnf/yum/misc.py
|
|
|
72d647 |
@@ -32,7 +32,6 @@
|
|
|
72d647 |
import dnf.i18n
|
|
|
72d647 |
import errno
|
|
|
72d647 |
import glob
|
|
|
72d647 |
-import gpg
|
|
|
72d647 |
import gzip
|
|
|
72d647 |
import hashlib
|
|
|
72d647 |
import io
|
|
|
72d647 |
@@ -278,7 +277,7 @@ def import_key_to_pubring(rawkey, keyid, gpgdir=None, make_ro_copy=True):
|
|
|
72d647 |
if not os.path.exists(gpgdir):
|
|
|
72d647 |
os.makedirs(gpgdir)
|
|
|
72d647 |
|
|
|
72d647 |
- with dnf.crypto.pubring_dir(gpgdir), gpg.Context() as ctx:
|
|
|
72d647 |
+ with dnf.crypto.pubring_dir(gpgdir), dnf.crypto.Context() as ctx:
|
|
|
72d647 |
# import the key
|
|
|
72d647 |
with open(os.path.join(gpgdir, 'gpg.conf'), 'wb') as fp:
|
|
|
72d647 |
fp.write(b'')
|