Created
March 20, 2020 21:45
-
-
Save Tasssadar/8bc8fd87c935c79c7593c8dc2f6c4f59 to your computer and use it in GitHub Desktop.
Generate OTP QR codes from Google Authenticator SQLite database
This file contains hidden or 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 | |
# pip3 install --user qrcode[pil] | |
import qrcode | |
import argparse | |
import sqlite3 | |
import os | |
from urllib.parse import quote | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser() | |
parser.add_argument("auth_db", help="Path to the authenticator database") | |
parser.add_argument("dest_dir", help="folder to store QRs in") | |
args = parser.parse_args() | |
os.makedirs(args.dest_dir, 0o755, True) | |
with sqlite3.connect("file:%s?mode=ro" % args.auth_db, uri=True) as db: | |
c =db.cursor() | |
c.execute("SELECT original_name, issuer, secret FROM accounts;") | |
for r in c: | |
label = quote(r[0]) | |
params = [ f"secret={quote(r[2])}" ] | |
if r[1] is not None: | |
params.append(f"issuer={quote(r[1])}") | |
uri = f"otpauth://totp/{label}?{'&'.join(params)}" | |
print(uri) | |
img = qrcode.make(uri) | |
img.save(os.path.join(args.dest_dir, label + ".png")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment