forked from payt0nc/fairplay-ksm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
contentKey.go
42 lines (33 loc) · 1.15 KB
/
contentKey.go
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
// NOTE: In production, please implement your content key logic instead of Random Content Key
package main
import (
"crypto/md5"
"math/rand"
"github.com/arabian9ts/fairplay-ksm/ksm"
)
type RandomContentKey struct {
}
// Implement FetchContentKey func
func (RandomContentKey) FetchContentKey(assetID []byte) ([]byte, []byte, error) {
return generateDummyKeyIVPair(assetID)
}
// Implement FetchContentKeyDuration func
func (RandomContentKey) FetchContentKeyDuration(assetID []byte) (*ksm.CkcContentKeyDurationBlock, error) {
LeaseDuration := rand.Uint32() // The duration of the lease, if any, in seconds.
RentalDuration := rand.Uint32() // The duration of the rental, if any, in seconds.
return ksm.NewCkcContentKeyDurationBlock(LeaseDuration, RentalDuration), nil
}
func generateDummyKeyIVPair(assetID []byte) ([]byte, []byte, error) {
dummyKey := make([]byte, 16)
dummyIV := make([]byte, 16)
rand.Read(dummyIV)
if len(assetID) == 0 {
rand.Read(dummyKey)
return dummyKey, dummyIV, nil
}
// NOTE: Here is to implement your key generator.
generator := md5.New()
generator.Write(assetID)
dummyKey = generator.Sum(nil)
return dummyKey, dummyIV, nil
}