signer

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessKeyStore

type AccessKeyStore interface {
	GetSecret(id string) (string, bool)
}

AccessKeyStore defines the interface of an access key store, which returns the corresponding secret when query by an id

type HeaderHoisting

type HeaderHoisting struct {
	AllowedPrefix    []string `yaml:"allowedPrefix" json:"allowedPrefix" jsonschema:"omitempty,uniqueItems=true"`
	DisallowedPrefix []string `yaml:"disallowedPrefix" json:"disallowedPrefix" jsonschema:"omitempty,uniqueItems=true"`
	Disallowed       []string `yaml:"disallowed" json:"disallowed" jsonschema:"omitempty,uniqueItems=true"`
	// contains filtered or unexported fields
}

HeaderHoisting defines which headers are allowed to be moved from header to query in presign: header with name has one of the allowed prefixes, but hasn't any disallowed prefixes and doesn't match any of disallowed names are allowed to be hoisted

type Literal

type Literal struct {
	// ScopeSuffix is the last part when build the credential scope.
	// Default: megaease_request
	ScopeSuffix string `yaml:"scopeSuffix" json:"scopeSuffix" jsonschema:"required"`

	// AlgorithmName is the query name of the signature algorithm
	// Default: X-Me-Algorithm
	AlgorithmName string `yaml:"algorithmName" json:"algorithmName" jsonschema:"required"`

	// AlgorithmName is the header/query value of the signature algorithm
	// Default: ME-HMAC-SHA256
	AlgorithmValue string `yaml:"algorithmValue" json:"alrithmValue" jsonschema:"required"`

	// SignedHeaders is the header/query headers of the signed headers
	// Default: X-Me-SignedHeaders
	SignedHeaders string `yaml:"signedHeaders" json:"signedHeaders" jsonschema:"required"`

	// Signature is the query name of the signature
	// Default: X-Me-Signature
	Signature string `yaml:"signature" json:"signature" jsonschema:"required"`

	// Date is the header/query name of request time
	// Default: X-Me-Date
	Date string `yaml:"date" json:"date" jsonschema:"required"`

	// Expires is the query name of expire duration
	// Default: X-Me-Expires
	Expires string `yaml:"expires" json:"expires" jsonschema:"required"`

	// Credential is the query name of credential
	// Default: X-Me-Credential
	Credential string `yaml:"credential" json:"credential" jsonschema:"required"`

	// ContentSHA256 is the header name of body/payload hash
	// Default: X-Me-Content-Sha256
	ContentSHA256 string `yaml:"contentSha256" json:"contentSha256" jsonschema:"required"`

	// SigningKeyPrefix is prepend to access key secret when derive the signing key
	// Default: ME
	SigningKeyPrefix string `yaml:"signingKeyPrefix" json:"signingKeyPrefix" jsonschema:"omitempty"`
}

Literal is the header name, query name and other text values. The literals are string constants, but customers may want to customize them to be their own, so we make them configurable.

type Signer

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

Signer is a signature calculator for http.Request

func CreateFromSpec

func CreateFromSpec(spec *Spec) *Signer

CreateFromSpec create a Signer from configuration

func New

func New() *Signer

New creates a new signer

func (*Signer) ExcludeBody

func (signer *Signer) ExcludeBody(exclude bool) *Signer

ExcludeBody is an option function for Signer to exclude body from signature

func (*Signer) IgnoreHeader

func (signer *Signer) IgnoreHeader(headers ...string) *Signer

IgnoreHeader is an option function for Signer to add ignored headers

func (*Signer) NewContext

func (signer *Signer) NewContext(timestamp time.Time, scopes ...string) *SigningContext

NewContext creates a new signing context for signing

func (*Signer) SetAccessKeyStore

func (signer *Signer) SetAccessKeyStore(store AccessKeyStore) *Signer

SetAccessKeyStore is an option function for Signer to set access key store

func (*Signer) SetCredential

func (signer *Signer) SetCredential(accessKeyID string, accessKeySecret string) *Signer

SetCredential is an option function for Signer to set access key id/secret for signing

func (*Signer) SetHeaderHoisting

func (signer *Signer) SetHeaderHoisting(hh *HeaderHoisting) *Signer

SetHeaderHoisting is an option function for Singer to set header hoisting

func (*Signer) SetLiteral

func (signer *Signer) SetLiteral(literal *Literal) *Signer

SetLiteral is an option function for Signer to set literals

func (*Signer) SetTTL

func (signer *Signer) SetTTL(d time.Duration) *Signer

SetTTL is an option function for Signer to set time to live of a signature

func (*Signer) Verify

func (signer *Signer) Verify(req *http.Request) error

Verify verifies the signature of a request

type SigningContext

type SigningContext struct {
	*Signer

	Time   time.Time
	Scopes []string

	ExpireTime time.Duration

	AccessKeyID      string
	AccessKeySecret  string
	SignedHeaders    string
	CanonicalHeaders string

	Signature string
	Query     url.Values
	BodyHash  string
	// contains filtered or unexported fields
}

SigningContext is the signing context for a single request

func (*SigningContext) Presign

func (ctx *SigningContext) Presign(req *http.Request, expireTime time.Duration) error

Presign calculate the signature and add it to request url

func (*SigningContext) Sign

func (ctx *SigningContext) Sign(req *http.Request) error

Sign calculate the signature and add it to request header

type Spec

type Spec struct {
	Literal         *Literal          `yaml:"literial,omitempty" json:"literial,omitempty" jsonschema:"omitempty"`
	HeaderHoisting  *HeaderHoisting   `yaml:"headerHoisting,omitempty" json:"headerHoisting,omitempty" jsonschema:"omitempty"`
	IgnoredHeaders  []string          `yaml:"ignoredHeaders" json:"ignoredHeaders" jsonschema:"omitempty,uniqueItems=true"`
	ExcludeBody     bool              `yaml:"excludeBody" json:"excludeBody" jsonschema:"omitempty"`
	TTL             string            `yaml:"ttl" json:"ttl" jsonschema:"omitempty,format=duration"`
	AccessKeyID     string            `yaml:"accessKeyId" json:"accessKeyId" jsonschema:"omitempty"`
	AccessKeySecret string            `yaml:"accessKeySecret" json:"accessKeySecret" jsonschema:"omitempty"`
	AccessKeys      map[string]string `yaml:"accessKeys" json:"accessKeys" jsonschema:"omitempty"`
}

Spec defines the configuration of a Signer

Jump to

Keyboard shortcuts

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