예제 #1
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'])
예제 #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
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
예제 #4
0
        '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