Skip to content

Commit 05c6867

Browse files
guiltKarthik Kumar Viswanathan
authored andcommitted
Add LPASS_CONFIG_FILE and LPASS_BLOB_FILE variables.
Add LPASS_USER and LPASS_PASSWORD variables.
1 parent fffe7f8 commit 05c6867

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

lastpass/parser.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,20 @@ def pad(data):
322322
# see http://passingcuriosity.com/2009/aes-encryption-in-python-with-m2crypto/
323323
padded = (BS - len(data) % BS) * chr(BS - len(data) % BS)
324324
if isinstance(data, str):
325-
data = str.encode(data, 'latin1')
325+
try:
326+
data = str.encode(data, 'latin1')
327+
except:
328+
data = bytes(data)
326329
if isinstance(padded, str):
327-
padded = str.encode(padded, 'latin1')
328-
return data + padded
330+
try:
331+
padded = str.encode(padded, 'latin1')
332+
except:
333+
padded = bytes(data)
334+
try:
335+
result = bytes(data + padded)
336+
except:
337+
result = data + padded
338+
return result
329339

330340

331341
def unpad(data):
@@ -334,7 +344,10 @@ def unpad(data):
334344
"""
335345
# see http://passingcuriosity.com/2009/aes-encryption-in-python-with-m2crypto/
336346
if isinstance(data, str):
337-
data = str.encode(data, 'latin1')
347+
try:
348+
data = str.encode(data, 'latin1')
349+
except:
350+
data = bytes(data)
338351
return data[0:-ord(data[-1:])]
339352

340353
def decode_aes256(cipher, iv, data, encryption_key):

scripts/lpass

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ LastPass CLI in Python. Very Minimal.
3636
---------------------------------------------
3737
"""
3838

39+
from __future__ import print_function
3940
import argparse
4041
import getpass
4142
import json
@@ -68,8 +69,8 @@ S_WHITE = '\033[37m'
6869
S_RESET = '\033[0m'
6970

7071
LPASS_ENCRYPTION_KEY = '1234567890ABCDEF'
71-
LPASS_CONFIG_FILE = os.path.expanduser("~/.lpass-config")
72-
LPASS_BLOB_FILE = os.path.expanduser("~/.lpass-blob")
72+
LPASS_CONFIG_FILE = os.getenv('LPASS_CONFIG_FILE', os.path.expanduser("~/.lpass-config"))
73+
LPASS_BLOB_FILE = os.getenv('LPASS_BLOB_FILE', os.path.expanduser("~/.lpass-blob"))
7374
CLIENT_ID = None # Usually the IMEI.
7475

7576

@@ -138,7 +139,7 @@ def command_login(args):
138139
if os.path.exists(LPASS_CONFIG_FILE):
139140
if not args.force:
140141
raise Exception('Unable to Overwrite Configuration.')
141-
(_, password) = __get_login(args.username, None, args.mfa)
142+
(_, password) = __get_login(args.username, os.getenv('LPASS_PASSWORD', None), args.mfa)
142143
__print_message('Logged into {}'.format(__colored(args.username, S_YELLOW)))
143144
__write_config(args.username, password, args.mfa)
144145

@@ -273,7 +274,7 @@ def main():
273274
parser_login.add_argument('--plaintext-key', default=True, action='store_true')
274275
parser_login.add_argument('--mfa', default=False, action='store_true')
275276
parser_login.add_argument('--force', '-f', default=False, action='store_true')
276-
parser_login.add_argument('username', type=str, default=None)
277+
parser_login.add_argument('username', type=str, default=os.getenv('LPASS_USER', None))
277278
parser_login.set_defaults(func=command_login)
278279

279280
parser_logout = subparsers.add_parser('logout', help='Logout from Lasspass.')

0 commit comments

Comments
 (0)