def importdb(conf, dbfile, passwd, passphrase): if PasswdManager.verbose: cprint('Reading and decrypting database', color='blue') g = Giltzarrapo().readEncrypted(conf['dbfile']).decrypt( passwd, conf['privkey'], passphrase) if PasswdManager.verbose: print(cprepare('Reading plain exported file :', color='blue'), cprepare(dbfile, color='lblue')) content = InternalPasswdManager.readfile(dbfile) header_fields = ['service', 'user', 'password'] old_header, lines = content[0].split('\t'), [ l.split('\t') for l in content[1:] ] line_template = '{}\n'.format('\t'.join([ ('{}' if h in header_fields else ' ') for h in old_header ])) if PasswdManager.verbose: print(cprepare('Inserting rows in', color='blue'), cprepare(conf['dbfile'].split('/')[-1], color='lblue'), cprepare('database', color='blue')) for l in lines: InternalPasswdManager.append(g, line_template.format(*l)) if PasswdManager.verbose: cprint('Saving modified database', color='blue') g.encrypt(passwd, conf['pubkey']).save(conf['dbfile'])
def changedbkey(conf, newpassphrase, passwd, passphrase): if PasswdManager.verbose: cprint('Reading and decrypting database', color='blue') g = Giltzarrapo().readEncrypted(conf['dbfile']).decrypt( passwd, conf['privkey'], passphrase) if PasswdManager.verbose: cprint('Generating rsa key pair', color='blue') keys_path, keyname = '/'.join( conf['privkey'].split('/')[:-1]), conf['privkey'].split('/')[-1] os.rename(conf['privkey'], '{}/.old.{}'.format(keys_path, keyname)) os.rename(conf['pubkey'], '{}/.old.{}.pub'.format(keys_path, keyname)) privkey, pubkey = Giltzarrapo.generateRSApair(newpassphrase, dir=keys_path, name=keyname) if PasswdManager.verbose: print( cprepare('Old keys moved to :\n - Privkey :', color='blue'), cprepare('{}/.old.{}'.format(keys_path, keyname), color='lblue'), cprepare('\n - Pubkey :', color='blue'), cprepare('{}/.old.{}.pub'.format(keys_path, keyname), color='lblue')) if PasswdManager.verbose: print(cprepare('New keys saved at :\n - Privkey :', color='blue'), cprepare(privkey, color='lblue'), cprepare('\n - Pubkey :', color='blue'), cprepare(pubkey, color='lblue')) if PasswdManager.verbose: cprint('Encrypting database with the new key pair', color='blue') g.encrypt(passwd, pubkey).save(conf['dbfile'])
def remove(conf, index, passwd, passphrase): if PasswdManager.verbose: cprint('Reading and decrypting database', color='blue') g = Giltzarrapo().readEncrypted(conf['dbfile']).decrypt( passwd, conf['privkey'], passphrase) if PasswdManager.verbose: cprint('Removing matching rows', color='blue') if index == '*': removerows = [ l[1].encode('utf-8') for l in InternalPasswdManager.getlines(g, '*') ] else: try: removerows = InternalPasswdManager.getlines( g, '*')[index][1].encode('utf-8') except IndexError: return False InternalPasswdManager.remove(g, removerows) if PasswdManager.verbose: cprint('Saving modified database', color='blue') g.encrypt(passwd, conf['pubkey']).save(conf['dbfile']) return True
def changedbpass(conf, newpasswd, passwd, passphrase): if PasswdManager.verbose: cprint('Reading and decrypting database', color='blue') g = Giltzarrapo().readEncrypted(conf['dbfile']).decrypt( passwd, conf['privkey'], passphrase) if PasswdManager.verbose: cprint('Encrypting database with the new password', color='blue') g.encrypt(newpasswd, conf['pubkey']).save(conf['dbfile'])
def list(conf, passwd, passphrase): if PasswdManager.verbose: cprint('Reading and decrypting database', color='blue') g = Giltzarrapo().readEncrypted(conf['dbfile']).decrypt( passwd, conf['privkey'], passphrase) if PasswdManager.verbose: cprint('Fetching rows', color='blue') lines = InternalPasswdManager.getlines(g, '*') if PasswdManager.verbose: cprint('Refreshing database', color='blue') g.encrypt(passwd, conf['pubkey']).save(conf['dbfile']) return lines
def verifyauth(conf, passwd, passphrase): if PasswdManager.verbose: cprint('Verifying database credentials', color='blue') try: g = Giltzarrapo().readEncrypted(conf['dbfile']).decrypt( passwd, conf['privkey'], passphrase) g.encrypt(passwd, conf['pubkey']).save(conf['dbfile']) except: return False if PasswdManager.verbose: cprint('Successfully verification', color='green') return True
def version(conf, passwd, passphrase): if PasswdManager.verbose: cprint('Reading and decrypting database', color='blue') g = Giltzarrapo().readEncrypted(conf['dbfile']).decrypt( passwd, conf['privkey'], passphrase) if PasswdManager.verbose: cprint('Fetching database version', color='blue') version = InternalPasswdManager.getversion(g) if PasswdManager.verbose: cprint('Refreshing database', color='blue') g.encrypt(passwd, conf['pubkey']).save(conf['dbfile']) return version
def insert(conf, service, user, spasswd, passwd, passphrase): if PasswdManager.verbose: cprint('Reading and decrypting database', color='blue') g = Giltzarrapo().readEncrypted(conf['dbfile']).decrypt( passwd, conf['privkey'], passphrase) if PasswdManager.verbose: cprint('Inserting new row', color='blue') if spasswd == '': spasswd = PasswdManager.passgen() InternalPasswdManager.append( g, '{}\t{}\t{}\n'.format(service, user, spasswd)) if PasswdManager.verbose: ctable(header=['service', 'user', 'password'], data=[[service, user, spasswd]], header_color='blue', rows_color='lblue') if PasswdManager.verbose: cprint('Saving modified database', color='blue') g.encrypt(passwd, conf['pubkey']).save(conf['dbfile'])
def create(dbname, passwd, passphrase, databases_path, keys_path): if PasswdManager.verbose: print(cprepare('Creating', color='blue'), cprepare(dbname, color='lblue'), cprepare('database', color='blue')) g = Giltzarrapo() InternalPasswdManager.append( g, 'passranoid_database:v1.1\tpassranoid_interface:v1.2\tpassranoid_config:v1\n' ) g.status = 'plain' if PasswdManager.verbose: cprint('Generating rsa key pair', color='blue') privkey, pubkey = Giltzarrapo.generateRSApair(passphrase, dir=keys_path, name=dbname) if PasswdManager.verbose: print(cprepare('Keys saved at :\n - Privkey :', color='blue'), cprepare(privkey, color='lblue'), cprepare('\n - Pubkey :', color='blue'), cprepare(pubkey, color='lblue')) if PasswdManager.verbose: print( cprepare('Saving database at :', color='blue'), cprepare('{}/{}'.format(databases_path, dbname), color='lblue')) g.encrypt(passwd, pubkey).save('{}/{}'.format(databases_path, dbname))
def exportdb(conf, dbfile, passwd, passphrase): if PasswdManager.verbose: cprint('Reading and decrypting database', color='blue') g = Giltzarrapo().readEncrypted(conf['dbfile']).decrypt( passwd, conf['privkey'], passphrase) if PasswdManager.verbose: cprint('Fetching rows', color='blue') header = '\t'.join(['service', 'user', 'password']) lines = [l for i, l in InternalPasswdManager.getlines(g, '*')] if len(lines) == 0: return False if PasswdManager.verbose: print(cprepare('Saving plain database rows at :', color='blue'), cprepare(dbfile, color='lblue')) InternalPasswdManager.savefile(header=header, lines=lines, file=dbfile) return True
# Stats enc_time = [] dec_time = [] enc_throughput = [] dec_throughput = [] results = [] print(" *** RUNNING {} TESTS ***".format(NTESTS)) print(" *** Using files with size: {} ***".format(FILE_SIZE)) # Generate RSA keypair and init context gz = Giltzarrapo(dynamic_library, pubkey, privkey, passphrase="asdf", password="******", fast_mode=True, generate_RSA_keypair=True) # Perform tests for i in range(NTESTS): loading_bar(i, NTESTS) subprocess.run(GENERATE_FILE) t_start = time.perf_counter() gz.encrypt(plaintext_file, encrypted_file) t_encrypt = time.perf_counter()
import sys from giltzarrapo import Giltzarrapo from printer import cprint, ecprint from datetime import datetime as dt passph = '123' passwd = 'abc' num_process = 3 sb = None if '-e' in sys.argv: #RSA KEYS cprint('Generando claves...', color='cyan', end='\r') s = dt.now() Giltzarrapo.generateRSApair(passphrase=passph) e = dt.now() ecprint(['Generacion de claves ', str(e - s)], color=['cyan', 'yellow'], template='{} : {}') #ENCRYPT g = Giltzarrapo(n_processes=num_process) #read cprint('Leyendo fichero...', color='cyan', end='\r') s = dt.now() g.readPlain('testfile.txt') e = dt.now() ecprint(['Lectura de fichero ', str(e - s)], color=['cyan', 'yellow'], template='{} : {}') #encrypt
'Enter file in which to save the key ({}): '.format(default_path)) if keypath == "": keypath = default_path passphrase = getpass('Enter passphrase (empty for no passphrase): ') rpassphrase = getpass('Enter same passphrase again: ') if passphrase != rpassphrase: ecprint('Passphrases do not match', color='red') sys.exit() keyargs = { 'dir': '/'.join(keypath.split('/')[:-1]), 'name': keypath.split('/')[-1] } #Generate new a new pair of keys privKey, pubKey = Giltzarrapo.generateRSApair( passphrase=passphrase, **{k: v for k, v in keyargs.items() if v is not ""}) args.key = pubKey if args.verbose: ecprint(privKey, color='yellow', template='Your identification has been saved in {}') ecprint(pubKey, color='yellow', template='Your public key has been save in {}') args.fast = True if (args.fast is 'on') else False if not args.verbose: #Encrypt the file as one-liner
import sys from getpass import getpass if args.modules is not None: sys.path.insert(0, args.modules) try: from giltzarrapo import Giltzarrapo from printer import ecprint except: sys.exit('Can not import required modules. Try using -m option') passwd = getpass('Password: '******'Passphrase: ') if args.passphrase else "" if not args.verbose: #Decrypt the file as one-liner Giltzarrapo().readEncrypted(args.infile, authfile=args.auth).decrypt( passwd, args.privkey, passphrase, selected_block=args.block).save(args.outfile) else: #Encrypt the file step by step ecprint('Starting decrypting module...', color='blue') #Read the file g = Giltzarrapo() ecprint([args.infile, os.path.getsize(args.infile)], color='yellow', template='Reading file : {} ({} Bytes)') if args.auth is not None: ecprint(args.auth, color='yellow', template='Using auth file : {}') g.readEncrypted(args.infile, authfile=args.auth) ecprint(len(g.blocks), color='yellow', template='Blocks to decrypt: {}')