Match serials based on output position (fix for non-English languages)

This commit is contained in:
Morgan Willcock 2017-06-02 19:26:50 +01:00
parent 0a08649637
commit 61f817d172

View file

@ -44,7 +44,8 @@ def get_cert_serial(cert_file):
'''
cmd = "certutil.exe -verify {0}".format(cert_file)
out = __salt__['cmd.run'](cmd)
matches = re.search(r"Serial: (.*)", out)
# match serial number by paragraph to work with multiple languages
matches = re.search(r":\w*(.*)\r\n\r\n", out)
if matches is not None:
return matches.groups()[0].strip()
else:
@ -66,7 +67,8 @@ def get_stored_cert_serials(store):
'''
cmd = "certutil.exe -store {0}".format(store)
out = __salt__['cmd.run'](cmd)
matches = re.findall(r"Serial Number: (.*)\r", out)
# match serial numbers by header position to work with multiple languages
matches = re.findall(r"={16}\r\n.*:\s*(\w*)\r\n", out)
return matches