コード例 #1
0
 def test_gen_check_validation_wrong_key(self):
     key1 = jose.JWKRSA.load(test_util.load_vector('rsa512_key.pem'))
     key2 = jose.JWKRSA.load(test_util.load_vector('rsa1024_key.pem'))
     self.assertFalse(
         self.resp_http.check_validation(
             validation=self.resp_http.gen_validation(self.chall, key1),
             chall=self.chall,
             account_public_key=key2.public_key()))
コード例 #2
0
 def test_gen_check_validation(self):
     account_key = jose.JWKRSA.load(test_util.load_vector('rsa512_key.pem'))
     self.assertTrue(
         self.resp_http.check_validation(
             validation=self.resp_http.gen_validation(
                 self.chall, account_key),
             chall=self.chall,
             account_public_key=account_key.public_key()))
コード例 #3
0
 def setUp(self):
     self.account_key = jose.JWKRSA.load(
         test_util.load_vector('rsa512_key.pem'))
     from acme.challenges import DNS
     self.msg = DNS(token=jose.b64decode(
         b'evaGxfADs6pSRb2LAv9IZf17Dt3juxGJ-PCt92wr-oA'))
     self.jmsg = {
         'type': 'dns',
         'token': 'evaGxfADs6pSRb2LAv9IZf17Dt3juxGJ-PCt92wr-oA',
     }
コード例 #4
0
    def setUp(self):
        self.account_key = jose.JWK.load(
            test_util.load_vector('rsa1024_key.pem'))
        self.resources = set() # type: Set

        from acme.standalone import HTTP01DualNetworkedServers
        self.servers = HTTP01DualNetworkedServers(('', 0), resources=self.resources)

        self.port = self.servers.getsocknames()[0][1]
        self.servers.serve_forever()
コード例 #5
0
 def test_simple_verify_good_validation(self, mock_get):
     account_key = jose.JWKRSA.load(test_util.load_vector('rsa512_key.pem'))
     for resp in self.resp_http, self.resp_https:
         mock_get.reset_mock()
         validation = resp.gen_validation(self.chall, account_key)
         mock_get.return_value = mock.MagicMock(
             text=validation.json_dumps(), headers=self.good_headers)
         self.assertTrue(resp.simple_verify(self.chall, "local", None))
         mock_get.assert_called_once_with(resp.uri("local", self.chall),
                                          verify=False)
コード例 #6
0
 def setUp(self):
     self.account_key = jose.JWKRSA.load(
         test_util.load_vector('rsa512_key.pem'))
     from acme.challenges import DNS
     self.msg = DNS(token=jose.b64decode(
         b'evaGxfADs6pSRb2LAv9IZf17Dt3juxGJ-PCt92wr-oA'))
     self.jmsg = {
         'type': 'dns',
         'token': 'evaGxfADs6pSRb2LAv9IZf17Dt3juxGJ-PCt92wr-oA',
     }
コード例 #7
0
ファイル: standalone_test.py プロジェクト: certbot/certbot
    def setUp(self):
        self.account_key = jose.JWK.load(
            test_util.load_vector('rsa1024_key.pem'))
        self.resources = set() # type: Set

        from acme.standalone import HTTP01DualNetworkedServers
        self.servers = HTTP01DualNetworkedServers(('', 0), resources=self.resources)

        self.port = self.servers.getsocknames()[0][1]
        self.servers.serve_forever()
コード例 #8
0
 def test_simple_verify_good_validation(self, mock_get):
     account_key = jose.JWKRSA.load(test_util.load_vector('rsa512_key.pem'))
     for resp in self.resp_http, self.resp_https:
         mock_get.reset_mock()
         validation = resp.gen_validation(self.chall, account_key)
         mock_get.return_value = mock.MagicMock(
             text=validation.json_dumps(), headers=self.good_headers)
         self.assertTrue(resp.simple_verify(self.chall, "local", None))
         mock_get.assert_called_once_with(resp.uri(
             "local", self.chall), verify=False)
コード例 #9
0
 def test_check_validation_wrong_payload(self):
     account_key = jose.JWKRSA.load(test_util.load_vector('rsa512_key.pem'))
     validations = tuple(
         jose.JWS.sign(payload=payload, alg=jose.RS256, key=account_key)
         for payload in (b'', b'{}', self.chall.json_dumps().encode('utf-8'),
                         self.resp_http.json_dumps().encode('utf-8'))
     )
     for validation in validations:
         self.assertFalse(self.resp_http.check_validation(
             validation=validation, chall=self.chall,
             account_public_key=account_key.public_key()))
