Пример #1
0
    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'])
Пример #2
0
    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))
Пример #3
0
    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'])
Пример #4
0
    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
Пример #5
0
    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'])
Пример #6
0
    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
Пример #7
0
 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
Пример #8
0
    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
Пример #9
0
    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'])
Пример #10
0
                         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()

            gz.decrypt(encrypted_file, decrypted_file)
            t_decrypt = time.perf_counter()

            enc_file_size = os.path.getsize(encrypted_file)
            dec_file_size = os.path.getsize(decrypted_file)

            enc_time.append(t_encrypt - t_start)
            dec_time.append(t_decrypt - t_encrypt)
            enc_throughput.append(enc_file_size / (t_encrypt - t_start))
            dec_throughput.append(dec_file_size / (t_decrypt - t_encrypt))
            results.append(filecmp.cmp(plaintext_file, decrypted_file))

        print("")
Пример #11
0
            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
    cprint('Cifrando fichero...', color='cyan', end='\r')
    s = dt.now()
    g.encrypt(passwd, 'giltza_rsa.pub', fast=False, selected_block=sb)
    e = dt.now()
    ecprint(['Cifrado de fichero   ', str(e - s)],
            color=['cyan', 'yellow'],
            template='{} : {}')
    #save
    cprint('Escribiendo fichero...', color='cyan', end='\r')
    s = dt.now()
    g.save('testfile.enc')
    e = dt.now()
    ecprint(['Escritura de fichero ', str(e - s)],
            color=['cyan', 'yellow'],
            template='{} : {}')

#DECRYPT
#g = Giltzarrapo(n_processes = num_process)
Пример #12
0
    ecprint(len(g.blocks), color='yellow', template='Blocks to encrypt: {}')

    #Select the symetric block (this step is automatically done in the encryption if the block is not provided)
    if args.block is None:
        ecprint('Selecting a high entropy block...', color='blue')
        args.block = g.selectBlock(tryLimit=10)
        while not g.verifySymetricBlock(args.block, args.key):
            args.block = g.selectBlock(tryLimit=10)
    else:
        ecprint('Preselected block for encryption', color='blue')
    ecprint([
        args.block, '{:.4f}'.format(Giltzarrapo.entropy(g.blocks[args.block]))
    ],
            color='yellow',
            template='Selected block: {} (entropy of {})')

    #Encrypt the file
    ecprint('Encrypting file...', color='blue')
    ecprint([args.block, args.key, ''.join(['*' for _ in passwd])],
            color='yellow',
            template=
            'Using : \n\tSymetric block: {}\n\tPublic key: {}\n\tPassword: {}')
    g.encrypt(passwd, args.key, selected_block=args.block, fast=args.fast)

    #Save the file
    ecprint('Saving file...', color='blue')
    g.save(args.outfile, authfile=args.auth)
    ecprint(args.outfile, color='blue', template='File saved at {}')
    if (args.auth is not None):
        ecprint(args.auth, color='blue', template='Authfile saved at {}')