Skip to content

Commit 1e27f7b

Browse files
committed
also parse widevine license response
1 parent 94bc1d9 commit 1e27f7b

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ require (
99
github.com/google/uuid v1.6.0
1010
github.com/iyear/gowidevine v0.1.2
1111
golang.org/x/text v0.23.0
12+
google.golang.org/protobuf v1.35.1
1213
)
1314

1415
require (
1516
github.com/chmike/cmac-go v1.1.0 // indirect
1617
github.com/google/go-cmp v0.5.8 // indirect
1718
github.com/pkg/errors v0.8.1 // indirect
18-
google.golang.org/protobuf v1.35.1 // indirect
1919
)

widevine.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,64 @@ import (
44
"bytes"
55
"encoding/json"
66
"fmt"
7+
"log/slog"
78
"os"
89

910
"github.com/google/uuid"
1011
widevine "github.com/iyear/gowidevine"
12+
wvpb "github.com/iyear/gowidevine/widevinepb"
13+
"google.golang.org/protobuf/encoding/protojson"
14+
"google.golang.org/protobuf/proto"
1115
)
1216

1317
func decodeWidevine(b []byte) error {
18+
slog.Debug("trying to parse widevine protobuf")
19+
20+
indent := ""
21+
if prettyPrint {
22+
indent = " "
23+
}
24+
25+
signedMsg := &wvpb.SignedMessage{}
26+
if err := proto.Unmarshal(tryBase64(b), signedMsg); err != nil {
27+
slog.Debug("failed to unmarshal signed widevinelicense message", "err", err.Error())
28+
} else {
29+
out, err := protojson.MarshalOptions{
30+
EmitUnpopulated: false,
31+
UseEnumNumbers: false,
32+
Indent: indent,
33+
}.Marshal(signedMsg)
34+
if err != nil {
35+
slog.Debug("failed to marshal signed widevine license message as json", "err", err.Error())
36+
} else {
37+
fmt.Fprintln(os.Stderr, "Widevine License Response:")
38+
fmt.Fprintln(os.Stderr, "----------------")
39+
fmt.Fprintln(os.Stdout, string(out))
40+
fmt.Println()
41+
42+
licenseMsg := &wvpb.License{}
43+
if err = proto.Unmarshal(signedMsg.Msg, licenseMsg); err != nil {
44+
return fmt.Errorf("failed to unmarshal license message: %w", err)
45+
} else {
46+
out, err := protojson.MarshalOptions{
47+
EmitUnpopulated: false,
48+
UseEnumNumbers: false,
49+
Indent: indent,
50+
}.Marshal(licenseMsg)
51+
if err != nil {
52+
slog.Debug("failed to marshal license message as json", "err", err.Error())
53+
} else {
54+
fmt.Fprintln(os.Stderr, "Widevine License Message:")
55+
fmt.Fprintln(os.Stderr, "----------------")
56+
fmt.Fprintln(os.Stdout, string(out))
57+
58+
return nil
59+
}
60+
}
61+
}
62+
}
63+
64+
slog.Debug("trying to parse widevine protobuf")
1465
o, err := widevine.NewPSSH(b)
1566
if err != nil {
1667
return fmt.Errorf("failed to parse widevine pssh: %w", err)

0 commit comments

Comments
 (0)