-
Notifications
You must be signed in to change notification settings - Fork 6
/
key.ts
53 lines (48 loc) · 1.5 KB
/
key.ts
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
import axios from "axios";
import fs from "fs";
import {
LicenseType,
SERVICE_CERTIFICATE_CHALLENGE,
Session,
} from "node-widevine";
import { USER_AGENT } from "./utils";
import { convertToWidevinePssh } from "./pssh";
interface Data {
licenseUid: string;
pssh: string;
privatekey: string;
clientid: string;
}
export async function getKeys(data: Data) {
const pssh = Buffer.from(convertToWidevinePssh(data.pssh), "base64");
const privateKey = fs.readFileSync(data.privatekey);
const identifierBlob = fs.readFileSync(data.clientid);
const session = new Session({ privateKey, identifierBlob }, pssh);
const serviceCertificateResponse = await axios.post(
"https://mlic.dmm.com/drm/widevine/license",
Buffer.from(SERVICE_CERTIFICATE_CHALLENGE),
{
headers: {
"Content-Type": "application/octet-stream",
},
responseType: "arraybuffer",
}
);
const serviceCertificate = Buffer.from(serviceCertificateResponse.data);
await session.setServiceCertificateFromMessage(serviceCertificate);
const response = await axios.post(
"https://mlic.dmm.com/drm/widevine/license",
Buffer.from(session.createLicenseRequest(LicenseType.OFFLINE)),
{
headers: {
"User-Agent": USER_AGENT,
Host: "mlic.dmm.com",
Cookie: `licenseUID=${data.licenseUid}`,
"Content-Type": "application/octet-stream",
},
responseType: "arraybuffer",
}
);
const keys = session.parseLicense(Buffer.from(response.data));
return keys;
}