コード例 #10
0
    def setUp(self):
        self.account_key = jose.JWK.load(
            test_util.load_vector('rsa1024_key.pem'))
        self.resources = set() # type: Set

        from acme.standalone import HTTP01Server
        self.server = HTTP01Server(('', 0), resources=self.resources)

        self.port = self.server.socket.getsockname()[1]
        self.thread = threading.Thread(target=self.server.serve_forever)
        self.thread.start()
コード例 #11
0
ファイル: standalone_test.py プロジェクト: certbot/certbot
    def setUp(self):
        self.account_key = jose.JWK.load(
            test_util.load_vector('rsa1024_key.pem'))
        self.resources = set() # type: Set

        from acme.standalone import HTTP01Server
        self.server = HTTP01Server(('', 0), resources=self.resources)

        self.port = self.server.socket.getsockname()[1]
        self.thread = threading.Thread(target=self.server.serve_forever)
        self.thread.start()
コード例 #12
0
    def setUp(self):
        self.account_key = jose.JWK.load(
            test_util.load_vector('rsa1024_key.pem'))
        self.resources = set()

        from acme.standalone import SimpleHTTPServer
        self.server = SimpleHTTPServer(('', 0), resources=self.resources)

        # pylint: disable=no-member
        self.port = self.server.socket.getsockname()[1]
        self.thread = threading.Thread(target=self.server.handle_request)
        self.thread.start()
コード例 #13
0
ファイル: standalone_test.py プロジェクト: 0xPoly/letsencrypt
    def setUp(self):
        self.account_key = jose.JWK.load(
            test_util.load_vector('rsa1024_key.pem'))
        self.resources = set()

        from acme.standalone import SimpleHTTPServer
        self.server = SimpleHTTPServer(('', 0), resources=self.resources)

        # pylint: disable=no-member
        self.port = self.server.socket.getsockname()[1]
        self.thread = threading.Thread(target=self.server.serve_forever)
        self.thread.start()
コード例 #14
0
 def test_check_validation_wrong_fields(self):
     resource = self.resp_http.gen_resource(self.chall)
     account_key = jose.JWKRSA.load(test_util.load_vector('rsa512_key.pem'))
     validations = tuple(
         jose.JWS.sign(payload=bad_resource.json_dumps().encode('utf-8'),
                       alg=jose.RS256, key=account_key)
         for bad_resource in (resource.update(tls=True),
                              resource.update(token=(b'x' * 20)))
     )
     for validation in validations:
         self.assertFalse(self.resp_http.check_validation(
             validation=validation, chall=self.chall,
             account_public_key=account_key.public_key()))
コード例 #15
0
    def setUp(self):
        self.cert = test_util.load_cert('cert.pem')
        key = OpenSSL.crypto.load_privatekey(
            OpenSSL.crypto.FILETYPE_PEM,
            test_util.load_vector('rsa512_key.pem'))
        # pylint: disable=protected-access
        certs = {b'foo': (key, self.cert._wrapped)}

        sock = socket.socket()
        sock.bind(('', 0))  # pick random port
        self.port = sock.getsockname()[1]

        self.server = threading.Thread(target=self._run_server, args=(certs, sock))
        self.server.start()
        time.sleep(1)  # TODO: avoid race conditions in other way
コード例 #16
0
    def setUp(self):
        self.cert = test_util.load_cert('cert.pem')
        key = OpenSSL.crypto.load_privatekey(
            OpenSSL.crypto.FILETYPE_PEM,
            test_util.load_vector('rsa512_key.pem'))
        # pylint: disable=protected-access
        certs = {b'foo': (key, self.cert._wrapped)}

        sock = socket.socket()
        sock.bind(('', 0))  # pick random port
        self.port = sock.getsockname()[1]

        self.server = threading.Thread(target=self._run_server, args=(certs, sock))
        self.server.start()
        time.sleep(1)  # TODO: avoid race conditions in other way
コード例 #17
0
    def setUp(self):
        # disable insecure requests warning, obviously they are not secure!
        from requests.packages.urllib3.exceptions import InsecureRequestWarning
        requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

        self.account_key = jose.JWK.load(
            test_util.load_vector('rsa1024_key.pem'))
        self.resources = set()

        # pylint: disable=no-member
        self.redirect_server = socketserver.TCPServer(('', 0), RedirectHandler)
        self.port = self.redirect_server.socket.getsockname()[1]
        self.redirect_thread = threading.Thread(
            target=self.redirect_server.serve_forever)
        self.redirect_thread.start()

        from acme.standalone import HTTP01TLSServer
        self.server = HTTP01TLSServer(('', 0), self.resources)
        self.thread = threading.Thread(target=self.server.serve_forever)
        self.thread.start()

        # make sure the redirect server directs to the port where the TLS
        # server is running
        RedirectHandler.port = self.server.socket.getsockname()[1]
コード例 #18
0
ファイル: jwk_test.py プロジェクト: jepler/letsencrypt
"""Tests for acme.jose.jwk."""
import unittest

from acme import test_util

from acme.jose import errors
from acme.jose import json_util
from acme.jose import util


DSA_PEM = test_util.load_vector('dsa512_key.pem')
RSA256_KEY = test_util.load_rsa_private_key('rsa256_key.pem')
RSA512_KEY = test_util.load_rsa_private_key('rsa512_key.pem')


class JWKTest(unittest.TestCase):
    """Tests for acme.jose.jwk.JWK."""

    def test_load(self):
        from acme.jose.jwk import JWK
        self.assertRaises(errors.Error, JWK.load, DSA_PEM)

    def test_load_subclass_wrong_type(self):
        from acme.jose.jwk import JWKRSA
        self.assertRaises(errors.Error, JWKRSA.load, DSA_PEM)


class JWKTestBaseMixin(object):
    """Mixin test for JWK subclass tests."""

    thumbprint = NotImplemented
コード例 #19
0
 def test_simple_verify_wrong_account_key(self):
     self.assertFalse(
         self.msg.simple_verify(
             self.chall, self.domain,
             jose.JWKRSA.load(
                 test_util.load_vector('rsa256_key.pem')).public_key()))
コード例 #20
0
ファイル: jwk_test.py プロジェクト: jepler/letsencrypt
 def test_load(self):
     from acme.jose.jwk import JWKRSA
     self.assertEqual(self.private, JWKRSA.load(
         test_util.load_vector('rsa256_key.pem')))
コード例 #21
0
ファイル: client_test.py プロジェクト: Jonadabe/letsencrypt
from six.moves import http_client  # pylint: disable=import-error

import mock
import requests

from acme import challenges
from acme import errors
from acme import jose
from acme import jws as acme_jws
from acme import messages
from acme import messages_test
from acme import test_util


CERT_DER = test_util.load_vector("cert.der")
KEY = jose.JWKRSA.load(test_util.load_vector("rsa512_key.pem"))
KEY2 = jose.JWKRSA.load(test_util.load_vector("rsa256_key.pem"))


class ClientTest(unittest.TestCase):
    """Tests for  acme.client.Client."""

    # pylint: disable=too-many-instance-attributes,too-many-public-methods

    def setUp(self):
        self.response = mock.MagicMock(ok=True, status_code=http_client.OK, headers={}, links={})
        self.net = mock.MagicMock()
        self.net.post.return_value = self.response
        self.net.get.return_value = self.response
コード例 #22
0
 def test_gen_check_validation_wrong_key(self):
     key1 = jose.JWKRSA.load(test_util.load_vector('rsa512_key.pem'))
     key2 = jose.JWKRSA.load(test_util.load_vector('rsa1024_key.pem'))
     self.assertFalse(self.resp_http.check_validation(
         validation=self.resp_http.gen_validation(self.chall, key1),
         chall=self.chall, account_public_key=key2.public_key()))
コード例 #23
0
 def test_gen_check_validation_wrong_key(self):
     key2 = jose.JWKRSA.load(test_util.load_vector('rsa1024_key.pem'))
     self.assertFalse(self.msg.check_validation(
         self.msg.gen_validation(KEY), key2.public_key()))
コード例 #24
0
 def test_simple_verify_failure(self):
     key2 = jose.JWKRSA.load(test_util.load_vector('rsa256_key.pem'))
     public_key = key2.public_key()
     verified = self.response.simple_verify(self.chall, "local", public_key)
     self.assertFalse(verified)
