File: gauth.py

package info (click to toggle)
rust-cotp 1.9.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,392 kB
  • sloc: python: 168; xml: 14; sh: 9; makefile: 4
file content (39 lines) | stat: -rw-r--r-- 908 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import sqlite3
import sys
import json


def get_accounts(filename):
    conn = sqlite3.connect(filename)
    c = conn.cursor()
    accounts = []
    for row in c.execute("SELECT email,secret,issuer,type,counter FROM accounts"):
        if row[3] == 0:
            type_ = "TOTP"
        else:
            type_ = "HOTP"
        accounts.append(
            {
                'label': row[0],
                'secret': row[1],
                'issuer': row[2],
                'type': type_,
                'digits': 6,
                'counter': row[4],
                'algorithm': 'SHA1',
            }
        )
    c.close()
    return accounts


def main():
    if len(sys.argv) != 3:
        print("Usage: python gauth.py [INPUT_FILE] [OUTPUT_FILE]")
        return
    output_file = open(sys.argv[2], 'w')
    output_file.write(json.dumps(get_accounts(sys.argv[1])))
    output_file.close()


main()