🐛 Add support for /usr/lib/firefox and /usr/lib/thunderbird libnss3.so locations

This commit is contained in:
Renato Alves
2025-10-31 10:17:55 +01:00
parent 8a5fdeb8c8
commit 7d86cb2969

View File

@@ -212,38 +212,40 @@ def find_nss(locations: list[str], nssname: str) -> ct.CDLL:
fail_errors: list[tuple[str, str]] = [] fail_errors: list[tuple[str, str]] = []
OS = ("Windows", "Darwin") OS = ("Windows", "Darwin")
sublocations = ("firefox", "thunderbird", "")
for loc in locations: for loc in locations:
nsslib = os.path.join(loc, nssname) for subloc in sublocations:
LOG.debug("Loading NSS library from %s", nsslib) nsslib = os.path.join(loc, subloc, nssname)
LOG.debug("Loading NSS library from %s", nsslib)
if SYSTEM in OS: if SYSTEM in OS:
# On windows in order to find DLLs referenced by nss3.dll # On windows in order to find DLLs referenced by nss3.dll
# we need to have those locations on PATH # we need to have those locations on PATH
os.environ["PATH"] = ";".join([loc, os.environ["PATH"]]) os.environ["PATH"] = ";".join([loc, os.environ["PATH"]])
LOG.debug("PATH is now %s", os.environ["PATH"]) LOG.debug("PATH is now %s", os.environ["PATH"])
# However this doesn't seem to work on all setups and needs to be # However this doesn't seem to work on all setups and needs to be
# set before starting python so as a workaround we chdir to # set before starting python so as a workaround we chdir to
# Firefox's nss3.dll/libnss3.dylib location # Firefox's nss3.dll/libnss3.dylib location
if loc: if loc:
if not os.path.isdir(loc): if not os.path.isdir(loc):
# No point in trying to load from paths that don't exist # No point in trying to load from paths that don't exist
continue continue
workdir = os.getcwd() workdir = os.getcwd()
os.chdir(loc) os.chdir(loc)
try: try:
nss: ct.CDLL = ct.CDLL(nsslib) nss: ct.CDLL = ct.CDLL(nsslib)
except OSError as e: except OSError as e:
fail_errors.append((nsslib, str(e))) fail_errors.append((nsslib, str(e)))
else: else:
LOG.debug("Loaded NSS library from %s", nsslib) LOG.debug("Loaded NSS library from %s", nsslib)
return nss return nss
finally: finally:
if SYSTEM in OS and loc: if SYSTEM in OS and loc:
# Restore workdir changed above # Restore workdir changed above
os.chdir(workdir) os.chdir(workdir)
else: else:
LOG.error( LOG.error(