mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
Allows getpass to get bypassed by reading from stdin
This commit is contained in:
parent
279547c350
commit
a84713e99a
2 changed files with 23 additions and 11 deletions
|
@ -3,8 +3,8 @@
|
||||||
|
|
||||||
try: from . import Entry
|
try: from . import Entry
|
||||||
except (SystemError, ValueError): import Entry
|
except (SystemError, ValueError): import Entry
|
||||||
try: from .util import get_local_timezone, prompt
|
try: from .util import get_local_timezone, prompt, getpass
|
||||||
except (SystemError, ValueError): from util import get_local_timezone, prompt
|
except (SystemError, ValueError): from util import get_local_timezone, prompt, getpass
|
||||||
import codecs
|
import codecs
|
||||||
import os
|
import os
|
||||||
try: import parsedatetime.parsedatetime_consts as pdt
|
try: import parsedatetime.parsedatetime_consts as pdt
|
||||||
|
@ -25,7 +25,6 @@ except ImportError:
|
||||||
if "win32" in sys.platform: import pyreadline as readline
|
if "win32" in sys.platform: import pyreadline as readline
|
||||||
else: import readline
|
else: import readline
|
||||||
import hashlib
|
import hashlib
|
||||||
import getpass
|
|
||||||
try:
|
try:
|
||||||
import colorama
|
import colorama
|
||||||
colorama.init()
|
colorama.init()
|
||||||
|
@ -89,6 +88,7 @@ class Journal(object):
|
||||||
sys.exit("Error: PyCrypto is not installed.")
|
sys.exit("Error: PyCrypto is not installed.")
|
||||||
atfork() # A seed for PyCrypto
|
atfork() # A seed for PyCrypto
|
||||||
iv = ''.join(chr(random.randint(0, 0xFF)) for i in range(16))
|
iv = ''.join(chr(random.randint(0, 0xFF)) for i in range(16))
|
||||||
|
print("iv", iv, len(iv))
|
||||||
crypto = AES.new(self.key, AES.MODE_CBC, iv)
|
crypto = AES.new(self.key, AES.MODE_CBC, iv)
|
||||||
if len(plain) % 16 != 0:
|
if len(plain) % 16 != 0:
|
||||||
plain += " " * (16 - len(plain) % 16)
|
plain += " " * (16 - len(plain) % 16)
|
||||||
|
@ -98,7 +98,8 @@ class Journal(object):
|
||||||
|
|
||||||
def make_key(self, prompt="Password: "):
|
def make_key(self, prompt="Password: "):
|
||||||
"""Creates an encryption key from the default password or prompts for a new password."""
|
"""Creates an encryption key from the default password or prompts for a new password."""
|
||||||
password = self.config['password'] or getpass.getpass(prompt)
|
password = self.config['password'] or getpass(prompt)
|
||||||
|
print("GOT PWD", password)
|
||||||
self.key = hashlib.sha256(password.encode('utf-8')).digest()
|
self.key = hashlib.sha256(password.encode('utf-8')).digest()
|
||||||
|
|
||||||
def open(self, filename=None):
|
def open(self, filename=None):
|
||||||
|
|
25
jrnl/util.py
25
jrnl/util.py
|
@ -3,24 +3,35 @@
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
from tzlocal import get_localzone
|
from tzlocal import get_localzone
|
||||||
|
import getpass as gp
|
||||||
|
|
||||||
PY3 = sys.version_info[0] == 3
|
PY3 = sys.version_info[0] == 3
|
||||||
PY2 = sys.version_info[0] == 2
|
PY2 = sys.version_info[0] == 2
|
||||||
|
STDIN = sys.stdin
|
||||||
|
STDERR = sys.stderr
|
||||||
|
STDOUT = sys.stdout
|
||||||
|
TEST = False
|
||||||
|
__cached_tz = None
|
||||||
|
|
||||||
|
def getpass(prompt):
|
||||||
|
if not TEST:
|
||||||
|
return gp.getpass(prompt)
|
||||||
|
else:
|
||||||
|
return py23_input(prompt)
|
||||||
|
|
||||||
|
|
||||||
def u(s):
|
def u(s):
|
||||||
"""Mock unicode function for python 2 and 3 compatibility."""
|
"""Mock unicode function for python 2 and 3 compatibility."""
|
||||||
return s if PY3 else unicode(s, "unicode_escape")
|
return s if PY3 else unicode(s, "unicode_escape")
|
||||||
|
|
||||||
STDIN = sys.stdin
|
|
||||||
STDERR = sys.stderr
|
|
||||||
STDOUT = sys.stdout
|
|
||||||
__cached_tz = None
|
|
||||||
|
|
||||||
def prompt(msg):
|
def prompt(msg):
|
||||||
"""Prints a message to the std err stream defined in util."""
|
"""Prints a message to the std err stream defined in util."""
|
||||||
print(msg, file=STDERR)
|
if not msg.endswith("\n"):
|
||||||
|
msg += "\n"
|
||||||
|
STDERR.write(u(msg))
|
||||||
|
|
||||||
def py23_input(msg):
|
def py23_input(msg):
|
||||||
STDOUT.write(msg)
|
STDERR.write(u(msg))
|
||||||
return STDIN.readline().strip()
|
return STDIN.readline().strip()
|
||||||
|
|
||||||
def get_local_timezone():
|
def get_local_timezone():
|
||||||
|
|
Loading…
Add table
Reference in a new issue