David Blume commited on 2020-03-12 12:43:21
Showing 6 changed files, with 104 additions and 1 deletions.
... | ... |
@@ -1,4 +1,6 @@ |
1 | 1 |
function init() |
2 |
+ m.top.ObserveField("pucidHash", "onUpdatePucidHash") |
|
3 |
+ |
|
2 | 4 |
m.title = m.top.findNode("title") |
3 | 5 |
m.title.font.size=248 |
4 | 6 |
m.title.color="0x62C7FF18" |
... | ... |
@@ -59,6 +61,7 @@ function init() |
59 | 61 |
|
60 | 62 |
m.testTask = CreateObject("roSGNode", "TestTask") |
61 | 63 |
m.testTask.ObserveField("updateText", "onUpdateTextRight") |
64 |
+ ' Note m.top.pucidHash is not set at this point, so we can't set it for testTask either. |
|
62 | 65 |
m.testTask.control = "RUN" |
63 | 66 |
|
64 | 67 |
texttimer = m.top.findNode("textTimer") |
... | ... |
@@ -74,6 +77,12 @@ function init() |
74 | 77 |
m.top.setFocus(true) |
75 | 78 |
end function |
76 | 79 |
|
80 |
+ |
|
81 |
+function onUpdatePucidHash() as void |
|
82 |
+ m.testTask.setField("pucidHash", m.top.pucidHash) |
|
83 |
+end function |
|
84 |
+ |
|
85 |
+ |
|
77 | 86 |
function onUpdateText() as void |
78 | 87 |
if m.updates.text.Len() = 0 |
79 | 88 |
m.updates.text = m.myTask.updateText |
... | ... |
@@ -1,7 +1,35 @@ |
1 | 1 |
sub init() |
2 | 2 |
m.top.functionName = "executeTest" |
3 |
+ m.top.ObserveField("pucidHash", "onUpdatePucidHash") |
|
3 | 4 |
end sub |
4 | 5 |
|
6 |
+ |
|
7 |
+function GetRequest() as object |
|
8 |
+ r = CreateObject("roUrlTransfer") |
|
9 |
+ r.InitClientCertificates() |
|
10 |
+ ' r.SetCertificatesFile("pkg:/certificates/rokuca.pem") |
|
11 |
+ r.SetCertificatesFile("common:/certs/ca-bundle.crt") |
|
12 |
+ |
|
13 |
+ r.SetUrl("https://api.roku.com/registrysvc/api/" + CreateObject("roAppInfo").GetDevID()) |
|
14 |
+ r.AddHeader("accept", "application/json") |
|
15 |
+ r.AddHeader("content-type", "application/*") |
|
16 |
+ r.AddHeader("x-roku-registry-aes-key-version", "v1") |
|
17 |
+ r.AddHeader("x-roku-reserved-regsvc-token", "") |
|
18 |
+ |
|
19 |
+ ' Note if called from init(), then m.top.pucidHash won't have been set yet. |
|
20 |
+ r.AddHeader("x-roku-registry-aes-encryption-key", m.top.pucidHash) |
|
21 |
+ |
|
22 |
+ print "GetRequest() x-roku-registry-aes-encryption-key:" + m.top.pucidHash |
|
23 |
+ print " URL:" + r.GetUrl() |
|
24 |
+ return r |
|
25 |
+end function |
|
26 |
+ |
|
27 |
+ |
|
28 |
+function onUpdatePucidHash() as void |
|
29 |
+ ' Maybe do something with m.top.pucidHash |
|
30 |
+end function |
|
31 |
+ |
|
32 |
+ |
|
5 | 33 |
function executeTest() as void |
6 | 34 |
' This task gets run one at the start, and then |
7 | 35 |
' again every time the OK button is pressed. |
... | ... |
@@ -13,4 +41,21 @@ function executeTest() as void |
13 | 41 |
m.top.updateText = key + " = " + val.ToStr() |
14 | 42 |
end for |
15 | 43 |
|
44 |
+ request = GetRequest() |
|
45 |
+ port = CreateObject("roMessagePort") |
|
46 |
+ request.SetMessagePort(port) |
|
47 |
+ |
|
48 |
+ res = request.AsyncPostFromString("My dxb credentials.") |
|
49 |
+ if res = true |
|
50 |
+ msg = wait(0, port) |
|
51 |
+ if type(msg) = "roUrlEvent" |
|
52 |
+ if msg.GetInt() = 1 |
|
53 |
+ m.top.updateText = "PSI Request roUrlEvent = " + msg.GetResponseCode().ToStr() |
|
54 |
+ end if |
|
55 |
+' else if msg = invalid |
|
56 |
+' request.AsyncCancel() |
|
57 |
+ end if |
|
58 |
+ else |
|
59 |
+ m.top.updateText = "AsyncPostFromString failed" |
|
60 |
+ end if |
|
16 | 61 |
end function |
... | ... |
@@ -1,10 +1,13 @@ |
1 | 1 |
title=dxb |
2 | 2 |
major_version=0 |
3 | 3 |
minor_version=0 |
4 |
-build_version=5 |
|
4 |
+build_version=7 |
|
5 | 5 |
ui_resolutions=fhd |
6 | 6 |
mm_icon_focus_hd=pkg:/images/mm_icon_focus_hd.png |
7 | 7 |
mm_icon_focus_sd=pkg:/images/mm_icon_focus_sd.png |
8 | 8 |
splash_screen_hd=pkg:/images/splash_screen_hd.png |
9 | 9 |
splash_screen_sd=pkg:/images/splash_screen_sd.png |
10 |
+dial_title=dxb |
|
11 |
+dial_additional_data_registry_section=dial_dxb |
|
12 |
+dial_additional_data_registry_key=additional_data |
|
10 | 13 |
splash_min_time=0 |
... | ... |
@@ -10,8 +10,18 @@ sub Main(launchParams) |
10 | 10 |
port = CreateObject("roMessagePort") |
11 | 11 |
screen.SetMessagePort(port) |
12 | 12 |
|
13 |
+ pucid = GetPUCID() |
|
14 |
+ if pucid <> invalid |
|
15 |
+ pucidHash = Sign(pucid) |
|
16 |
+ print "PUCID: " + pucid + ", hash: " + pucidHash |
|
17 |
+ else |
|
18 |
+ pucidHash = "" |
|
19 |
+ print "Error: PUCID is not valid" |
|
20 |
+ end if |
|
21 |
+ |
|
13 | 22 |
' Create a scene and load /components/dxb.xml' |
14 | 23 |
m.scene = screen.CreateScene("dxb") |
24 |
+ m.scene.setField("pucidHash", pucidHash) |
|
15 | 25 |
screen.show() |
16 | 26 |
|
17 | 27 |
while(true) |
... | ... |
@@ -25,3 +35,35 @@ sub Main(launchParams) |
25 | 35 |
|
26 | 36 |
end sub |
27 | 37 |
|
38 |
+ |
|
39 |
+function Sign(key) as String |
|
40 |
+ evp = CreateObject("roEVPDigest") |
|
41 |
+ ba = CreateObject("roByteArray") |
|
42 |
+ ba.FromAsciiString(key) |
|
43 |
+ evp.Setup("md5") |
|
44 |
+ evp.Update(ba) |
|
45 |
+ md5 = evp.Final() |
|
46 |
+ base64 = CreateObject("roByteArray") |
|
47 |
+ base64.FromHexString(md5) |
|
48 |
+ hashedKey = base64.ToBase64String() |
|
49 |
+ return hashedKey |
|
50 |
+end function |
|
51 |
+ |
|
52 |
+ |
|
53 |
+function GetPUCID() as String |
|
54 |
+ key = invalid |
|
55 |
+ appInfo = CreateObject("roAppInfo") |
|
56 |
+ if appInfo.IsDev() = true |
|
57 |
+ key = "my-secret" |
|
58 |
+ else |
|
59 |
+ cs = CreateObject("roChannelStore") |
|
60 |
+ res = cs.GetChannelCred() |
|
61 |
+ if res <> invalid |
|
62 |
+ if res.json <> invalid and res.json <> "" |
|
63 |
+ json = ParseJson(res.json) |
|
64 |
+ key = json.roku_pucid |
|
65 |
+ end if |
|
66 |
+ end if |
|
67 |
+ end if |
|
68 |
+ return key |
|
69 |
+end function |
|
28 | 70 |
\ No newline at end of file |
29 | 71 |