Add support for TOTP tokens.

This commit is contained in:
Markus Birth 2021-08-18 18:35:03 +02:00
parent 785425d613
commit 66a1ee3e27
Signed by: mbirth
GPG Key ID: A9928D7A098C3A9A
2 changed files with 32 additions and 2 deletions

View File

@ -1 +1,13 @@
Quick hack to export a 1pif (1Password export) to kdbx (KeePass).
Improved quick hack to convert a 1pif (1Password export) to kdbx (KeePass).
Install dependencies
--------------------
pipenv install
Run converter
-------------
pipenv run ./convert.py infile.1pif

View File

@ -7,7 +7,7 @@ import onepif
from os.path import splitext
from pykeepass import create_database
from urllib.parse import urlparse
from urllib.parse import urlparse, quote_plus
parser = argparse.ArgumentParser(description="Convert 1Password 1PIF exports into a KeePass KDBX file.")
parser.add_argument("inpath", metavar="input.1pif", help="1Password export file/folder")
@ -65,6 +65,18 @@ def getField(item, designation):
return None
def getTotp(item):
secure = item["secureContents"]
if "sections" in secure:
for section in secure["sections"]:
if not "fields" in section:
continue
for field in section["fields"]:
if field["t"] == "totp":
return field["v"]
return None
opif = onepif.OnepifReader("{}/data.1pif".format(args.inpath))
for item in opif:
@ -94,6 +106,12 @@ for item in opif:
if new_password:
entry.password = new_password
# TOTP
totp = getTotp(item)
if totp:
entry.set_custom_property("TimeOtp-Secret-Base32", totp)
entry.set_custom_property("otp", "otpauth://totp/Sample:username?secret={}&algorithm=SHA1&digits=6&period=30&issuer=Sample".format(quote_plus(totp)))
# Other web fields
if "fields" in secure:
for field in secure["fields"]: