-
Notifications
You must be signed in to change notification settings - Fork 0
/
cbcreate
executable file
·39 lines (30 loc) · 1.34 KB
/
cbcreate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python
import getpass
import argparse
import sys
import os
import lib.config as config
import lib.crypto as crypto
import lib.log as log
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Create empty cryptobox database')
parser.add_argument('-v', '--version', action='version', version='Cryptobox ' + config.version)
parser.add_argument('-V', '--verbose', action='store_true', help='enable verbose mode')
parser.add_argument('-c', '--config', action='store', help='use specified config')
defines = config.read(parser.parse_args())
try:
os.mkdir(defines['path.db'])
except:
pass
if os.path.exists(defines['path.db_cipher']):
ans = log.yn("File '%s' already exists, do you want to overwrite it?" % defines['path.db_cipher'])
if not ans in ['Y', 'y']:
sys.exit(0)
password = getpass.getpass('Password: ')
password2 = getpass.getpass('Retype password: ')
if password != password2:
log.e("Your passwords don't match!")
sys.exit(0)
crypto.create_db_conf(defines['path.db_conf'], config.format_version)
db_conf = crypto.read_db_conf(defines['path.db_conf'], config.format_version)
crypto.enc_plaintext(db_conf, password, "# Lines started with # are comments", defines['path.db_cipher'], defines['path.db_hmac'])