Coverage for pass_import/managers/freeotp.py: 100%
23 statements
« prev ^ index » next coverage.py v7.4.3, created at 2024-02-26 12:11 +0000
« prev ^ index » next coverage.py v7.4.3, created at 2024-02-26 12:11 +0000
1# -*- encoding: utf-8 -*-
2# pass import - Passwords importer swiss army knife
3# Copyright (C) 2017-2024 Alexandre PUJOL <alexandre@pujol.io>.
4#
6import base64
7import json
9from pass_import.core import register_managers
10from pass_import.formats.otp import OTP
13class FreeOTPPlus(OTP):
14 """Importer for FreeOTPPlus in JSON format."""
15 name = 'freeotp+'
16 format = 'json'
17 url = 'https://github.com/helloworld1/FreeOTPPlus'
18 hexport = 'Settings> Export> Export JSON Format'
19 himport = 'pass import freeotp+ file.json'
20 json_header = {
21 'tokenOrder': list,
22 'tokens': [{
23 'algo': str,
24 'digits': int,
25 'issuerExt': str,
26 'label': str,
27 'secret': list,
28 'type': str
29 }]
30 }
32 def parse(self):
33 """Parse FreeOTP+ JSON file."""
34 jsons = json.loads(self.content)
35 for item in jsons['tokens']:
36 item['label'] = item['issuerExt']
37 item['algorithm'] = item['algo']
38 item['secret'] = base64.b32encode(
39 bytes(x & 0xff for x in item['secret'])).decode("utf8")
41 entry = {}
42 entry['title'] = item['issuerExt']
43 entry['otpauth'] = self._otp(item)
44 entry['type'] = item['type'].lower()
45 self.data.append(entry)
48register_managers(FreeOTPPlus)