summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/keymanager/wrapper.py
diff options
context:
space:
mode:
authorKali Kaneko (leap communications) <kali@leap.se>2016-10-21 17:05:43 -0400
committerKali Kaneko (leap communications) <kali@leap.se>2016-10-21 17:17:40 -0400
commitce504db409ca2db4df5be807d636120d210061ad (patch)
treee1122da662d45ba3ddfb8914ecb8a654719d09ca /src/leap/bitmask/keymanager/wrapper.py
parent7c2a489725293bba7de8b8238fb1c5c7f1e30a47 (diff)
[bug] fallback to python-gnupg as a workaround
currently windows 7 support is broken with gnupg.
Diffstat (limited to 'src/leap/bitmask/keymanager/wrapper.py')
-rw-r--r--src/leap/bitmask/keymanager/wrapper.py39
1 files changed, 35 insertions, 4 deletions
diff --git a/src/leap/bitmask/keymanager/wrapper.py b/src/leap/bitmask/keymanager/wrapper.py
index 4f36cec..1fd4429 100644
--- a/src/leap/bitmask/keymanager/wrapper.py
+++ b/src/leap/bitmask/keymanager/wrapper.py
@@ -18,12 +18,25 @@
GPG wrapper for temporary keyrings
"""
import os
+import platform
import shutil
import tempfile
+
from gnupg import GPG
+from twisted.logger import Logger
+
from leap.common.check import leap_assert
+try:
+ from gnupg.gnupg import GPGUtilities
+ GNUPG_NG = True
+except ImportError:
+ GNUPG_NG = False
+
+
+logger = Logger()
+
class TempGPGWrapper(object):
"""
@@ -88,8 +101,16 @@ class TempGPGWrapper(object):
listkeys = lambda: self._gpg.list_keys()
listsecretkeys = lambda: self._gpg.list_keys(secret=True)
- self._gpg = GPG(binary=self._gpgbinary,
- homedir=tempfile.mkdtemp())
+ try:
+ self._gpg = GPG(binary=self._gpgbinary,
+ homedir=tempfile.mkdtemp())
+ except TypeError:
+ # compat-mode with python-gnupg until windows
+ # support is fixed in gnupg-ng
+ self._gpg = GPG(gpgbinary=self._gpgbinary,
+ gnupghome=tempfile.mkdtemp(),
+ options=[])
+
leap_assert(len(listkeys()) is 0, 'Keyring not empty.')
# import keys into the keyring:
@@ -129,6 +150,16 @@ class TempGPGWrapper(object):
raise
finally:
- leap_assert(self._gpg.homedir != os.path.expanduser('~/.gnupg'),
+ try:
+ homedir = self._gpg.homedir
+ except AttributeError:
+ homedir = self._gpg.gnupghome
+ leap_assert(homedir != os.path.expanduser('~/.gnupg'),
"watch out! Tried to remove default gnupg home!")
- shutil.rmtree(self._gpg.homedir)
+ # TODO some windows debug ....
+ homedir = os.path.normpath(homedir).replace("\\", "/")
+ homedir = str(homedir.replace("c:/", "c://"))
+ if platform.system() == "Windows":
+ logger.error("BUG! Not erasing folder in Windows")
+ return
+ shutil.rmtree(homedir)