LinsRuis.HW1 3 months ago
parent
commit
39d10b119d
  1. 39
      core/utils/hbtp.go
  2. 2
      go.mod
  3. 2
      go.sum

39
core/utils/hbtp.go

@ -0,0 +1,39 @@
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))
}

2
go.mod

@ -6,7 +6,7 @@ require (
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/gin-gonic/gin v1.10.0
github.com/go-sql-driver/mysql v1.7.0
github.com/mgr9525/HyperByte-Transfer-Protocol v1.1.6-0.20250305031530-c7db43517148
github.com/mgr9525/HyperByte-Transfer-Protocol v1.1.6-0.20250305031847-fe0bb5a7afdc
github.com/mgr9525/go-cloud v1.0.6-0.20250304094133-5581a9414222
github.com/mgr9525/go-ruisutil v1.0.8-0.20250302163406-e880f81a51fb
github.com/qiniu/qmgo v1.1.9

2
go.sum

@ -192,6 +192,8 @@ github.com/mgr9525/HyperByte-Transfer-Protocol v1.1.6-0.20230907125023-7c49de2c5
github.com/mgr9525/HyperByte-Transfer-Protocol v1.1.6-0.20230907125023-7c49de2c55bd/go.mod h1:U2OZ06VD1PHu3ZLZ8tuEHooaOZnoke/4ZKAZfL44bUQ=
github.com/mgr9525/HyperByte-Transfer-Protocol v1.1.6-0.20250305031530-c7db43517148 h1:H2Qie5y6FEq8KGIWRm8Nn2MlYXb6T5JAovSOtcRQA/A=
github.com/mgr9525/HyperByte-Transfer-Protocol v1.1.6-0.20250305031530-c7db43517148/go.mod h1:U2OZ06VD1PHu3ZLZ8tuEHooaOZnoke/4ZKAZfL44bUQ=
github.com/mgr9525/HyperByte-Transfer-Protocol v1.1.6-0.20250305031847-fe0bb5a7afdc h1:7knH9jBQYpw7a5PYoPrBr3jj/EDxZdrZP+XDYcY6CxA=
github.com/mgr9525/HyperByte-Transfer-Protocol v1.1.6-0.20250305031847-fe0bb5a7afdc/go.mod h1:U2OZ06VD1PHu3ZLZ8tuEHooaOZnoke/4ZKAZfL44bUQ=
github.com/mgr9525/go-cloud v1.0.6-0.20250304094133-5581a9414222 h1:VVFuN3YRMLZmxIOzpvIJ1zrra2hViYJTwPPvnOuF0bo=
github.com/mgr9525/go-cloud v1.0.6-0.20250304094133-5581a9414222/go.mod h1:WVmToyrGDsQIneQgAvLBRvmF0sgcKv2IcWzCbGtvCZg=
github.com/mgr9525/go-ruisutil v1.0.8-0.20221028033917-5aedb9af9f79 h1:oJg2AORgRLdiX2MrocyuGN6da+RJ+lp3vbNJnrN87yE=

Loading…
Cancel
Save