Skip to content

Commit 3c84fdf

Browse files
committed
Clean up log messages in NSSDatabase
1 parent c789a47 commit 3c84fdf

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

base/common/python/pki/nssdb.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,6 @@ def run(self,
337337
check=check,
338338
universal_newlines=text)
339339

340-
if capture_output:
341-
logger.debug('stdout:\n%s', result.stdout)
342-
343340
return result
344341

345342
def create(self, enable_trust_policy=False):
@@ -1337,6 +1334,8 @@ def __list_private_keys(self, password_file, token=None):
13371334
# < 1> rsa dcd6cbc1226ede02a961488553b01639ff981cdd someNickame
13381335
#
13391336
# The hex string is the hex-encoded CKA_ID
1337+
logger.debug('stdout:\n%s', out)
1338+
13401339
return re.findall(br'^<\s*\d+>\s+\w+\s+(\w+)', out, re.MULTILINE)
13411340

13421341
def __create_basic_constraints_ext(self, exts, basic_constraints_ext):
@@ -1949,6 +1948,8 @@ def get_trust(self, nickname, token=None):
19491948
stdout = result.stdout.decode()
19501949
stderr = result.stderr.decode()
19511950

1951+
logger.debug('stdout:\n%s', stdout)
1952+
19521953
if stderr:
19531954
logger.error('stderr : %s', stderr)
19541955

@@ -1998,9 +1999,11 @@ def show_cert(self, nickname, token=None):
19981999

19992000
result = self.run(cmd, capture_output=True)
20002001

2001-
output = result.stdout
2002+
output = result.stdout.decode('ascii')
20022003
error = result.stderr
20032004

2005+
logger.debug('stdout:\n%s', output)
2006+
20042007
if error:
20052008
# certutil returned an error
20062009
# raise exception unless its not cert not found
@@ -2013,13 +2016,20 @@ def show_cert(self, nickname, token=None):
20132016
if result.returncode != 0:
20142017
logger.warning('certutil returned non-zero exit code (bug #1539996)')
20152018

2016-
print(output.decode('ascii'))
2019+
print(output)
20172020

20182021
finally:
20192022
shutil.rmtree(tmpdir)
20202023

20212024
def get_cert(self, nickname, token=None, output_format='pem',
20222025
output_text=False):
2026+
'''
2027+
This method returns a PEM pert, a base64-encoded DER cert,
2028+
or a human-readable cert.
2029+
2030+
If output_format=base64 or output_text=True the return type
2031+
will be a Unicode string, otherwise it will be a binary string.
2032+
'''
20232033

20242034
logger.debug('NSSDatabase.get_cert(%s) begins', nickname)
20252035

@@ -2105,6 +2115,13 @@ def get_cert(self, nickname, token=None, output_format='pem',
21052115
# convert to text
21062116
cert_data = cert_data.decode('ascii')
21072117

2118+
if isinstance(cert_data, str):
2119+
output = cert_data
2120+
else:
2121+
output = cert_data.decode('utf-8')
2122+
2123+
logger.debug('stdout:\n%s', output)
2124+
21082125
logger.debug('NSSDatabase.get_cert(%s) ends', nickname)
21092126

21102127
return cert_data

0 commit comments

Comments
 (0)