Skip to content

Commit 4163ea3

Browse files
committed
update
1 parent f883d30 commit 4163ea3

1 file changed

Lines changed: 52 additions & 1 deletion

File tree

main.go

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@ package main
22

33
import (
44
"flag"
5+
"os"
56
"log"
67
"sync"
8+
"strings"
79
"io/ioutil"
8-
"os"
910
"os/signal"
1011
"syscall"
1112
"net/http"
1213
"fmt"
1314
"time"
1415
"encoding/json"
16+
"crypto/hmac"
17+
"crypto/sha1"
1518
"github.com/chenyf/gibbon/comet"
1619
)
1720

@@ -30,6 +33,31 @@ func getStatus(w http.ResponseWriter, r *http.Request) {
3033
fmt.Fprintf(w, "total register device: %d\n", size)
3134
}
3235

36+
func checkAuthz(uid string, devid string) bool {
37+
return false
38+
}
39+
40+
func sign(path string, query map[string]string) []byte{
41+
uid := query["uid"]
42+
rid := query["rid"]
43+
tid := query["tid"]
44+
src := query["src"]
45+
tm := query["tm"]
46+
pmtt := query["pmtt"]
47+
48+
raw := []string{path, uid, rid, tid, src, tm, pmtt}
49+
args := []string{}
50+
x := []int{6, 5, 4, 3, 2, 1, 0}
51+
for _, item := range(x) {
52+
args = append(args, raw[item])
53+
}
54+
data := strings.Join(args, "")
55+
key := "xnRzFxoCDRVRU2mNQ7AoZ5MCxpAR7ntnmlgRGYav"
56+
mac := hmac.New(sha1.New, []byte(key))
57+
mac.Write([]byte(data))
58+
return mac.Sum(nil)
59+
}
60+
3361
func postRouterCommand(w http.ResponseWriter, r *http.Request) {
3462
var response CommandResponse
3563
response.Status = 1
@@ -56,6 +84,13 @@ func postRouterCommand(w http.ResponseWriter, r *http.Request) {
5684
return
5785
}
5886

87+
if !checkAuthz(uid, rid) {
88+
response.Error = "authorization failed"
89+
b, _ := json.Marshal(response)
90+
fmt.Fprintf(w, string(b))
91+
return
92+
}
93+
5994
/*
6095
uid := r.FormValue("uid")
6196
if uid == "" { fmt.Fprintf(w, "missing 'uid'\n"); return; }
@@ -67,6 +102,22 @@ func postRouterCommand(w http.ResponseWriter, r *http.Request) {
67102
if tm == "" { fmt.Fprintf(w, "missing 'tm'\n"); return; }
68103
pmtt := r.FormValue("pmtt")
69104
if pmtt == "" { fmt.Fprintf(w, "missing 'pmtt'\n"); return; }
105+
query := map[string]string {
106+
"uid" : uid,
107+
"rid" : rid,
108+
"tid" : tid,
109+
"src" : "letv",
110+
"tm" : tm,
111+
"pmtt" : pmtt,
112+
}
113+
path := "/router/command"
114+
mysign := sign(path, query)
115+
if mysign != sign {
116+
response.Error = "sign valication failed"
117+
b, _ := json.Marshal(response)
118+
fmt.Fprintf(w, string(b))
119+
return
120+
}
70121
*/
71122

72123
if r.Body == nil {

0 commit comments

Comments
 (0)