Exemplo n.º 1
0
    def generate_key_pair(self):  # 3.1.1
        questions = [{
            'type': 'list',
            'name': 'regenerate',
            'message': 'Do you want to regenerate the key pair?',
            'choices': ['Yes', 'No'],
            'filter': lambda val: val.lower()
        }, {
            'type': 'list',
            'name': 'save_pwd',
            'message': 'Do you want save password?',
            'choices': ['Yes', 'No'],
            'filter': lambda val: val.lower(),
            'when': lambda answer: answer['regenerate'] == 'yes'
        }]
        crypto = CryptoUtility()

        answer = prompt(questions, style=self.style)

        if answer['regenerate'] == 'yes':
            crypto.generate_key_pair()
            print('Generating key pair...')
            crypto.password = self._set_password()
            if answer['save_pwd'] == 'yes':
                print(crypto.export_password_hash_to_file())
            else:
                crypto.delete_password_hash_file()
            print(crypto.export_private_key_to_file())
            print(crypto.export_public_key_to_file())
            print('Key pair successfully generated!\n')
            self._show_public_key()
            self.configure_key_pair()
        else:
            self.configure_key_pair()
Exemplo n.º 2
0
 def decrypt(self):  # 2
     questions = [
         {
             'type': 'input',
             'name': 'cipher_text',
             'message': 'Input encrypted cipher text:',
         }
     ]
     input_password = [
         {
             'type': 'password',
             'name': 'password',
             'message': 'Enter the password of private key to decrypt:',
         }
     ]
     answer = prompt(questions)
     crypto = CryptoUtility(self.key_path)
     if not crypto.password:
         input_pwd = prompt(input_password)
         crypto.password = input_pwd['password']
     print(f' Decrypting...', end="\r")
     crypto.import_private_key_from_file()
     password = crypto.decrypt_text(answer['cipher_text'])
     qprint(f'Your password is:', style='#06c8ff', flush=True)
     qprint(f'\n{password}\n', style='bold #06c8ff')
Exemplo n.º 3
0
    def set_key_pair_from_string(self):  # 3.1.3
        questions = [
            {
                'type': 'input',
                'name': 'private_key_store',
                'message': 'Input private key store json:',
            },
            {
                'type': 'password',
                'message': 'Enter the password to decrypt private key:',
                'name': 'password',
                'when': lambda answer: answer['private_key_store'] != '',
            },
        ]

        new_password = [
            {
                'type': 'list',
                'name': 'new_pwd',
                'message': 'Do you want set a new password?',
                'choices': ['Yes', 'No'],
                'filter': lambda val: val.lower(),
            }
        ]

        save_password = [
            {
                'type': 'list',
                'name': 'save_pwd',
                'message': 'Do you want to save password?',
                'choices': ['Yes', 'No'],
                'filter': lambda val: val.lower(),
            }
        ]

        crypto = CryptoUtility(self.key_path)
        answer = prompt(questions)
        if answer['private_key_store'] != '':
            print('Setting key pair...')
            try:
                crypto.password = answer['password']
                if not crypto.set_private_key(answer['private_key_store']):
                    self.configure_key_pair()

                answer = prompt(new_password)
                if answer['new_pwd'] == 'yes':
                    crypto.password = self._set_password()

                answer = prompt(save_password)
                if answer['save_pwd'] == 'yes':
                    crypto.export_password_hash_to_file()
                else:
                    crypto.delete_password_hash_file()
                print(crypto.export_private_key_to_file())
                print(crypto.export_public_key_to_file())
                print('Key pair successfully generated!')
            except Exception as e:
                print(e)
        self.configure_key_pair()
Exemplo n.º 4
0
 def encrypt(self):  # 1
     questions = [
         {'type': 'password', 'message': 'Enter the string to be encrypted:', 'name': 'password'}
     ]
     crypto = CryptoUtility(self.key_path)
     if not crypto.import_public_key_from_file():
         print('No public Key found!')
     else:
         answer = prompt(questions)
         qprint('Encrypted password: (use incl. "crypt:")\n', style='#06c8ff')
         cipher_text = crypto.encrypt_text(answer['password'])
         qprint(f"{cipher_text}\n", style='bold #06c8ff')
Exemplo n.º 5
0
 def delete_public_key(self):
     delete_password = [{
         'type': 'list',
         'name': 'delete_public',
         'message': 'Do you really want to delete public key?',
         'choices': ['Yes', 'No'],
         'filter': lambda val: val.lower(),
     }]
     answer = prompt(delete_password, style=custom_style_fancy)
     if answer['delete_public'] == 'yes':
         crypto = CryptoUtility()
         if crypto.delete_public_key_file():
             print('Successfully deleted!')
