-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecuritykiss.surr.user.js
320 lines (280 loc) · 7.73 KB
/
securitykiss.surr.user.js
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
// ==UserScript==
// @name securitykiss_surrogate
// @description Allows you to obtain your personal SecurityKiss Wireguard "private" (in fact, not really private, real private keys must be generated client side) key without running their JavaScript.
// @author KOLANICH
// @version 0.1
// @license Unlicense
// @grant none
// @run-at document-idle
// @match https://securitykiss.com/download.html
// ==/UserScript==
// todo: Contact [email protected] and ask them to replace their impl with my one
"use strict";
const SecurityKissAPIBase = 'https://cm.securitykiss.com/';
class SecurityKissAPI {
static get(partialUri, jsonDict = null) {
if(jsonDict){
let queryPart = [];
for (let [k, v] of Object.values(jsonDict)) {
queryPart.push(k + "=" + encodeURIComponent(v));
}
partialUri+="?" + queryPart.join("&");
}
return fetch(SecurityKissAPIBase + partialUri, {
method: 'GET',
mode: 'cors',
cache: 'no-cache',
headers: {}
});
}
static post(partialUri, jsonDict = null) {
// fetch doesn't work!!!
let req = new XMLHttpRequest();
req.open("POST", SecurityKissAPIBase + partialUri);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); // Extremily strange, it must be application/json
return new Promise((resolve, reject) => {
req.addEventListener('load', (e) => {
resolve({
"json": () => {
return new Promise((resolve, reject) => {
resolve(JSON.parse(req.responseText));
});
},
"text": () => {
return new Promise((resolve, reject) => {
resolve(req.responseText);
});
}
});
});
req.send(jsonDict ? new Blob([JSON.stringify(jsonDict)], {
type: 'application/json'
}) : null);
});
}
static jsonPost(partialUri, jsonDict = null) {
return this.post(partialUri, jsonDict).then(res => res.json());
}
static textPost(partialUri, jsonDict = null) {
return this.post(partialUri, jsonDict).then(res => res.text());
}
static jsonGet(partialUri, jsonDict = null) {
return this.get(partialUri, jsonDict).then(res => res.json());
}
static textGet(partialUri, jsonDict = null) {
return this.get(partialUri, jsonDict).then(res => res.text());
}
static requestUserId() {
return this.textPost("api/genusid");
}
static getVepList(userID) {
if (!userID) {
throw new Error("userID is mandatory!");
}
return this.jsonPost("api/veplist", {
"Usid": userID
});
}
static getClientConfigLinks(userID, vepID) {
if (!userID) {
throw new Error("userID is mandatory!");
}
if (!vepID) {
throw new Error("vepID is mandatory!");
}
return this.jsonPost("api/clientconfig", {
"Usid": userID,
"Vepid": vepID
});
}
static getGeo() {
return this.jsonGet("geo");
}
static getDatabox(token) {
if(!token){
throw new Error("You must specify token");
}
return this.jsonGet("databox", {
"token": encodeURIComponent(token)
});
}
static getAppDownloadLink(appType="win") {
return this.jsonPost("api/appupdate", {
"Apptype": appType + "app",
"Version": "0.0.0"
});
}
static getPlans() {
return this.jsonGet("api/payableitems");
}
};
const remapping = {
"Id": "ID",
"Name": "Name",
"Country": "State",
"Cc": "State_ISO_code",
"City": "City",
//"Dns": "Recommended_DNS" /* Always 8.8.8.8/32, it is Google public DNS */ ,
"Ipnet": "Interface_Address",
"Eport": "Endpoint_port",
"Eipnet": "Endpoint_IP",
"Pubkey": "Peer_PublicKey",
};
class VEP {
static keys() {
return Object.values(remapping);
}
constructor(parent, id = null) {
this.parent = parent
this.configLinks = null
for (let rk of this.constructor.keys()) {
this[rk] = null;
}
this.ID = id;
}
initFromJsonObject(jso) {
for (let [k, rk] of Object.entries(remapping)) {
this[rk] = jso[k];
}
return this;
}
* values() {
for (let rk of this.constructor.keys()) {
yield this[rk];
}
}
* entries() {
for (let rk of this.constructor.keys()) {
yield [rk, this[rk]];
}
}
[Symbol.iterator]() {
return this.entries();
}
async getConfigLinks() {
if (!this.configLinks) {
this.configLinks = SecurityKissAPI.getClientConfigLinks(this.parent.userID, this.ID);
this.configLinks = await this.configLinks;
}
return this.configLinks
}
async getConfigURI() {
return (await this.getConfigLinks())["Txt"]
}
async getQrURI() {
return (await this.getConfigLinks())["Qr"];
}
async getConfig() {
return SecurityKissAPI.getText(await this.getConfigURI());
}
};
class SecurityKiss {
constructor(userID = null) {
this.userID = userID;
this.veps = null;
}
async getUserId() {
if (!this.userID) {
this.userID = await SecurityKissAPI.requestUserId();
}
return this.userID
}
*convertVeps(veps) {
for (let vepJSO of veps) {
let v = new VEP(this);
v.initFromJsonObject(vepJSO);
yield v;
}
}
async getVeps() {
if (!this.veps) {
this.veps = [...this.convertVeps(await SecurityKissAPI.getVepList(await this.getUserId()))];
}
return this.veps;
}
}
const newUserBtn = document.getElementById("getconfaction"),
existingUserCbx = document.getElementById("existing-user-chb"),
stepTwoContainer = document.getElementById("step-two"),
configInnerBox = document.getElementById("getconfiginner"),
mySubscriberIdArea = document.getElementById("sid-enter"),
mySubscriberIdField = document.getElementById("sid");
mySubscriberIdField.required = !0;
mySubscriberIdField.pattern = "\\d{5}(?:-\\d{5}){3}";
mySubscriberIdField.title = "4 groups of 5 digits each, separated with dashes (" + mySubscriberIdField.placeholder + ")";
{
let s = document.createElement("STYLE");
s.textContent = "#sid:invalid {border-color: red;};#sid:valid {border-color: green;};";
document.head.appendChild(s);
}
const mySubscriberIdIndicationDiv = document.getElementById("sid-value");
const sk = new SecurityKiss;
function getStuffForAUser(userID = null) {
sk.userID = userID;
sk.getVeps().then((veps) => {
stepTwoContainer.style.display = "block";
mySubscriberIdField.value = mySubscriberIdIndicationDiv.textContent = sk.userID;
existingUserCbx.checked = !0;
onExistingUserCbxToggle();
let t = document.createElement("TABLE"), tr = document.createElement("THEAD");
t.appendChild(tr);
let tbd = document.createElement("TBODY"), rk_td;
t.appendChild(tbd);
for (rk_td of Object.values(remapping)) {
let th = document.createElement("TH");
th.textContent = rk_td.replace("_", " ");
tr.appendChild(th)
}
for (let vep of sk.veps) {
tr = document.createElement("TR");
for (let [k, v] of vep) {
rk_td = document.createElement("TD");
if (k == "ID") {
let a = document.createElement("A");
a.textContent = v;
let cb = (evt) => {
a.removeEventListener("click", cb, false);
vep.getConfigURI().then((uri) => {
a.href = uri;
}).then(
() => {
vep.getQrURI().then(
(uri) => {
let i = new Image;
i.src = uri;
i.style.height = i.style.width = "10em";
a.appendChild(i)
}
);
},
(err) => {
a.textContent = err;
}
);
};
a.addEventListener("click", cb, !1);
rk_td.appendChild(a);
} else {
rk_td.textContent = v;
}
tr.appendChild(rk_td);
}
tbd.appendChild(tr);
}
configInnerBox.appendChild(t);
configInnerBox.scrollIntoView();
});
}
newUserBtn.addEventListener("click", (evt) => {
getStuffForAUser(mySubscriberIdField.value ? mySubscriberIdField.value : null);
}, !1);
function onExistingUserCbxToggle(){
mySubscriberIdField.reportValidity();
mySubscriberIdArea.style.display = (existingUserCbx.checked ? "block" : "none");
}
existingUserCbx.addEventListener("change", (evt) => {
onExistingUserCbxToggle();
}, !1);
mySubscriberIdField.addEventListener("change", (evt) => {
evt.target.reportValidity();
}, !1);