From 39d10b119d8c96a3161c62683016c078da3de8e4 Mon Sep 17 00:00:00 2001 From: "LinsRuis.HW1" Date: Wed, 5 Mar 2025 11:19:55 +0800 Subject: [PATCH] + --- core/utils/hbtp.go | 39 +++++++++++++++++++++++++++++++++++++++ go.mod | 2 +- go.sum | 2 ++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 core/utils/hbtp.go diff --git a/core/utils/hbtp.go b/core/utils/hbtp.go new file mode 100644 index 0000000..488fdb0 --- /dev/null +++ b/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)) +} diff --git a/go.mod b/go.mod index 066f097..ec20fbc 100644 --- a/go.mod +++ b/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 diff --git a/go.sum b/go.sum index 78f489f..1a105d2 100644 --- a/go.sum +++ b/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=