Skip to content

Instantly share code, notes, and snippets.

@fcelda
Last active May 11, 2016 23:26
Show Gist options
  • Save fcelda/f29180f0d6ea5bfca3b03bb27d23ec53 to your computer and use it in GitHub Desktop.
Save fcelda/f29180f0d6ea5bfca3b03bb27d23ec53 to your computer and use it in GitHub Desktop.
Yubikey OATH import from FreeOTP
#!/usr/bin/env python3
#
# % adb backup -shared org.fedorahosted.freeotp
# % java -jar abe.all.jar unpack backup.bb backup.tar password
# % # extract tokens.xml from the tar
#
import json
import xml.etree.ElementTree
import base64
def export_yubioath(data, secret):
print("yubioath-cli put --name '%s' --oath-type '%s' --digits %d %s" % (
name,
data["type"].lower(),
data["digits"],
base64.b32encode(secret).decode("ascii")
))
tree = xml.etree.ElementTree.parse("tokens.xml")
root = tree.getroot()
assert root.tag == "map"
for child in root:
assert child.tag == "string"
name = child.get("name")
if name == "tokenOrder":
continue
data = json.loads(child.text)
secret = bytes([(uc + 256) % 256 for uc in data["secret"]])
export_yubioath(data, secret)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment