Example #1
0
    def test_message_encryption_with_random_iv_taken_from_config(self):
        pn_config = pnconf_file_copy()
        pn_config.use_random_initialization_vector = True
        crypto_with_custom_settings = PubNubCryptodome(pn_config)

        self.test_message_encryption_with_random_iv(
            crypto_with_custom_settings)
Example #2
0
import unittest

from pubnub.crypto import PubNubCryptodome
from tests.helper import gen_decrypt_func

crypto = PubNubCryptodome()
todecode = 'QfD1NCBJCmt1aPPGU2cshw=='
key = 'testKey'


class TestDecode(unittest.TestCase):
    def test_decode_aes(self):
        hey = """

        dfjn
        t564

        sdfhp\n
        """

        assert crypto.decrypt(key, crypto.encrypt(key, hey)) == hey
        assert crypto.decrypt(key, todecode) == "hey-0"

    def test_vc_body_decoder(self):
        input = b'"9P/7+NNs54o7Go41yh+3rIn8BW0H0ad+mKlKTKGw2i1eoQP1ddHrnIzkRUPEC3ko"'
        # print(json.loads(input.decode('utf-8')))
        assert {"name": "Alex", "online": True} == \
            gen_decrypt_func('testKey')(input.decode('utf-8'))
Example #3
0
)

PAM_TOKEN_EXPIRED = (
    "qEF2AkF0GmEI03xDdHRsGDxDcmVzpURjaGFuoWljaGFubmVsLTEY70NncnChb2NoYW5uZWxfZ3JvdXAtMQ"
    "VDdXNyoENzcGOgRHV1aWShZnV1aWQtMRhoQ3BhdKVEY2hhbqFtXmNoYW5uZWwtXFMqJBjvQ2dycKF0XjpjaG"
    "FubmVsX2dyb3VwLVxTKiQFQ3VzcqBDc3BjoER1dWlkoWpedXVpZC1cUyokGGhEbWV0YaBEdXVpZHR0ZXN0LWF1"
    "dGhvcml6ZWQtdXVpZENzaWdYIPpU-vCe9rkpYs87YUrFNWkyNq8CVvmKwEjVinnDrJJc")

PAM_TOKEN_WITH_PUBLISH_ENABLED = (
    "qEF2AkF0GmEI03xDdHRsGDxDcmVzpURjaGFuoWljaGFubmVsLTEY70NncnChb2NoYW5uZWxfZ3JvdXAtMQ"
    "VDdXNyoENzcGOgRHV1aWShZnV1aWQtMRhoQ3BhdKVEY2hhbqFtXmNoYW5uZWwtXFMqJBjvQ2dycKF0XjpjaG"
    "FubmVsX2dyb3VwLVxTKiQFQ3VzcqBDc3BjoER1dWlkoWpedXVpZC1cUyokGGhEbWV0YaBEdXVpZHR0ZXN0LWF1"
    "dGhvcml6ZWQtdXVpZENzaWdYIPpU-vCe9rkpYs87YUrFNWkyNq8CVvmKwEjVinnDrJJc")

crypto_configuration = PNConfiguration()
crypto = PubNubCryptodome(crypto_configuration)

DEFAULT_TEST_CIPHER_KEY = "testKey"

pub_key = "pub-c-739aa0fc-3ed5-472b-af26-aca1b333ec52"
sub_key = "sub-c-33f55052-190b-11e6-bfbc-02ee2ddab7fe"

pub_key_mock = "pub-c-mock-key"
sub_key_mock = "sub-c-mock-key"
uuid_mock = "uuid-mock"

pub_key_pam = "pub-c-98863562-19a6-4760-bf0b-d537d1f5c582"
sub_key_pam = "sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f"
sec_key_pam = "sec-c-MGFkMjQxYjMtNTUxZC00YzE3LWFiZGYtNzUwMjdjNmM3NDhk"

pnconf = PNConfiguration()
    def test_history_item(self):
        assert str(PNHistoryItemResult({'blah': 2}, PubNubCryptodome(), 123)) == \
            "History item with tt: 123 and content: {'blah': 2}"

        assert str(PNHistoryItemResult({'blah': 2}, PubNubCryptodome())) == \
            "History item with tt: None and content: {'blah': 2}"
Example #5
0
from pubnub.pubnub import PubNub
from pubnub.crypto import PubNubCryptodome
from tests.helper import gen_decrypt_func
from tests.helper import pnconf_file_copy

crypto = PubNubCryptodome(pnconf_file_copy())
todecode = 'QfD1NCBJCmt1aPPGU2cshw=='
plaintext_message = "hey-0"
KEY = 'testKey'


class TestPubNubCryptodome:
    def test_decode_aes(self):
        multiline_test_message = """

        dfjn
        t564

        sdfhp\n
        """

        assert crypto.decrypt(KEY, crypto.encrypt(
            KEY, multiline_test_message)) == multiline_test_message
        assert crypto.decrypt(KEY, todecode) == plaintext_message

    def test_vc_body_decoder(self):
        input = b'"9P/7+NNs54o7Go41yh+3rIn8BW0H0ad+mKlKTKGw2i1eoQP1ddHrnIzkRUPEC3ko"'
        # print(json.loads(input.decode('utf-8')))
        assert {"name": "Alex", "online": True} == \
            gen_decrypt_func()(input.decode('utf-8'))
Example #6
0
import threading
import string
import random
import six

from copy import copy
from pubnub import utils
from pubnub.crypto import PubNubCryptodome
from pubnub.pnconfiguration import PNConfiguration

try:
    from mock import patch
except ImportError:
    from unittest.mock import patch  # noqa: F401

crypto = PubNubCryptodome(PNConfiguration())

pub_key = "pub-c-739aa0fc-3ed5-472b-af26-aca1b333ec52"
sub_key = "sub-c-33f55052-190b-11e6-bfbc-02ee2ddab7fe"

pub_key_mock = "pub-c-mock-key"
sub_key_mock = "sub-c-mock-key"

pub_key_pam = "pub-c-98863562-19a6-4760-bf0b-d537d1f5c582"
sub_key_pam = "sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f"
sec_key_pam = "sec-c-MGFkMjQxYjMtNTUxZC00YzE3LWFiZGYtNzUwMjdjNmM3NDhk"

pnconf = PNConfiguration()
pnconf.publish_key = pub_key
pnconf.subscribe_key = sub_key
pnconf.enable_subscribe = False
from pubnub.pubnub import PubNub
from pubnub.crypto import PubNubCryptodome
from tests.helper import pnconf_file_copy, hardcoded_iv_config_copy

crypto = PubNubCryptodome(pnconf_file_copy())
crypto_hardcoded_iv = PubNubCryptodome(hardcoded_iv_config_copy())
todecode = 'QfD1NCBJCmt1aPPGU2cshw=='
plaintext_message = "hey-0"
KEY = 'testKey'


class TestPubNubCryptodome:
    def test_decode_aes(self):
        multiline_test_message = """

        dfjn
        t564

        sdfhp\n
        """

        assert crypto.decrypt(KEY, crypto.encrypt(
            KEY, multiline_test_message)) == multiline_test_message

    def test_decode_aes_default_hardcoded_iv(self):
        assert crypto_hardcoded_iv.decrypt(KEY, todecode) == plaintext_message

    def test_message_encryption_with_random_iv(self, pn_crypto=crypto):
        encrypted = pn_crypto.encrypt(KEY,
                                      plaintext_message,
                                      use_random_iv=True)