Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add "X-Gnfd-Expires" header #34

Merged
merged 3 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -710,8 +710,6 @@ github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8t
github.com/klauspost/crc32 v0.0.0-20161016154125-cb6bfca970f6/go.mod h1:+ZoRqAPRLkC4NPOvfYeR5KNOrY6TD+/sAC3HXPZgDYg=
github.com/klauspost/pgzip v1.0.2-0.20170402124221-0bf5dcad4ada/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs=
github.com/klauspost/reedsolomon v1.9.3/go.mod h1:CwCi+NUr9pqSVktrkN+Ondf06rkhYZ/pcNv7fu+8Un4=
github.com/klauspost/reedsolomon v1.11.6 h1:h0MUpEzmretucmlelC3EefQHKgk6vWpKz/ctB/tmaEs=
github.com/klauspost/reedsolomon v1.11.6/go.mod h1:cuXqklb3LNaurR5MVjy7WLXAEUqGz4I0Uc+rnQ7POUg=
github.com/klauspost/reedsolomon v1.11.8 h1:s8RpUW5TK4hjr+djiOpbZJB4ksx+TdYbRH7vHQpwPOY=
github.com/klauspost/reedsolomon v1.11.8/go.mod h1:4bXRN+cVzMdml6ti7qLouuYi32KHJ5MGv0Qd8a47h6A=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
Expand Down
5 changes: 4 additions & 1 deletion go/http/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ const (
HTTPHeaderUnsignedMsg = "X-Gnfd-Unsigned-Msg"

HTTPHeaderContentMD5 = "Content-MD5"
HTTPHeaderDate = "X-Gnfd-Date"
HTTPHeaderRange = "Range"
HTTPHeaderContentSHA256 = "X-Gnfd-Content-Sha256"

HTTPHeaderUserAddress = "X-Gnfd-User-Address"
// HTTPHeaderDate The date and time format must follow the ISO 8601 standard, and must be formatted with the "yyyyMMddTHHmmssZ" format. For example if the date and time was "08/01/2016 15:32:41.982-700" then it must first be converted to UTC (Coordinated Universal Time) and then submitted as "20160801T223241Z".
HTTPHeaderDate = "X-Gnfd-Date"
// HTTPHeaderExpires Provides the time period, in seconds, for which the generated signature URL is valid. For example, 86400 (24 hours). This value is an integer. The minimum value you can set is 1, and the maximum is 604800 (seven days).
HTTPHeaderExpires = "X-Gnfd-Expires"
ruojunm marked this conversation as resolved.
Show resolved Hide resolved
)
14 changes: 10 additions & 4 deletions go/http/gen_sign_str.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import (
"strings"

"github.com/ethereum/go-ethereum/crypto"

"github.com/bnb-chain/greenfield-common/go/hash"
)

var supportHeads = []string{
HTTPHeaderContentSHA256, HTTPHeaderTransactionHash, HTTPHeaderObjectID, HTTPHeaderRedundancyIndex, HTTPHeaderResource,
HTTPHeaderDate, HTTPHeaderRange, HTTPHeaderPieceIndex, HTTPHeaderContentType, HTTPHeaderContentMD5, HTTPHeaderUnsignedMsg, HTTPHeaderUserAddress,
HTTPHeaderExpires,
}

// getCanonicalHeaders generate a list of request headers with their values
Expand Down Expand Up @@ -86,8 +85,15 @@ func GetCanonicalRequest(req *http.Request, supportHeaders map[string]struct{})
// GetMsgToSign generate the msg bytes from canonicalRequest to sign
func GetMsgToSign(req *http.Request) []byte {
headers := initSupportHeaders()
ruojunm marked this conversation as resolved.
Show resolved Hide resolved
signBytes := hash.GenerateChecksum([]byte(GetCanonicalRequest(req, headers)))
return crypto.Keccak256(signBytes)
return crypto.Keccak256([]byte(GetCanonicalRequest(req, headers)))
}

// GetMsgToSignForPreSignedURL is only used in SP get Object API. This util method can be used in by SP side and client side to construct the MsgToSign
func GetMsgToSignForPreSignedURL(req *http.Request) []byte {
queryValues := req.URL.Query()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if len(queryValues) == 0 {
	return nil
}

queryValues.Del("Authorization")
ruojunm marked this conversation as resolved.
Show resolved Hide resolved
req.URL.RawQuery = queryValues.Encode()
return GetMsgToSign(req)
}

func initSupportHeaders() map[string]struct{} {
Expand Down