forked from easonlin404/ksm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic.go
122 lines (102 loc) · 3.95 KB
/
basic.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
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
package main
import (
"encoding/base64"
"fmt"
"math/rand"
"net/http"
"github.com/getfiit/ksm"
"github.com/getfiit/ksm/d"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
)
func main() {
r := gin.Default()
type SpcMessage struct {
Spc string `json:"spc" binding:"required"`
AssetId string `json:"assetId"`
}
r.POST("/fps/rest/getLicense", func(c *gin.Context) {
var spcMessage SpcMessage
if err := c.ShouldBindWith(&spcMessage, binding.JSON); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"err": err.Error(),
})
return
}
fmt.Printf("%v\n", spcMessage)
playback, err := base64.StdEncoding.DecodeString(spcMessage.Spc)
checkError(err)
k := &ksm.Ksm{
Pub: pub,
Pri: pri,
Rck: RandomContentKey{}, // Use random content key for testing
DFunction: d.AppleD{}, // Use D function provided by Apple Inc.
Ask: []byte{},
}
ckc, err2 := k.GenCKC(playback)
checkError(err2)
ckcBase64 := base64.StdEncoding.EncodeToString(ckc)
c.JSON(http.StatusOK, gin.H{
"ckc": ckcBase64,
})
})
r.Run(":8080")
}
func checkError(err error) {
if err != nil {
panic(err)
}
}
// Random content key
type RandomContentKey struct {
}
// Implement FetchContentKey func
func (RandomContentKey) FetchContentKey(assetId []byte) ([]byte, []byte, error) {
key := make([]byte, 16)
iv := make([]byte, 16)
rand.Read(key)
rand.Read(iv)
return key, iv, nil
}
// 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
}
var pub = `-----BEGIN CERTIFICATE-----
MIIDfTCCAmWgAwIBAgIIboBT3GOPJ50wDQYJKoZIhvcNAQEFBQAwfTELMAkGA1UE
BhMCVVMxEzARBgNVBAoMCkFwcGxlIEluYy4xJjAkBgNVBAsMHUFwcGxlIENlcnRp
ZmljYXRpb24gQXV0aG9yaXR5MTEwLwYDVQQDDChEUk0gVGVjaG5vbG9naWVzIENl
cnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTExMTAxODAxNTcyMloXDTEzMTAxNzAx
NTcyMlowRjERMA8GA1UEAwwIUGFydG5lcjIxETAPBgNVBAsMCFBhcnRuZXIyMREw
DwYDVQQKDAhQYXJ0bmVyMjELMAkGA1UEBhMCVVMwgZ8wDQYJKoZIhvcNAQEBBQAD
gY0AMIGJAoGBALReAQ24va6MquxUkOyrVLE0vjc3rv3a16qndKKKGL6afpkN19xc
/cWw9A2W0FCSJYgkY+iyhGPAO4BLWe0QSonJz08GdeEMS2wmj87h8PLe6Yyu8Ida
3hH+snc7hv2bxX5AI72ETSQWlElky3tHLCYV2tqbTW4BGQZvvE4LfM+tAgMBAAGj
gbswgbgwJwYLKoZIhvdjZAYNAQMEGAGAgEeXuoURG4c6qSNQztlZmgq9dM3kTzAv
BgsqhkiG92NkBg0BBAQgAaWxaRPd6O3itrSL3iqhd3fcpUMMhDQTIebXMN1IfmQw
HQYDVR0OBBYEFDdUHOfoNQC1nqz9IzDvC/WJR1ssMAwGA1UdEwEB/wQCMAAwHwYD
VR0jBBgwFoAU6rShbWWjpF5JZST6HCRnrVoa0DMwDgYDVR0PAQH/BAQDAgUgMA0G
CSqGSIb3DQEBBQUAA4IBAQB4gFunl0s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C8VERJ
Q5uTL1t7RFIydXcvm80CQH/E17mWT66PPeqloAfSH/5tJyak2gagkuFnMh779JRF
rl5YIIiAh+q5DkcjWw6eni5O4+UuwXRp29vZaxmDlIE=
-----END RSA PRIVATE KEY-----`