-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGhostsChat-confgen.py
184 lines (139 loc) Β· 6.05 KB
/
GhostsChat-confgen.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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/python3
from argparse import ArgumentParser
from sys import exit
from os import mkdir
import json
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.primitives.asymmetric import padding
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives import serialization
banner = """
βββββ βββ ββ ββββββ ββββββ βββββββββ ββββββ ββββββ βββ ββ βββ βββββββββ
βββ βββββββ βββββββ ββββββ β β βββ βββββ β ββββ ββ ββββ βββββββββ β βββ ββ
ββββββββββββββββββββ ββββ ββββ β ββββ βββ ββββ βββ β βββββββββββ βββ β ββββ ββ
βββ ββββββ βββ βββ βββ β ββββ ββββ β β βββββββ βββββββ βββ ββββββββββ ββββ β
βββββββββββββββββ ββββββββββββββββ ββββ β ββββββββββ βββββ βββββββββ ββ ββββ ββββ β
ββ β β ββββββ ββββββ β βββ β β β ββ β βββ β ββ ββ β β β βββββ ββ ββββ β ββ
β β β βββ β β β ββ β ββ β β β β ββ β β β β β βββ β β ββ β β
β β β β ββ ββ β β β β β β β β β β β β ββ β β β β
β β β β β β β β β β β β β β β
β akpalanaza v0.3.1
"""
W = '\033[0m'
R = '\033[31m'
G = '\033[32m'
O = '\033[33m'
B = '\033[34m'
P = '\033[35m'
C = '\033[36m'
GR = '\033[37m'
CLIENTS = []
CONFNAME = ""
CONFFOLDER = ""
SERVERIP = ""
SERVERPORT = ""
# +------------------------------+
# | Encryption |
# +------------------------------+
def RsaGenKey() -> tuple[bytes, bytes]:
private_key = rsa.generate_private_key(
public_exponent=65537,
key_size=4096,
backend=default_backend()
)
public_key = private_key.public_key()
private_key = private_key.private_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PrivateFormat.PKCS8,
encryption_algorithm=serialization.NoEncryption()
)
public_key = public_key.public_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PublicFormat.SubjectPublicKeyInfo
)
return private_key, public_key
def RsaGetKeyBytes(key) -> bytes:
return bytes(key)
def RsaGetKeyStr(key=bytes) -> str:
return key.decode()
# +------------------------------+
# | File |
# +------------------------------+
def CreateServerConf():
global CONFNAME, CONFFOLDER, SERVERIP, SERVERPORT
file = CONFFOLDER + "/" + CONFNAME + ".server.ghosts"
with open(file, "w") as f:
payload = {
"server" : {
"ip" : SERVERIP,
"port" : SERVERPORT
}
}
data = json.dumps(payload)
f.write(data)
print ("++SERVER CONF CREATED++")
def CreateClientsConf():
global CONFNAME, CONFFOLDER, SERVERIP, SERVERPORT, CLIENTS
arr = []
for i in CLIENTS:
index = CLIENTS.index(i)
client = json.loads(i)
client[str(index)]["privkey"] = None
arr.append(client)
for i in CLIENTS:
index = CLIENTS.index(i)
client = json.loads(i)
nickname = client[str(index)]["nickname"]
PRIVKEY = client[str(index)]["privkey"]
PUBKEY = client[str(index)]["pubkey"]
file = CONFFOLDER + "/" + CONFNAME + "." + nickname + ".ghosts"
with open(file, "w") as f:
payload = {
"server" : {
"ip" : SERVERIP,
"port" : SERVERPORT
},
"user" : {
"nickname" : nickname,
"aeskey" : AESKEY,
"privkey" : PRIVKEY,
"pubkey" : PUBKEY,
},
"clients" : arr
}
data = json.dumps(payload)
f.write(data)
# +------------------------------+
# | Main |
# +------------------------------+
if __name__ == "__main__":
print (banner)
print ("**SERVER CONFIGURATION**")
CONFNAME = input("Name of configuration: ")
CONFFOLDER = CONFNAME + ".ghosts"
mkdir(CONFFOLDER)
print ("++FOLDER CREATED SUCCESSFULLY++")
SERVERIP = input("Server listening ip [must be x.x.x. not domain]: ")
SERVERPORT = input("Server listening port: ")
print ("**CLIENTS CONFIGURATION**")
client_count = input("Amount of client to generate [defautl is 1]: ")
AESKEY = input("Plain-text AES key to use [must 16, 18 or 20 chars long]: ")
if client_count == "": client_count = 1
else: client_count = int(client_count)
for i in range(client_count):
print (f"**CLIENT {i}**")
NICKNAME = input("Nickname for client: ")
RSAPRIV, RSAPUB = RsaGenKey()
payload = {
str(i) : {
"nickname": NICKNAME,
"pubkey" : RsaGetKeyStr(RSAPUB),
"privkey" : RsaGetKeyStr(RSAPRIV)
}
}
data = json.dumps(payload)
CLIENTS.append(data)
print ("++USER CREATED SUCCESSFULLY++")
CreateServerConf()
CreateClientsConf()