def __init__(self, homedir='/path/to/home/directory', key_id=None): # gnupg.GPG(homedir=homedir, keyring='pubring.gpg', secring='secring.gpg') self.gpg = gnupg.GPG(binary='/usr/bin/gpg', homedir=homedir, keyring='pubring.gpg', secring='secring.gpg') self.key_id = key_id
def extract_plain_text_passwort_from_pgp_file(file_path: Path) -> str: gpg = gnupg.GPG(homedir='~/.gnupg') with open(file_path, 'rb') as file_handle: try: plain_file_content = gpg.decrypt_file(file_handle) except ValueError: pass return str(plain_file_content).strip("\n")
def test(self): print(1) gpg = gnupg.GPG(binary='/usr/bin/gpg', homedir='./keys', keyring='pubring.gpg', secring='secring.gpg') print(2) key_input = gpg.gen_key_input(key_type='RSA', key_length=4096) print(key_input) key = gpg.gen_key(key_input) print(4) assert key.fingerprint print(key.fingerprint)
def main(): parser = argparse.ArgumentParser( description='Backup data using Dropbox as storage.') parser.add_argument('--api-key', required=True, help='Dropbox API Key to use for authentication') parser.add_argument('--backup-name', required=True, help='Name for the backup in Dropbox') parser.add_argument('--max-backups', type=int, help='Max number of these backups to keep in Dropbox') parser.add_argument('--gpg-encrypt', help='Key fingerprint to use for encrypting') parser.add_argument('--gpg-home', help='Folder to use as GPG home') parser.add_argument('--gpg-pubkeyring', help='GPG public key keyring to use') parser.add_argument('paths', nargs='+', help='List of paths to include in the backup') args = parser.parse_args() start_time = time.perf_counter() logging.info('Creating Dropbox client') dropbox_client = DropboxClient(dropbox.Dropbox(args.api_key, timeout=None)) encryption_service = None if args.gpg_encrypt is not None: from pretty_bad_protocol import gnupg gnupg_api = gnupg.GPG(homedir=args.gpg_home, keyring=args.gpg_pubkeyring) encryption_service = GpgEncryptionService(args.gpg_encrypt, gnupg_api) backup_service = BackupService(dropbox_client, args.backup_name, encryption_service) if args.max_backups is not None: logging.info('Performing cleanup of old backups') backup_service.cleanup_old_backups(args.max_backups - 1) backup_service.backup_paths(args.paths) end_time = time.perf_counter() logging.info('Backup finished. Time elapsed: %.2f', end_time - start_time)
def get_pgp(mix_id=None): if mix_id: gpg = gnupg.GPG(homedir=os.path.join(BASE_DIR, '.gnupg2')) imported_k = gpg.import_keys(pgp_public) imported_p = gpg.import_keys(pgp_private) print(gpg.list_keys()) print(gpg.list_keys(True)) sett = Settings.objects.all()[0] mix = Mix.objects.filter(mix_id=mix_id)[0] adds = mix.addresses_set.all() adds_dets = [ ','.join([ 'Amount : ' + str(render_dec_int(number=float(x.amount_sent))), 'Delay : ' + str(x.delay), 'Transaction ID : ' + str(x.txid) ]) for x in adds ] adds_msg = '\n'.join(adds_dets) print(adds_msg) date = mix.date.strftime('%Y-%m-%d %H:%M:%S') message = """ This certificate was issued by Anonymix.io, a Bitcoin mixing service. It can be utilized to proof that the Bitcoins received through the following transaction(s) were sent by Anonymix. Transaction(s) details: {0} Session is valid for {1} days From {2} Service Fee : {3} Transaction_fee : {4} PGP fingerprint: {5}""".format(adds_msg, sett.d_inactive, date, render_dec_int(number=sett.s_fee), render_dec_int(number=sett.t_fee), fingerprint) print(message) signed = gpg.sign(message, passphrase=passphrase, default_key=imported_k.fingerprints[0]) return str(signed) else: return ''