From d2b4c26e0fbd6bd2d1d715de6a029c8442c8721b Mon Sep 17 00:00:00 2001 From: Jayash Satolia Date: Tue, 7 Jan 2025 04:07:48 +0530 Subject: [PATCH] Fix auth ticket enterprise --- .../blobbercore/handler/auth_ticket.go | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/code/go/0chain.net/blobbercore/handler/auth_ticket.go b/code/go/0chain.net/blobbercore/handler/auth_ticket.go index 89032880c..5a8923b9a 100644 --- a/code/go/0chain.net/blobbercore/handler/auth_ticket.go +++ b/code/go/0chain.net/blobbercore/handler/auth_ticket.go @@ -2,8 +2,10 @@ package handler import ( "context" + "fmt" "github.com/0chain/blobber/code/go/0chain.net/core/node" "github.com/0chain/common/core/common" + "github.com/0chain/gosdk/core/encryption" "net/http" ) @@ -19,28 +21,33 @@ type AuthTicketResponse struct { // // parameters: // -// +name: Zbox-Signature -// in: header -// type: string -// description: Digital signature to verify that the sender is 0box service. -// +name: client_id -// type: string -// in: query -// description: Client ID is used as a payload to the token generated. The token represents a signed version of this string by the blobber's private key. +// +name: Zbox-Signature +// in: header +// type: string +// description: Digital signature to verify that the sender is 0box service. +// +name: client_id +// type: string +// in: query +// description: Client ID is used as a payload to the token generated. The token represents a signed version of this string by the blobber's private key. // // responses: -// 200: AuthTicketResponse +// +// 200: AuthTicketResponse func GenerateAuthTicket(ctx context.Context, r *http.Request) (interface{}, error) { + clientID := r.URL.Query().Get("client_id") if clientID == "" { return nil, common.NewError("missing_client_id", "client_id is required") } - signature, err := node.Self.Sign(clientID) + round := r.URL.Query().Get("round") + + payload := encryption.Hash(fmt.Sprintf("%s_%s", clientID, round)) + + signature, err := node.Self.Sign(payload) if err != nil { return nil, common.NewError("signature_failed", "signature failed") } - return &AuthTicketResponse{ AuthTicket: signature, }, nil