mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
Makes encryption optional.
This commit is contained in:
parent
67e958f4b6
commit
132b08ccc7
1 changed files with 23 additions and 7 deletions
30
jrnl.py
30
jrnl.py
|
@ -20,8 +20,12 @@ try: import simplejson as json
|
||||||
except ImportError: import json
|
except ImportError: import json
|
||||||
import sys
|
import sys
|
||||||
import readline, glob
|
import readline, glob
|
||||||
from Crypto.Cipher import AES
|
try:
|
||||||
from Crypto.Random import random, atfork
|
from Crypto.Cipher import AES
|
||||||
|
from Crypto.Random import random, atfork
|
||||||
|
PYCRYPTO = True
|
||||||
|
except ImportError:
|
||||||
|
PYCRYPTO = False
|
||||||
import hashlib
|
import hashlib
|
||||||
import getpass
|
import getpass
|
||||||
try:
|
try:
|
||||||
|
@ -360,11 +364,15 @@ def setup():
|
||||||
default_config['journal'] = os.path.expanduser(journal_path)
|
default_config['journal'] = os.path.expanduser(journal_path)
|
||||||
|
|
||||||
# Encrypt it?
|
# Encrypt it?
|
||||||
password = getpass.getpass("Enter password for journal (leave blank for no encryption): ")
|
if PYCRYPTO:
|
||||||
if password:
|
password = getpass.getpass("Enter password for journal (leave blank for no encryption): ")
|
||||||
default_config['encrypt'] = True
|
if password:
|
||||||
print("Journal will be encrypted.")
|
default_config['encrypt'] = True
|
||||||
print("If you want to, you can store your password in .jrnl_config and will never be bothered about it again.")
|
print("Journal will be encrypted.")
|
||||||
|
print("If you want to, you can store your password in .jrnl_config and will never be bothered about it again.")
|
||||||
|
else:
|
||||||
|
password = None
|
||||||
|
print("PyCrypto not found. To encrypt your journal, install the PyCrypto package from http://www.pycrypto.org and run 'jrnl --encrypt'. For now, your journal will be stored in plain text.")
|
||||||
|
|
||||||
# Use highlighting:
|
# Use highlighting:
|
||||||
if not CLINT:
|
if not CLINT:
|
||||||
|
@ -397,6 +405,11 @@ if __name__ == "__main__":
|
||||||
with open(CONFIG_PATH, 'w') as f:
|
with open(CONFIG_PATH, 'w') as f:
|
||||||
json.dump(config, f, indent=2)
|
json.dump(config, f, indent=2)
|
||||||
|
|
||||||
|
# check if the configuration is supported by available modules
|
||||||
|
if config['encrypt'] and not PYCRYPTO:
|
||||||
|
print("According to your jrnl_conf, your journal is encrypted, however PyCrypto was not found. To open your journal, install the PyCrypto package from http://www.pycrypto.org.")
|
||||||
|
sys.exit(-1)
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
composing = parser.add_argument_group('Composing', 'Will make an entry out of whatever follows as arguments')
|
composing = parser.add_argument_group('Composing', 'Will make an entry out of whatever follows as arguments')
|
||||||
composing.add_argument('-date', dest='date', help='Date, e.g. "yesterday at 5pm"')
|
composing.add_argument('-date', dest='date', help='Date, e.g. "yesterday at 5pm"')
|
||||||
|
@ -487,6 +500,9 @@ if __name__ == "__main__":
|
||||||
elif args.markdown: # export to json
|
elif args.markdown: # export to json
|
||||||
print(journal.to_md())
|
print(journal.to_md())
|
||||||
|
|
||||||
|
elif (args.encrypt or args.decrypt) and not PYCRYPTO:
|
||||||
|
print("PyCrypto not found. To encrypt or decrypt your journal, install the PyCrypto package from http://www.pycrypto.org.")
|
||||||
|
|
||||||
# Encrypt into new file If args.encrypt is True, that it is present in the command line arguments
|
# Encrypt into new file If args.encrypt is True, that it is present in the command line arguments
|
||||||
# but isn't followed by any value - in which case we encrypt the journal file itself. Otherwise
|
# but isn't followed by any value - in which case we encrypt the journal file itself. Otherwise
|
||||||
# encrypt to a new file.
|
# encrypt to a new file.
|
||||||
|
|
Loading…
Add table
Reference in a new issue