After some troubleshooting, we found a nice solution for this bug, which
is transforming password to string with utf-8 as below:

    def setup_database(
            db_dir, password=None, over_write=False, password_file=None):
        """ Create an NSS database """
        if os.path.exists(db_dir):
            if not over_write:
                raise IOError("Directory already exists.")
            if os.path.isdir(db_dir):
                shutil.rmtree(db_dir)
            else:
                os.remove(db_dir)
        os.makedirs(db_dir)

        try:
            if password:
                (f, password_file) = tempfile.mkstemp()
                os.write(f, str(password).encode('utf-8'))
                os.close(f)

            command = ['certutil', '-N', '-d', db_dir, '-f', password_file]
            subprocess.check_call(command)
        except Exception as e:
            LOG.info(str(e))

        finally:
            if password and password_file:
                os.remove(password_file)


However, that was not the last problem with this library. I faced another error 
inside import_cert function:
        # certutil -A -d db_dir -n cert_nick -t trust -i cert_file
        with tempfile.NamedTemporaryFile() as cert_file:
            cert_file.write(content)
            cert_file.flush()
            command = ['certutil', '-A', '-d', self.certdb_dir,
                       '-n', cert_nick, '-t', trust,
                       '-i', cert_file.name]
            subprocess.check_call(command)

Which finished with such error:
Command '['/us
r/bin/certutil', '-A', '-d', '/etc/barbican/alias', '-n', 'KRA transport cert', 
'-t', 'u,u,u', '-i', '/tmp/tmp7djgq3r6']' returned non-zero exit status 255.


I believe there can be more issues with testing it against ubuntu.

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1905473

Title:
  NSS DB can't be created with barbican stein

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/barbican/+bug/1905473/+subscriptions

-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to