Ejemplo n.º 1
0
    def test_asymmetric_encryption_and_decryption(self):
        # Test case specific setUp
        provider = ProviderNaCl()
        private_key_str = provider.generate_key()

        ## Trixy bit - Normally we have a serialized public key available (saved after
        ## rendezvoux) but here we have to retrieve one
        private_key = ProviderNaCl._deserialize_private_key(private_key_str)
        public_key = private_key.public_key
        public_key_str = ProviderNaCl._serialize_public_key(public_key)

        test_string = """\
        an example string to encrypt
        including line breaks, etc

        also: exotic characters!
        åäö
        ㅏ매아내ㅐ
        """

#        print("String before encryption")
#        print(test_string)

        encrypted_string = provider.encrypt(test_string, public_key_str)

#        print("String after encryption")
#        print(encrypted_string)
        decrypted_string = provider.decrypt(encrypted_string, private_key_str)
#        print("String after decryption")
#        print(decrypted_string)

        self.assertEqual(test_string, decrypted_string)
Ejemplo n.º 2
0
    def test_symmetric_encryption_and_decryption(self):
        provider = ProviderNaCl()

        test_string = """\
        an example string to encrypt
        including line breaks, etc

        also: exotic characters!
        åäö
        ㅏ매아내ㅐ
        """

        shared_secret = "a-secret-well-kept"

#        print("String before encryption")
#        print(test_string)

        encrypted_string = provider.encrypt_symmetric(test_string,
                                                      shared_secret)
#        print("String after encryption")
#        print(encrypted_string)

        decrypted_string = provider.decrypt_symmetric(encrypted_string,
                                                      shared_secret)
#        print("String after decryption")
#        print(decrypted_string)

        self.assertEqual(test_string, decrypted_string)
Ejemplo n.º 3
0
    def __init__(self, root_window, conf: ConfigParser):
        self._logger = logging.getLogger(__name__)
        self._logger.info("Starting curses CLI")

        # Global state init
        self._quit = False
        self._active_menu = _Menu("Empty menu", [])

        # Persistence
        try:
            db_file_path = conf.get("persistence", "db_file_path")
            self._db = SqliteStorage(db_file_path)
        except (NoSectionError, NoOptionError):
            self._logger.info("No configuration found for db file. Using default.")
            self._db = SqliteStorage()
        self._db.connect_thread()

        # Crypto init
        self._crypto_provider = ProviderNaCl()

        # Communication
        self._adapter = TcpUdpAdapter(self._crypto_provider)
        self._is_listening_passive = False
        self._is_listening_active = False

        # Root window init
        self._stdscr = root_window
        self._stdscr.clear()

        # Status init
        max_y, max_x = self._stdscr.getmaxyx()
        self._statusscr = self._stdscr.derwin(3, 45, 0, max_x - 45)
        self._status = "Inactive"
Ejemplo n.º 4
0
    def test_key_searialization(self):
        provider = ProviderNaCl()
        key = public.PrivateKey.generate()

        str_key = ProviderNaCl._serialize_private_key(key)
#        print("Stringified key is:", str_key)

        reconstituted_key = ProviderNaCl._deserialize_private_key(str_key)

        self.assertEqual(key, reconstituted_key)
Ejemplo n.º 5
0
    def __init__(self, conf: ConfigParser):
        self._logger = logging.getLogger(__name__)

        # Set up persistence
        try:
            db_file_path = conf.get("persistence", "db_file_path")
            self._db = SqliteStorage(db_file_path)
        except (NoSectionError, NoOptionError):
            self._logger.info("No configuration found for db file. "
                              "Using default.")
            self._db = SqliteStorage()
        self._db.connect_thread()

        # Set up encryption
        self._crypto_provider = ProviderNaCl()

        # Set up networking
        self._adapter = TcpUdpAdapter(self._crypto_provider)