WHEW. GPG decryption now works correctly.

This commit is contained in:
brent s. 2020-03-29 20:40:38 -04:00
parent 2545138ae1
commit 2b9b78d3f9
Signed by: bts
GPG Key ID: 8C004C2F93481F6B
3 changed files with 11 additions and 17 deletions

View File

@ -1,7 +0,0 @@
#!/usr/bin/env python3

import vaultpass

cfg = vaultpass.config.LocalFile('/tmp/vaultpass.xml')
cfg.main()

View File

@ -46,8 +46,10 @@ class Config(object):
def decryptGpg(self, gpg_xml):
home = gpg_xml.attrib.get('gpgHome')
tag = gpg_xml.tag
ns_xml = self.xml.find(tag)
xml = self.stripNS(obj = ns_xml).tag
ns_search = './/{0}'.format(tag)
ns_xml = self.namespaced_xml.find(ns_search)
search = './/{0}'.format(self.stripNS(obj = ns_xml).tag)
xml = self.xml.find(search)
fpath = gpg_xml.text
if not self.gpg:
self.gpg = gpg_handler.GPG(home = home)
@ -129,15 +131,14 @@ class Config(object):
return(None)

def parseGpg(self):
gpg_elem_found = False # Change to True if we find any GPG-encrypted elems
gpg_elem_found = False
search = []
for x in self.gpg_elems:
search.append("local-name()='{0}'".format(x))
search = '[{0}]'.format(' or '.join(search))
print(search)
gpg_elems = self.namespaced_xml.findall('|'.join(search))
search = '//*[{0}]'.format(' or '.join(search))
gpg_elems = self.namespaced_xml.xpath(search)
for e in gpg_elems:
print(e)
self.decryptGpg(e)
return(gpg_elem_found)

def parseRaw(self, parser = None):
@ -166,7 +167,7 @@ class Config(object):
_logger.debug('Stripping namespace.')
# https://stackoverflow.com/questions/30232031/how-can-i-strip-namespaces-out-of-an-lxml-tree/30233635#30233635
xpathq = "descendant-or-self::*[namespace-uri()!='']"
if not obj:
if obj is None:
_logger.debug('No XML object selected; using instance\'s xml and tree.')
for x in (self.tree, self.xml):
for e in x.xpath(xpathq):

View File

@ -13,8 +13,7 @@ class GPG(object):
gpg = None

def __init__(self, home = None):
if home:
self.home = home
self.home = home
self.initHome()

def decrypt(self, fpath):
@ -36,4 +35,5 @@ class GPG(object):
if not os.path.isdir(self.home):
raise ValueError('GPG home does not exist')
_logger.debug('Set GPG home to explicitly specified value {0}'.format(self.home))
self.gpg = gpg.Context(home_dir = self.home)
return(None)