How to use the josepy.JWKRSA.load function in josepy

To help you get started, we’ve selected a few josepy 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 / certbot / plugins / dns_test_common.py View on Github external
"""Base test class for DNS authenticators."""

import configobj
import josepy as jose
import mock
import six

from acme import challenges

from certbot import achallenges
from certbot.compat import security
from certbot.tests import acme_util
from certbot.tests import util as test_util

DOMAIN = 'example.com'
KEY = jose.JWKRSA.load(test_util.load_vector("rsa512_key.pem"))


class BaseAuthenticatorTest(object):
    """
    A base test class to reduce duplication between test code for DNS Authenticator Plugins.

    Assumes:
     * That subclasses also subclass unittest.TestCase
     * That the authenticator is stored as self.auth
    """

    achall = achallenges.KeyAuthorizationAnnotatedChallenge(
        challb=acme_util.DNS01, domain=DOMAIN, account_key=KEY)

    def test_more_info(self):
        # pylint: disable=no-member
github certbot / certbot / certbot / certbot / plugins / dns_test_common_lexicon.py View on Github external
"""Base test class for DNS authenticators built on Lexicon."""

import josepy as jose
import mock
from requests.exceptions import HTTPError
from requests.exceptions import RequestException

from certbot import errors
from certbot.plugins import dns_test_common
from certbot.tests import util as test_util

DOMAIN = 'example.com'
KEY = jose.JWKRSA.load(test_util.load_vector("rsa512_key.pem"))

# These classes are intended to be subclassed/mixed in, so not all members are defined.
# pylint: disable=no-member

class BaseLexiconAuthenticatorTest(dns_test_common.BaseAuthenticatorTest):

    def test_perform(self):
        self.auth.perform([self.achall])

        expected = [mock.call.add_txt_record(DOMAIN, '_acme-challenge.'+DOMAIN, mock.ANY)]
        self.assertEqual(expected, self.mock_client.mock_calls)

    def test_cleanup(self):
        self.auth._attempt_cleanup = True  # _attempt_cleanup | pylint: disable=protected-access
        self.auth.cleanup([self.achall])
github aptise / peter_sslers / peter_sslers / lib / cert_utils.py View on Github external
"""
    :param key_pem_filepath: (required) the filepath to a PEM encoded RSA account key file.

    This routine will use crypto/certbot if available.
    If not, openssl is used via subprocesses

    This includes code from acme-tiny [https://github.com/diafygi/acme-tiny]
    acme-tiny is released under the MIT license and Copyright (c) 2015 Daniel Roesler
    """
    log.info("account_key__parse >")
    alg = "RS256"
    if josepy:
        if not key_pem:
            raise ValueError("submit key_pem!!!")
            key_pem = open(key_pem_filepath).read()
        _jwk = josepy.JWKRSA.load(key_pem.encode("utf8"))
        jwk = _jwk.public_key().fields_to_partial_json()
        jwk["kty"] = "RSA"
        thumbprint = _b64(_jwk.thumbprint())
    else:
        log.debug(".account_key__parse > openssl fallback")
        with psutil.Popen(
            [openssl_path, "rsa", "-in", key_pem_filepath, "-noout", "-text",],
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
        ) as proc:
            out, err = proc.communicate()
            if six.PY3:
                out = out.decode("utf8")
        pub_pattern = r"modulus:[\s]+?00:([a-f0-9\:\s]+?)\npublicExponent: ([0-9]+)"
        pub_hex, pub_exp = re.search(