Exemplo n.º 6
0
 def delete_saved_password(self):  # 3.1.6
     delete_password = [{
         'type': 'list',
         'name': 'delete_pwd',
         'message': 'Do you really want to delete saved password?',
         'choices': ['Yes', 'No'],
         'filter': lambda val: val.lower()
     }]
     answer = prompt(delete_password, style=self.style)
     if answer['delete_pwd'] == 'yes':
         crypto = CryptoUtility()
         if crypto.delete_password_hash_file():
             print('Successfully deleted!')
     self.configure_key_pair()
Exemplo n.º 7
0
 def encrypt(self):  # 1
     questions = [{
         'type': 'password',
         'message': 'Enter the password to encrypt',
         'name': 'password'
     }]
     crypto = CryptoUtility()
     if not crypto.import_public_key_from_file():
         print('No public Key found!')
     else:
         answer = prompt(questions, style=custom_style_fancy)
         print('Encrypted password: (use incl. "crypt:")\n')
         cipher_text = crypto.encrypt_text(answer['password'])
         print(f"{cipher_text}\n", style='bold blink #06c8ff')
Exemplo n.º 8
0
 def encrypt(self):  # 1
     questions = [{
         'type': 'password',
         'message': 'Enter the password to encrypt',
         'name': 'password'
     }]
     crypto = CryptoUtility()
     if not crypto.import_public_key_from_file():
         print('No public Key found!')
     else:
         answer = prompt(questions, style=self.style)
         print('Encrypted password: (use inlc. "crypt:")\n')
         cipher_text = crypto.encrypt_text(answer['password'])
         print(cipher_text)
         print()
     self.main_menu()
Exemplo n.º 9
0
 def set_public_key_from_string(self):  # 3.2.2
     questions = [{
         'type': 'input',
         'name': 'public_key',
         'message': 'Input public_key as Base64:',
     }]
     crypto = CryptoUtility()
     answer = prompt(questions, style=self.style)
     if answer['public_key'] != '':
         try:
             crypto.set_public_key(answer['public_key'])
             print(crypto.export_public_key_to_file())
             print('Key successfully stored!\n')
         except Exception as e:
             print(e)
     self.configure_public_key()
Exemplo n.º 10
0
 def delete_key_pair(self):  # 3.1.4
     delete_password = [
         {
             'type': 'list',
             'name': 'delete_keys',
             'message': 'Do you really want to delete key pair?',
             'choices': ['Yes', 'No'],
             'filter': lambda val: val.lower(),
         }
     ]
     answer = prompt(delete_password)
     if answer['delete_keys'] == 'yes':
         crypto = CryptoUtility(self.key_path)
         if crypto.delete_key_store():
             print('Successfully deleted!')
     self.configure_key_pair()
Exemplo n.º 11
0
    def __init__(self, password=None, variable_decryption=False):
        """
+--------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
| **password:**            | Password for private key can be given as argument.                                                                                      |
+--------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
| **variable_decryption:** | If set to ``True`` all variables that are available on Test Case start, that contain a encrypted text, will be decrypted automatically. |
+--------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
        """
        self.ROBOT_LIBRARY_LISTENER = self
        self.value_list = list()
        self.crypto = CryptoUtility()
        self.original_log_level = 'INFO'
        self.disable_logging = False
        if password:
            self.crypto.password = password
        self.variable_decryption = variable_decryption
        self.builtin = BuiltIn()
Exemplo n.º 12
0
 def decrypt(self):  # 2
     questions = [{
         'type': 'input',
         'name': 'cipher_text',
         'message': 'Input encrypted cipher text:',
     }]
     input_password = [{
         'type': 'password',
         'name': 'password',
         'message': 'Enter the password to decrypt'
     }]
     answer = prompt(questions, style=self.style)
     crypto = CryptoUtility()
     if not crypto.password:
         input_pwd = prompt(input_password, style=self.style)
         crypto.password = input_pwd['password']
     crypto.import_private_key_from_file()
     password = crypto.decrypt_text(answer['cipher_text'])
     print(f'Your password is: {password}')
     print()
     self.main_menu()
Exemplo n.º 13
0
    def save_private_key_password(self):  # 3.1.5
        input_password = [
            {
                'type': 'password',
                'name': 'password',
                'message': 'Enter the password to decrypt private key:',
            }
        ]
        crypto = CryptoUtility(self.key_path)

        if not crypto.password:
            input_pwd = prompt(input_password)
            crypto.password = input_pwd['password']
            if crypto.import_private_key_from_file():
                crypto.export_password_hash_to_file()
                print('Saved password successfully!')
            else:
                print('Wrong Password!')
        else:
            print('Password already saved.')
        self.configure_key_pair()
Exemplo n.º 14
0
 def _show_public_key(self):
     crypto = CryptoUtility()
     key = crypto.import_public_key_from_file()
     if key:
         print(f'Public Key: {key}')
         print()
Exemplo n.º 15
0
 def __init__(self, ctx):
     self.crypto = CryptoUtility()
     LibraryComponent.__init__(self, ctx)