def _get_private_key_name()

in keyper/__init__.py [0:0]


    def _get_private_key_name(self) -> Optional[str]:

        log.debug("Getting certificate private key name")

        command = [
            "openssl",
            "pkcs12",
            "-in",
            self.path,
            "-nocerts",
            "-passin",
            f"pass:{self.password}",
            "-passout",
            f"pass:{self.password}",
        ]

        try:
            lines = subprocess.run(
                command,
                universal_newlines=True,
                check=True,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                encoding="utf-8",
            ).stdout.split("\n")
        except subprocess.CalledProcessError as ex:
            log.error("Failed to get private key name: %s", ex)
            return None

        key = "friendlyName: "
        lines = [line.strip() for line in lines]
        friendly_names = [line for line in lines if line.startswith(key)]

        if len(friendly_names) != 1:
            log.error(f"Failed to get friendly name: {friendly_names}")
            return None

        value = friendly_names[0][len(key) :]

        log.debug("Friendly name: %s", value)

        return value