How to use the letsencrypt.display.util function in letsencrypt

To help you get started, we’ve selected a few letsencrypt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github certbot / certbot / letsencrypt / display / ops.py View on Github external
:param list prepared: List of `~.PluginEntryPoint`.
    :param str question: Question to be presented to the user.

    :returns: Plugin entry point chosen by the user.
    :rtype: `~.PluginEntryPoint`

    """
    opts = [plugin_ep.description_with_name +
            (" [Misconfigured]" if plugin_ep.misconfigured else "")
            for plugin_ep in prepared]

    while True:
        code, index = util(interfaces.IDisplay).menu(
            question, opts, help_label="More Info")

        if code == display_util.OK:
            plugin_ep = prepared[index]
            if plugin_ep.misconfigured:
                util(interfaces.IDisplay).notification(
                    "The selected plugin encountered an error while parsing "
                    "your server configuration and cannot be used. The error "
                    "was:\n\n{0}".format(plugin_ep.prepare()),
                    height=display_util.HEIGHT, pause=False)
            else:
                return plugin_ep
        elif code == display_util.HELP:
            if prepared[index].misconfigured:
                msg = "Reported Error: %s" % prepared[index].prepare()
            else:
                msg = prepared[index].init().more_info()
            util(interfaces.IDisplay).notification(
                msg, height=display_util.HEIGHT)
github certbot / certbot / letsencrypt / cli.py View on Github external
# private key! #525
    le_util.make_or_verify_dir(
        args.logs_dir, 0o700, os.geteuid(), "--strict-permissions" in cli_args)
    setup_logging(args, _cli_log_handler, logfile='letsencrypt.log')

    # do not log `args`, as it contains sensitive data (e.g. revoke --key)!
    logger.debug("Arguments: %r", cli_args)
    logger.debug("Discovered plugins: %r", plugins)

    sys.excepthook = functools.partial(_handle_exception, args=args)

    # Displayer
    if args.text_mode:
        displayer = display_util.FileDisplay(sys.stdout)
    else:
        displayer = display_util.NcursesDisplay()
    zope.component.provideUtility(displayer)

    # Reporter
    report = reporter.Reporter()
    zope.component.provideUtility(report)
    atexit.register(report.atexit_print_messages)

    # TODO: remove developer EULA prompt for the launch
    if not config.eula:
        eula = pkg_resources.resource_string("letsencrypt", "EULA")
        if not zope.component.getUtility(interfaces.IDisplay).yesno(
                eula, "Agree", "Cancel"):
            raise errors.Error("Must agree to TOS")

    if not os.geteuid() == 0:
        logger.warning(
github certbot / certbot / letsencrypt / cert_manager.py View on Github external
def _more_info(self, selection):
        """Displays more info about the cert.

        :param str selection: Selection from display_certs

        """
        if self._is_lineage(selection):
            info = self._more_info_lineage(self.certs[int(selection)])
        else:
            lineage, version = self._lineage_version(selection)
            info = self._more_info_cert(lineage, version)

        zope.component.getUtility(interfaces.IDisplay).notification(
            info, height=display_util.HEIGHT)
github certbot / certbot / letsencrypt / display / ops.py View on Github external
def _choose_names_manually():
    """Manually input names for those without an installer."""

    code, input_ = util(interfaces.IDisplay).input(
        "Please enter in your domain name(s) (comma and/or space separated) ")

    if code == display_util.OK:
        invalid_domains = dict()
        retry_message = ""
        try:
            domain_list = display_util.separate_list_input(input_)
        except UnicodeEncodeError:
            domain_list = []
            retry_message = (
                "Internationalized domain names are not presently "
                "supported.{0}{0}Would you like to re-enter the "
                "names?{0}").format(os.linesep)

        for domain in domain_list:
            try:
                le_util.check_domain_sanity(domain)
            except errors.ConfigurationError as e:
                invalid_domains[domain] = e.message

        if len(invalid_domains):
            retry_message = (
                "One or more of the entered domain names was not valid:"
github certbot / certbot / letsencrypt / proof_of_possession.py View on Github external
except ValueError:
                try:
                    cert_obj = x509.load_der_x509_certificate(
                        cert_data, default_backend())
                except ValueError:
                    logger.warn("Certificate is neither PER nor DER: %s", cert)

            cert_key = achall.alg.kty(key=cert_obj.public_key())
            if cert_key == achall.hints.jwk:
                return self._gen_response(achall, key)

        # Is there are different prompt we should give the user?
        code, key = zope.component.getUtility(
            interfaces.IDisplay).input(
                "Path to private key for identifier: %s " % achall.domain)
        if code != display_util.CANCEL:
            return self._gen_response(achall, key)

        # If we get here, the key wasn't found
        return False
github certbot / certbot / letsencrypt / revoker.py View on Github external
def pretty_print(self):
        """Nicely frames a cert str"""
        frame = "-" * (display_util.WIDTH - 4) + os.linesep
        return "{frame}{cert}{frame}".format(frame=frame, cert=str(self))
github certbot / certbot / letsencrypt / display / ops.py View on Github external
a valid-looking email

    :returns: Email or ``None`` if cancelled by user.
    :rtype: str

    """
    msg = "Enter email address (used for urgent notices and lost key recovery)"
    if invalid:
        msg = "There seem to be problems with that address. " + msg
    if more:
        msg += ('\n\nIf you really want to skip this, you can run the client with '
                '--register-unsafely-without-email but make sure you backup your '
                'account key from /etc/letsencrypt/accounts\n\n')
    code, email = zope.component.getUtility(interfaces.IDisplay).input(msg)

    if code == display_util.OK:
        if le_util.safe_email(email):
            return email
        else:
            # TODO catch the server's ACME invalid email address error, and
            # make a similar call when that happens
            return get_email(more=True, invalid=(email != ""))
    else:
        return None
github certbot / certbot / letsencrypt / revoker.py View on Github external
def revoke_from_menu(self):
        """List trusted Let's Encrypt certificates."""

        csha1_vhlist = self._get_installed_locations()
        certs = self._populate_saved_certs(csha1_vhlist)

        while True:
            if certs:
                code, selection = revocation.display_certs(certs)

                if code == display_util.OK:
                    revoked_certs = self._safe_revoke([certs[selection]])
                    # Since we are currently only revoking one cert at a time...
                    if revoked_certs:
                        del certs[selection]
                elif code == display_util.HELP:
                    revocation.more_info_cert(certs[selection])
                else:
                    return
            else:
                logger.info(
                    "There are not any trusted Let's Encrypt "
                    "certificates for this server.")
                return
github certbot / certbot / letsencrypt / cert_manager.py View on Github external
:param list certs: each is a :class:`letsencrypt.storage.RenewableCert`
        :param str question: Question to display
        :param str ok_label: Label of ok button
        :param str extra_label: Label of additional button

        :returns: tuple of the form (`code`, `selection`) where
            code is a display exit code
            selection is the user's str selection tag
        :rtype: tuple

        """
        # nodes - where each is a (tag, item, status, depth) tuple
        # `depth` = how many tabs in
        nodes = []
        # 12 is for ' (*) ' and other box spacing requirements
        free_chars = display_util.WIDTH - 12

        for i, cert in enumerate(certs):
            item = (
                "{names:{name_len}s}".format(
                    names=" ".join(cert.names())[:free_chars],
                    name_len=free_chars,
                )
            )
            if i == 0:
                nodes.append((str(i), item, "on", 0))
            else:
                nodes.append((str(i), item, "off", 0))

            self.append_lineage(cert, nodes, str(i))

        code, tag = zope.component.getUtility(interfaces.IDisplay).treeview(