コード例 #25
0
 def test_simple_verify_failure(self):
     key2 = jose.JWKRSA.load(test_util.load_vector('rsa256_key.pem'))
     public_key = key2.public_key()
     verified = self.response.simple_verify(self.chall, "local", public_key)
     self.assertFalse(verified)
コード例 #26
0
 def test_simple_verify_bad_key_authorization(self):
     key2 = jose.JWKRSA.load(test_util.load_vector('rsa256_key.pem'))
     self.response.simple_verify(self.chall, "local", key2.public_key())
コード例 #27
0
 def test_gen_check_validation(self):
     account_key = jose.JWKRSA.load(test_util.load_vector('rsa512_key.pem'))
     self.assertTrue(self.resp_http.check_validation(
         validation=self.resp_http.gen_validation(self.chall, account_key),
         chall=self.chall, account_public_key=account_key.public_key()))
コード例 #28
0
ファイル: client_test.py プロジェクト: rwky/certbot
from six.moves import http_client  # pylint: disable=import-error

import josepy as jose
import mock
import requests

from acme import challenges
from acme import errors
from acme import jws as acme_jws
from acme import messages
from acme import messages_test
from acme import test_util


CERT_DER = test_util.load_vector('cert.der')
CERT_SAN_PEM = test_util.load_vector('cert-san.pem')
CSR_SAN_PEM = test_util.load_vector('csr-san.pem')
KEY = jose.JWKRSA.load(test_util.load_vector('rsa512_key.pem'))
KEY2 = jose.JWKRSA.load(test_util.load_vector('rsa256_key.pem'))

DIRECTORY_V1 = messages.Directory({
    messages.NewRegistration:
        'https://www.letsencrypt-demo.org/acme/new-reg',
    messages.Revocation:
        'https://www.letsencrypt-demo.org/acme/revoke-cert',
    messages.NewAuthorization:
        'https://www.letsencrypt-demo.org/acme/new-authz',
    messages.CertificateRequest:
        'https://www.letsencrypt-demo.org/acme/new-cert',
})
コード例 #29
0
ファイル: jws_test.py プロジェクト: 1resu/letsencrypt
"""Tests for acme.jws."""
import unittest

from acme import jose
from acme import test_util


KEY = jose.JWKRSA.load(test_util.load_vector('rsa512_key.pem'))


class HeaderTest(unittest.TestCase):
    """Tests for acme.jws.Header."""

    good_nonce = jose.encode_b64jose(b'foo')
    wrong_nonce = u'F'
    # Following just makes sure wrong_nonce is wrong
    try:
        jose.b64decode(wrong_nonce)
    except (ValueError, TypeError):
        assert True
    else:
        assert False  # pragma: no cover

    def test_nonce_decoder(self):
        from acme.jws import Header
        nonce_field = Header._fields['nonce']

        self.assertRaises(
            jose.DeserializationError, nonce_field.decode, self.wrong_nonce)
        self.assertEqual(b'foo', nonce_field.decode(self.good_nonce))
コード例 #30
0
 def test_gen_check_validation_wrong_key(self):
     key2 = jose.JWKRSA.load(test_util.load_vector('rsa1024_key.pem'))
     self.assertFalse(self.msg.check_validation(
         self.msg.gen_validation(self.account_key), key2.public_key()))
コード例 #31
0
ファイル: jws_test.py プロジェクト: 792685970/bootking
"""Tests for acme.jose.jws."""
import base64
import unittest

import mock
import OpenSSL

from acme import test_util

from acme.jose import errors
from acme.jose import json_util
from acme.jose import jwa
from acme.jose import jwk

CERT = test_util.load_comparable_cert('cert.pem')
KEY = jwk.JWKRSA.load(test_util.load_vector('rsa512_key.pem'))


class MediaTypeTest(unittest.TestCase):
    """Tests for acme.jose.jws.MediaType."""
    def test_decode(self):
        from acme.jose.jws import MediaType
        self.assertEqual('application/app',
                         MediaType.decode('application/app'))
        self.assertEqual('application/app', MediaType.decode('app'))
        self.assertRaises(errors.DeserializationError, MediaType.decode,
                          'app;foo')

    def test_encode(self):
        from acme.jose.jws import MediaType
        self.assertEqual('app', MediaType.encode('application/app'))
コード例 #32
0
ファイル: jws_test.py プロジェクト: Ghostff/letsencrypt
import base64
import unittest

import mock
import OpenSSL

from acme import test_util

