-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgetwvkeys.js
149 lines (122 loc) · 3.51 KB
/
getwvkeys.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
import axios from "axios";
import { Buffer } from "node:buffer";
class getWvKeys {
constructor(
pssh,
licenseUrl,
authKey,
x_custom_data,
apiUrl = "https://getwvkeys.cc/pywidevine",
buildInfo = "",
force = false,
verbose = false,
) {
this.pssh = pssh;
this.licenseUrl = licenseUrl;
this.authKey = authKey;
this.apiUrl = apiUrl;
this.buildInfo = buildInfo;
this.force = force;
this.data = {
"pssh": this.pssh,
"buildInfo": this.buildInfo,
"force": this.force,
"license_url": this.licenseUrl,
};
this.headers = {
"X-API-Key": this.authKey,
"Content-Type": "application/json",
};
this.headers["x-custom-data"] = x_custom_data;
this.verbose = verbose;
}
async generate_request() {
const config = {
method: "post",
url: this.apiUrl,
headers: this.headers,
data: this.data,
validateStatus: false,
};
const licenseResponse = await axios(config);
//get json from response
const licenseData = licenseResponse.data;
const responseHeaders = licenseResponse.headers;
if (this.verbose) {
log("headers: " + JSON.stringify(responseHeaders));
}
if ("x-cache" in responseHeaders) {
return { "cache": true, "keys": licenseData["keys"] };
}
this.data["session_id"] = licenseData["session_id"];
let challenge = licenseData["challenge"];
if (this.verbose) {
log("License Request Generated\n", challenge);
log("Session ID:", this.data["session_id"]);
}
//turn challenge into byte array it's encoded in base64
challenge = Buffer.from(challenge, "base64");
return { "cache": false, "challenge": challenge };
}
async post_request(challenge) {
const config = {
method: "post",
url: this.licenseUrl,
headers: this.headers,
data: challenge,
responseType: "arraybuffer",
};
let licenseResponse = await axios(config);
// check if response is ok
if (licenseResponse.status !== 200) {
log("License Request Failed" + licenseResponse.data.toString(), true);
return;
}
// encode license response in base64
licenseResponse = Buffer.from(licenseResponse.data, "binary").toString(
"base64",
);
if (this.verbose) {
log("License Response Generated\n" + licenseResponse);
}
return licenseResponse;
}
async decrypter(license_response) {
this.data["response"] = license_response;
const header = {
"X-API-Key": this.authKey,
"Content-Type": "application/json",
};
let config = {
method: "post",
url: this.apiUrl,
headers: header,
data: this.data,
};
let decrypterResponse = await axios(config);
// check if response is ok
if (decrypterResponse.status !== 200) {
log("License Request Failed" + decrypterResponse.data.toString(), true);
return;
}
log("License Response Generated\n" + decrypterResponse.data.toString());
return decrypterResponse.data;
}
async getWvKeys() {
let licenseData = await this.generate_request();
if (licenseData["cache"] === true) {
return licenseData["keys"][0]["key"];
}
let license_response = await this.post_request(licenseData["challenge"]);
let decrypt_response = await this.decrypter(license_response);
return decrypt_response["keys"][0];
}
}
export default getWvKeys;
function log(msg, error = false) {
if (error) {
console.error("[-]\t" + msg);
return;
}
console.log("[+]\t" + msg);
}