-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcreateCredentials.py
68 lines (55 loc) · 1.69 KB
/
createCredentials.py
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
# -*- coding: utf-8 -*-
"""
Created on Thu Jan 17 08:19:38 2019
@author: Thomas Beha
"""
from cryptography.fernet import Fernet
import getpass
from lxml import etree
uname = input("Username: ")
password = getpass.getpass()
timerange = input("Time Range [s]: ")
resolution = input("Resolution [SECOND | MINUTE]: ")
monitoring = input("Monitoring Intervall [s]: ")
logfile = input("Logfile: ")
port = input("Port: ")
ovc = input("OVC IP Addr: ")
fname = input("Filename: ")
keyfile = fname + '.key'
xmlfile = fname + '.xml'
key = Fernet.generate_key()
k1 = key.decode('ASCII')
f = open(keyfile, 'w')
f.write(key.decode('ASCII'))
f.close()
f = Fernet(key)
token = f.encrypt(password.encode('ASCII'))
user = f.encrypt(uname.encode('ASCII'))
root = etree.Element("data")
etree.SubElement(root, "username").text = uname
etree.SubElement(root, "user").text = user
etree.SubElement(root, "password").text = token
etree.SubElement(root, "ovc").text = ovc
etree.SubElement(root, "timerange").text = timerange
etree.SubElement(root, "resolution").text = resolution
etree.SubElement(root, "monitoringintervall").text = monitoring
etree.SubElement(root, "logfile").text = logfile
etree.SubElement(root, "port").text = port
xmloutput = etree.tostring(root, pretty_print=True)
f = open(xmlfile, 'w')
f.write(xmloutput.decode('ASCII'))
f.close()
""" Test the keys """
""" Read keyfile """
f = open(keyfile, 'r')
k2 = f.readline()
f.close()
key2 = k2.encode('ASCII')
""" Parse XML File """
tree = etree.parse(xmlfile)
u2 = (tree.find("user")).text
p2 = (tree.find("password")).text
f = Fernet(key2)
user = f.decrypt(u2.encode('ASCII')).decode('ASCII')
password = f.decrypt(p2.encode('ASCII')).decode('ASCII')
print(user, password)