-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathWVApi.cs
87 lines (78 loc) · 3.13 KB
/
WVApi.cs
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
using ProtoBuf;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WVCore.Widevine;
namespace WVCore
{
public class WVApi
{
Dictionary<string, CDMDevice> Devices { get; set; } = new Dictionary<string, CDMDevice>();
public string SessionId { get; set; }
public WVApi(FileInfo clientIdBlobFile, FileInfo privateKeyFile, FileInfo? vmpFile = null)
{
if (!clientIdBlobFile.Exists)
{
throw new FileNotFoundException("clientIdBlobFile not found: " + clientIdBlobFile.FullName);
}
if (!privateKeyFile.Exists)
{
throw new FileNotFoundException("privateKeyFile not found: " + privateKeyFile.FullName);
}
var clientId = File.ReadAllBytes(clientIdBlobFile.FullName);
var privateKey = File.ReadAllBytes(privateKeyFile.FullName);
if (vmpFile != null)
{
if (!vmpFile.Exists)
{
throw new FileNotFoundException("vmpFile not found: " + vmpFile.FullName);
}
var vmp = File.ReadAllBytes(vmpFile.FullName);
Devices.Add("default", new CDMDevice("default", clientId, privateKey, vmp));
}
else
{
Devices.Add("default", new CDMDevice("default", clientId, privateKey));
}
CDM.Devices = Devices;
}
public WVApi(string deviceName)
{
Devices.Add(deviceName, new CDMDevice(deviceName));
CDM.Devices = Devices;
}
public WVApi(byte[] clientIdBlobBytes, byte[] privateKeyBytes, byte[] vmpBytes = null)
{
Devices.Add("default", new CDMDevice("default", clientIdBlobBytes, privateKeyBytes, vmpBytes));
CDM.Devices = Devices;
}
public byte[] GetChallenge(string initDataB64, string certDataB64 = null, bool offline = false, bool raw = false)
{
SessionId = CDM.OpenSession(initDataB64, Devices.Keys.First(), offline, raw);
if (!string.IsNullOrEmpty(certDataB64))
{
CDM.SetServiceCertificate(SessionId, Convert.FromBase64String(certDataB64));
}
return CDM.GetLicenseRequest(SessionId);
}
public bool ProvideLicense(string licenseB64)
{
CDM.ProvideLicense(SessionId, Convert.FromBase64String(licenseB64));
return true;
}
public bool ProvideLicense(string licenseB64, string challengeB64)
{
var signedLicenseRequest = Serializer.Deserialize<SignedLicenseRequest>(new MemoryStream(Convert.FromBase64String(challengeB64)));
var sessionId = signedLicenseRequest.Msg.ContentId.CencId.RequestId;
SessionId = BitConverter.ToString(sessionId).Replace("-", "");
CDM.ProvideLicense(SessionId, Convert.FromBase64String(licenseB64));
return true;
}
public List<ContentKey> GetKeys()
{
return CDM.GetKeys(SessionId);
}
}
}