Compare commits

...

4 Commits

Author SHA1 Message Date
Felipe M ca85afd45c
Cleaned error messages and logging
Show more detailed messages directly on qutebrowser instead of using
logging and returning error code 0 to avoid doble messages in
qutebrowser dure to the script "failing".
2021-02-09 16:42:14 +01:00
Felipe M 97495851af
Refusing to fill non-https sites 2021-02-09 16:41:46 +01:00
Felipe M 5f41e4a7c6
Find match on items with more than one URL 2021-02-09 14:13:14 +01:00
Felipe M e31bd672ee
Filter login type using op cli 2021-02-09 14:07:24 +01:00
1 changed files with 24 additions and 9 deletions

View File

@ -29,7 +29,7 @@ CMD_ITEM_SELECT = "echo -e '{items}' | rofi -dmenu -p 'Select login'"
CMD_LIST_PROMPT = "echo {items} | rofi -dmenu"
CMD_OP_LOGIN = "echo -n {password} | op signin {subdomain} --output=raw"
CMD_OP_LIST_ITEMS = "op list items --session={session_id}"
CMD_OP_LIST_ITEMS = "op list items --categories Login --session={session_id}"
CMD_OP_GET_ITEM = "op get item {uuid} --session={session_id}"
CMD_OP_GET_TOTP = "op get totp {uuid} --session={session_id}"
@ -47,6 +47,11 @@ parser.add_argument(
help="Cache 1password session for 30 minutes",
action="store_true",
)
parser.add_argument(
"--allow-insecure-sites",
help="Allow filling credentials on insecure sites",
action="store_true",
)
class Qute:
@ -129,7 +134,7 @@ class OnePass:
password = execute_command(CMD_PASSWORD_PROMPT)
except ExecuteError:
Qute.message_error("Error calling pinentry program")
sys.exit(1)
sys.exit(0)
try:
session_id = execute_command(
@ -137,7 +142,7 @@ class OnePass:
)
except ExecuteError:
Qute.message_error("Login error")
sys.exit(1)
sys.exit(0)
if arguments.cache_session:
with open(SESSION_PATH, "w") as handler:
@ -187,11 +192,9 @@ class OnePass:
host = extract_host(url)
def filter_host(item):
"""Exclude items that does not match host and are not a login"""
if item["templateUuid"] != "001":
return False
if "url" in item["overview"]:
return host in item["overview"]["url"]
"""Exclude items that does not match host on any configured URL"""
if "URLs" in item["overview"]:
return any(filter(lambda x: host in x["u"], item["overview"]["URLs"]))
return False
items = cls.list_items()
@ -263,7 +266,9 @@ class CLI:
try:
item = OnePass.get_item_for_url(os.environ["QUTE_URL"])
except OnePass.NoItemsFoundError as error:
Qute.message_warning(error)
Qute.message_warning("No item found for this site")
logger.error(f"No item found for site: {os.environ['QUTE_URL']}")
logger.error(error)
sys.exit(0)
return item
@ -327,5 +332,15 @@ class CLI:
if __name__ == "__main__":
arguments = parser.parse_args()
# Prevent filling credentials in non-secure sites if not explicitly allwoed
if not arguments.allow_insecure_sites:
if urlsplit(os.environ["QUTE_URL"])[0] != "https":
Qute.message_error(
"Trying to fill a non-secure site. If you want to allow it add the --allow-insecure-sites flag."
)
logger.error("Refusing to fill credentials on non-secure sites")
sys.exit(0)
cli = CLI(arguments)
sys.exit(cli.run())