This repository was archived by the owner on Jan 24, 2018. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathkeysync
More file actions
executable file
·120 lines (104 loc) · 5.3 KB
/
keysync
File metadata and controls
executable file
·120 lines (104 loc) · 5.3 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''keysync is a command line program'''
from __future__ import print_function
import sys
import os
import platform
import argparse
# if python < 2.7, get OrderedDict from a standalone lib
if sys.version_info[0] == 2 and sys.version_info[1] < 7:
from ordereddict import OrderedDict
else:
from collections import OrderedDict
import otrapps.util
import otrapps
from otrapps.chatsecure import ChatSecureProperties
# no argv passed in here because argparse just checks sys.argv directly
def main():
'''this is the main entry into this program'''
if len(sys.argv) == 1:
sys.argv.append('--help') # if no args, show help
# defaults
if platform.system() == 'Darwin':
default_input = 'adium'
else:
default_input = 'pidgin'
default_output = 'chatsecure'
parser = argparse.ArgumentParser()
# Note: the 'default' argument is not used with the input and output args
# below, because the combination of the append action and default, means
# the default will ALWAYS appear in the actions.
# this may or may not be an argparse bug.
parser.add_argument('-i', '--input', action='append',
choices=sorted(otrapps.apps_supported),
help="specify which programs to take as input. if multiple then they'll be merged (default: %s)" % (default_input))
parser.add_argument('-o', '--output', action='append',
choices=sorted(otrapps.apps_supported),
help="specify which format to write out. if multiple then each will be written out (default: %s)" % (default_output))
parser.add_argument('--output-folder', default=os.getcwd(),
help='write the output files to this folder (default: current folder)')
parser.add_argument('--no-qrcode', action='store_true', default=False,
help='do not print the ChatSecure QR Code to the terminal')
parser.add_argument('-q', '--quiet', action='store_true', default=False,
help='do not print anything to the terminal')
parser.add_argument('-t', '--test', help=argparse.SUPPRESS, default=None)
parser.add_argument('--version', action='version', version='%(prog)s {v}'.format(v=otrapps.__version__))
args = parser.parse_args()
# manually set defaults, see Note above
if args.input == None or len(args.input) == 0:
args.input = [default_input]
if args.output == None or len(args.output) == 0:
args.output = [default_output]
# downcase all names to be a little more friendly
args.input = [i.lower() for i in args.input]
args.output = [o.lower() for o in args.output]
keydict = dict()
for app in args.input:
print('Reading %s files...' % ( app ))
# special case GB for now 'cause of this keyfile business
if app == 'chatsecure':
keyfile = os.path.join(args.output_folder, ChatSecureProperties.keyfile)
if os.path.exists(keyfile):
otrapps.util.merge_keydicts(keydict, ChatSecureProperties.parse(keyfile))
else:
encrypted_keyfile = os.path.join(args.output_folder, ChatSecureProperties.encryptedkeyfile)
if os.path.exists(encrypted_keyfile):
if sys.version_info[0] == 2:
password = raw_input("What is the encryption password for keystore \"otr_keystore.ofcaes\"?\n")
else:
password = input("What is the encryption password for keystore \"otr_keystore.ofcaes\"?\n")
keyfile = ChatSecureProperties._decrypt_ofcaes(encrypted_keyfile, password)
otrapps.util.merge_keydicts(keydict, ChatSecureProperties.parse(keyfile))
else:
print(('ChatSecure WARNING: No usable "' + ChatSecureProperties.keyfile +
'" or "' + ChatSecureProperties.encryptedkeyfile +
'" file found, not reading keys from ChatSecure!'))
break
properties = otrapps.apps[app]
if args.test:
# example: "tests/gajim/"
settings_dir = os.path.join(args.test, app)
otrapps.util.merge_keydicts(keydict, properties.parse(settings_dir))
else:
otrapps.util.merge_keydicts(keydict, properties.parse())
if keydict:
keydict = OrderedDict(sorted(keydict.items(), key=lambda t: t[0]))
otrapps.make_outdir(args.output_folder, '')
for app in args.output:
# once again special case GB
if 'chatsecure' in args.output:
ChatSecureProperties.write(keydict, args.output_folder)
if not args.quiet and ChatSecureProperties.password:
if not args.no_qrcode and sys.stdout.isatty():
print('\nScan this QR Code:')
import qrcode
pwqr = qrcode.QRCode()
pwqr.add_data(ChatSecureProperties.password)
pwqr.print_tty()
print(('\nor enter this password into ChatSecure: \n\t' + ChatSecureProperties.password))
break
properties = otrapps.apps[app]
properties.write(keydict, args.output_folder)
if __name__ == "__main__":
main()