from acme.jose import errors
from acme.jose import json_util
from acme.jose import jwa
from acme.jose import jwk


CERT = test_util.load_comparable_cert("cert.pem")
KEY = jwk.JWKRSA.load(test_util.load_vector("rsa512_key.pem"))


class MediaTypeTest(unittest.TestCase):
    """Tests for acme.jose.jws.MediaType."""

    def test_decode(self):
        from acme.jose.jws import MediaType

        self.assertEqual("application/app", MediaType.decode("application/app"))
        self.assertEqual("application/app", MediaType.decode("app"))
        self.assertRaises(errors.DeserializationError, MediaType.decode, "app;foo")

    def test_encode(self):
        from acme.jose.jws import MediaType
コード例 #33
0
 def test_simple_verify_bad_key_authorization(self):
     key2 = jose.JWKRSA.load(test_util.load_vector('rsa256_key.pem'))
     self.response.simple_verify(self.chall, "local", key2.public_key())
コード例 #34
0
ファイル: client_test.py プロジェクト: bad194/certbot
from six.moves import http_client  # pylint: disable=import-error

import mock
import requests

from acme import challenges
from acme import errors
from acme import jose
from acme import jws as acme_jws
from acme import messages
from acme import messages_test
from acme import test_util


CERT_DER = test_util.load_vector('cert.der')
KEY = jose.JWKRSA.load(test_util.load_vector('rsa512_key.pem'))
KEY2 = jose.JWKRSA.load(test_util.load_vector('rsa256_key.pem'))


class ClientTest(unittest.TestCase):
    """Tests for  acme.client.Client."""
    # pylint: disable=too-many-instance-attributes,too-many-public-methods

    def setUp(self):
        self.response = mock.MagicMock(
            ok=True, status_code=http_client.OK, headers={}, links={})
        self.net = mock.MagicMock()
        self.net.post.return_value = self.response
        self.net.get.return_value = self.response
コード例 #35
0
ファイル: jwk_test.py プロジェクト: fmarier/letsencrypt
"""Tests for acme.jose.jwk."""
import unittest

from acme import test_util

from acme.jose import errors
from acme.jose import json_util
from acme.jose import util


DSA_PEM = test_util.load_vector('dsa512_key.pem')
RSA256_KEY = test_util.load_rsa_private_key('rsa256_key.pem')
RSA512_KEY = test_util.load_rsa_private_key('rsa512_key.pem')


class JWKTest(unittest.TestCase):
    """Tests for acme.jose.jwk.JWK."""

    def test_load(self):
        from acme.jose.jwk import JWK
        self.assertRaises(errors.Error, JWK.load, DSA_PEM)

    def test_load_subclass_wrong_type(self):
        from acme.jose.jwk import JWKRSA
        self.assertRaises(errors.Error, JWKRSA.load, DSA_PEM)


class JWKOctTest(unittest.TestCase):
    """Tests for acme.jose.jwk.JWKOct."""

    def setUp(self):
コード例 #36
0
 def test_simple_verify_wrong_account_key(self):
     self.assertFalse(self.msg.simple_verify(
         self.chall, self.domain, jose.JWKRSA.load(
             test_util.load_vector('rsa256_key.pem')).public_key()))
コード例 #37
0
ファイル: client_test.py プロジェクト: sedrubal/certbot
import unittest

from six.moves import http_client  # pylint: disable=import-error

import mock
import requests

from acme import challenges
from acme import errors
from acme import jose
from acme import jws as acme_jws
from acme import messages
from acme import messages_test
from acme import test_util

CERT_DER = test_util.load_vector('cert.der')
KEY = jose.JWKRSA.load(test_util.load_vector('rsa512_key.pem'))
KEY2 = jose.JWKRSA.load(test_util.load_vector('rsa256_key.pem'))


class ClientTest(unittest.TestCase):
    """Tests for  acme.client.Client."""

    # pylint: disable=too-many-instance-attributes,too-many-public-methods

    def setUp(self):
        self.response = mock.MagicMock(ok=True,
                                       status_code=http_client.OK,
                                       headers={},
                                       links={})
        self.net = mock.MagicMock()
コード例 #38
0
ファイル: jwk_test.py プロジェクト: fmarier/letsencrypt
 def test_load(self):
     from acme.jose.jwk import JWKRSA
     self.assertEqual(self.private, JWKRSA.load(
         test_util.load_vector('rsa256_key.pem')))