Last active
May 11, 2016 23:26
-
-
Save fcelda/f29180f0d6ea5bfca3b03bb27d23ec53 to your computer and use it in GitHub Desktop.
Yubikey OATH import from FreeOTP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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