package utils import ( "time" hbtp "github.com/mgr9525/HyperByte-Transfer-Protocol" ruisUtil "github.com/mgr9525/go-ruisutil" ) func hbtpAuthCheck(c *hbtp.Context, token string) bool { times := c.Args().Get("times") random := c.Args().Get("random") sign := c.Args().Get("sign") if times == "" || random == "" || sign == "" { c.ResString(hbtp.ResStatusAuth, "times,random,sign err") return false } signs := ruisUtil.Md5String(c.Command() + random + times + token) if sign != signs { c.ResString(hbtp.ResStatusAuth, "sign err:"+sign) return false } _, err := time.Parse(time.RFC3339Nano, times) if err != nil { c.ResString(hbtp.ResStatusAuth, "times err:"+err.Error()) return false } //println(fmt.Sprintf("authCheck [%s] parse.times:%s", c.Command(), tms.Format(comm.TimeFmt))) return true } func putHbtpAuthReq(req *hbtp.Request, token string) { times := time.Now().Format(time.RFC3339Nano) random := ruisUtil.RandomString(20) req.SetVersion(2) req.SetArg("times", times) req.SetArg("random", random) req.SetArg("sign", ruisUtil.Md5String(req.GetCommand()+random+times+token)) }