def do_init(config, files): if files: print_help() key_length = config.getint('key-length') if os.path.exists('.salakey'): print >>sys.stderr, 'Error: The master key already exists' return 1 print '''\ Please pick a master passphrase. It is used to encrypt a very long random key, which in turn is used to encrypt all the private data in this directory. Make sure you remember the master passphrase and that it's strong enough for your privacy needs. ''' passphrase = read_passphrase('Enter the master passphrase', confirm=True) print '' print 'Generating a master key (%d bits)...' % (key_length * 8), rng = random.SystemRandom() data = ''.join(chr(rng.randint(0, 255)) for x in range(key_length)) key = binascii.hexlify(data) gpg_encrypt(config, '.salakey', passphrase, key) print 'done'
def do_set(config, files, options): if not files: print_help() key = read_master_key(config) if key is False: return 1 print('') for filename in files: run_hooks('pre', 'set', config, filename) pwlist = generate_passwords(config.get('password-generator')) if pwlist: options = range(len(pwlist)) prompt = 'Select a number from the list ' + \ 'or type a new secret for ' + filename for i, pw in enumerate(pwlist): print('%d. %s' % (i, pw.decode('utf-8'))) print('') else: options = None prompt = 'Type a new secret for ' + filename secret = read_passphrase(prompt, confirm=True, options=options) if secret is False: return 1 if options: try: i = int(secret) secret = pwlist[i] except (ValueError, IndexError): pass if os.path.isabs(filename): full_file_path = filename else: full_file_path = os.path.join(config.topdir, filename) make_parent_dirs(full_file_path) gpg_encrypt(config, full_file_path, key, secret) run_hooks('post', 'set', config, filename) print('')
def do_init(config, files, options): if files: print_help() key_length = config.getint('key-length') if os.path.exists(config.keyfile): print('Error: The master key already exists', file=sys.stderr) return 1 print('''\ Please pick a master passphrase. It is used to encrypt a very long random key, which in turn is used to encrypt all the private data in this directory. Make sure you remember the master passphrase and that it's strong enough for your privacy needs. ''') passphrase = read_passphrase('Enter the master passphrase', confirm=True) if passphrase is False: return 1 print('') print('Generating a master key (%d bits)... ' % (key_length * 8), end='') rng = random.SystemRandom() key_bytes = (rng.randint(0, 255) for x in range(key_length)) if Py2: # bytes is str in Python 2, there's no cleaner way to build a # bytestring from byte ints. data = b''.join(chr(x) for x in key_bytes) else: data = bytes(key_bytes) key = binascii.hexlify(data) if not os.path.exists(config.saladir): os.mkdir(config.saladir) gpg_encrypt(config, config.keyfile, passphrase, key) if not os.path.exists(config.hooksdir): os.mkdir(config.hooksdir) init_hooks(config.hooksdir) print('done')
def do_set(config, files): if not files: print_help() key = read_master_key() if key is False: return 1 for filename in files: pwlist = generate_passwords(config.get('password-generator')) if pwlist: options = range(len(pwlist)) prompt = 'Select a number from the list ' + \ 'or type a new secret for ' + filename for i, pw in enumerate(pwlist): print '%d. %s' % (i, pw) print '' else: options = None prompt = 'Type a new secret for ' + filename secret = read_passphrase(prompt, confirm=True, options=options) if secret is False: continue if options: try: i = int(secret) secret = pwlist[i] except (ValueError, IndexError): pass make_parent_dirs(filename) gpg_encrypt(config, filename, key, secret) print ''