utils

package
v0.0.0-...-936ba1f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HashTypeMd5 generates MD5 checksum for the data stream
	HashTypeMd5 = "md5"
	// HashTypeSha256 generates SHA256 checksum for the data stream
	HashTypeSha256 = "sha256"
	// HashTypeNone is a no-op checksum for the data stream
	HashTypeNone = "none"
)

Variables

This section is empty.

Functions

func CheckPresignedSignature

func CheckPresignedSignature(ctx *fiber.Ctx, auth AuthData, secret string, debug bool) error

CheckPresignedSignature validates presigned request signature

func CheckValidSignature

func CheckValidSignature(ctx *fiber.Ctx, auth AuthData, secret, checksum string, tdate time.Time, contentLen int64, debug bool) error

CheckValidSignature validates the ctx v4 auth signature

func GetUserMetaData

func GetUserMetaData(headers *fasthttp.RequestHeader) (metadata map[string]string)

func IsBigDataAction

func IsBigDataAction(ctx *fiber.Ctx) bool

func IsSpecialPayload

func IsSpecialPayload(str string) bool

IsSpecialPayload checks for streaming/unsigned authorization types

func IsValidBucketName

func IsValidBucketName(bucket string) bool

func LogCtxDetails

func LogCtxDetails(ctx *fiber.Ctx, respBody []byte)

func Md5SumString

func Md5SumString(b []byte) string

Md5SumString converts the hash bytes to the string checksum value

func ParseUint

func ParseUint(str string) (int32, error)

func SetMetaHeaders

func SetMetaHeaders(ctx *fiber.Ctx, meta map[string]string)

func SetResponseHeaders

func SetResponseHeaders(ctx *fiber.Ctx, headers []CustomHeader)

func ValidateDate

func ValidateDate(date time.Time) error

Types

type AuthData

type AuthData struct {
	Algorithm     string
	Access        string
	Region        string
	SignedHeaders string
	Signature     string
	Date          string
}

AuthData is the parsed authorization data from the header

func ParseAuthorization

func ParseAuthorization(authorization string) (AuthData, error)

ParseAuthorization returns the parsed fields for the aws v4 auth header example authorization string from aws docs: Authorization: AWS4-HMAC-SHA256 Credential=AKIAIOSFODNN7EXAMPLE/20130524/us-east-1/s3/aws4_request, SignedHeaders=host;range;x-amz-date, Signature=fe5f80f77d5fa3beca038a248ff027d0445342fe2855ddc963176630326f1024

func ParsePresignedURIParts

func ParsePresignedURIParts(ctx *fiber.Ctx) (AuthData, error)

https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-query-string-auth.html

ParsePresignedURIParts parses and validates request URL query parameters

?X-Amz-Algorithm=AWS4-HMAC-SHA256 &X-Amz-Credential=access-key-id/20130721/us-east-1/s3/aws4_request &X-Amz-Date=20130721T201207Z &X-Amz-Expires=86400 &X-Amz-SignedHeaders=host &X-Amz-Signature=1e68ad45c1db540284a4a1eca3884c293ba1a0ff63ab9db9a15b5b29dfa02cd8

type AuthReader

type AuthReader struct {
	// contains filtered or unexported fields
}

AuthReader is an io.Reader that validates the request authorization once the underlying reader returns io.EOF. This is needed for streaming data requests where the data size and checksum are not known until the data is completely read.

func NewAuthReader

func NewAuthReader(ctx *fiber.Ctx, r io.Reader, auth AuthData, secret string, debug bool) *AuthReader

NewAuthReader initializes an io.Reader that will verify the request v4 auth when the underlying reader returns io.EOF. This postpones the authorization check until the reader is consumed. So it is important that the consumer of this reader checks for the auth errors while reading.

func (*AuthReader) Read

func (ar *AuthReader) Read(p []byte) (int, error)

Read allows *AuthReader to be used as an io.Reader

type ChunkReader

type ChunkReader struct {
	// contains filtered or unexported fields
}

ChunkReader reads from chunked upload request body, and returns object data stream

func NewChunkReader

func NewChunkReader(ctx *fiber.Ctx, r io.Reader, authdata AuthData, region, secret string, date time.Time) (*ChunkReader, error)

NewChunkReader reads from request body io.Reader and parses out the chunk metadata in stream. The headers are validated for proper signatures. Reading from the chunk reader will read only the object data stream without the chunk headers/trailers.

func (*ChunkReader) Read

func (cr *ChunkReader) Read(p []byte) (int, error)

Read satisfies the io.Reader for this type

type CustomHeader

type CustomHeader struct {
	Key   string
	Value string
}

type HashReader

type HashReader struct {
	// contains filtered or unexported fields
}

HashReader is an io.Reader that calculates the checksum as the data is read

func NewHashReader

func NewHashReader(r io.Reader, expectedSum string, ht HashType) (*HashReader, error)

NewHashReader intializes an io.Reader from an underlying io.Reader that calculates the checksum while the reader is being read from. If the sum provided is not "", the reader will return an error when the underlying reader returns io.EOF if the checksum does not match the provided expected checksum. If the provided sum is "", then the Sum() method can still be used to get the current checksum for the data read so far.

func (*HashReader) Read

func (hr *HashReader) Read(p []byte) (int, error)

Read allows *HashReader to be used as an io.Reader

func (*HashReader) Sum

func (hr *HashReader) Sum() string

Sum returns the checksum hash of the data read so far

type HashType

type HashType string

HashType identifies the checksum algorithm to be used

type PresignedAuthReader

type PresignedAuthReader struct {
	// contains filtered or unexported fields
}

PresignedAuthReader is an io.Reader that validates presigned request authorization once the underlying reader returns io.EOF. This is needed for streaming data requests where the data size is not known until the data is completely read.

func NewPresignedAuthReader

func NewPresignedAuthReader(ctx *fiber.Ctx, r io.Reader, auth AuthData, secret string, debug bool) *PresignedAuthReader

func (*PresignedAuthReader) Read

func (pr *PresignedAuthReader) Read(p []byte) (int, error)

Read allows *PresignedAuthReader to be used as an io.Reader

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL