sign4

package module
v0.0.0-...-faa0b21 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2023 License: BSD-2-Clause Imports: 11 Imported by: 0

README

aws

aws related things

Documentation

Index

Constants

View Source
const (
	BasicDateFormat      = "20060102T150405Z"
	BasicDateFormatShort = "20060102"
)

BasicDateFormat and BasicDateFormatShort define aws-date format

Variables

This section is empty.

Functions

func AuthHeaderValue

func AuthHeaderValue(signature, accessKey, credentialScope, signedHeaders string) string

Get the finalized value for the "Authorization" header. The signature parameter is the output from SignStringToSign

func CanonicalHeaders

func CanonicalHeaders(r *http.Request, signedHeaders map[string]bool) string

CanonicalHeaders

func CanonicalQueryString

func CanonicalQueryString(r *http.Request) string

CanonicalQueryString

func CanonicalRequest

func CanonicalRequest(r *http.Request, signedHeaders map[string]bool) (string, error)

Build a CanonicalRequest from a regular request string

See http://docs.aws.amazon.com/general/latest/gr/sigv4-create-canonical-request.html CanonicalRequest =

HTTPRequestMethod + '\n' +
CanonicalURI + '\n' +
CanonicalQueryString + '\n' +
CanonicalHeaders + '\n' +
SignedHeaders + '\n' +
HexEncode(Hash(RequestPayload))

func CanonicalURI

func CanonicalURI(r *http.Request) string

CanonicalURI return request uri

func CredentialScope

func CredentialScope(t time.Time, regionName, serviceName string) string

Return the Credential Scope. See http://docs.aws.amazon.com/general/latest/gr/sigv4-create-string-to-sign.html

func GenerateSigningKey

func GenerateSigningKey(secretKey, regionName, serviceName string, t time.Time) ([]byte, error)

Generate a "signing key" to sign the "String To Sign". See http://docs.aws.amazon.com/general/latest/gr/sigv4-calculate-signature.html

func HexEncodeSHA256Hash

func HexEncodeSHA256Hash(body []byte) (string, error)

HexEncodeSHA256Hash return hexcode of sha256

func RequestPayload

func RequestPayload(r *http.Request) ([]byte, error)

RequestPayload

func SignStringToSign

func SignStringToSign(stringToSign string, signingKey []byte) (string, error)

Create the AWS Signature Version 4. See http://docs.aws.amazon.com/general/latest/gr/sigv4-calculate-signature.html

func SignedHeaders

func SignedHeaders(r *http.Request, signedHeaders map[string]bool) string

SignedHeaders

func StringToSign

func StringToSign(canonicalRequest, credentialScope string, t time.Time) string

Create a "String to Sign". See http://docs.aws.amazon.com/general/latest/gr/sigv4-create-string-to-sign.html

Types

type Signature

type Signature struct {
	AccessKey string
	SecretKey string
	Region    string
	Service   string
}

Signature AWS meta

func GetSignature

func GetSignature(r *http.Request) (*Signature, string, map[string]bool, error)

Authorization: AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-1/host/aws4_request, SignedHeaders=content-type;date;host, Signature=5a15b22cf462f047318703b92e6f4f38884e4a7ab7b1d6426ca46a8bd1c26cbc Authorization: AWS4-HMAC-SHA256 Credential=devops/20180312/hz/dnsapi/aws4_request,SignedHeaders=Content-Length;Content-type;host;x-amz-date,Signature=8a31f6aaa5026579bb2cf20962768190fdd0b4846ed5c48842fa61936245e9c5

func GetSignatureFromString

func GetSignatureFromString(authHeader string) (*Signature, string, map[string]bool, error)

func (*Signature) GetStringToSign

func (s *Signature) GetStringToSign(r *http.Request, signedHeaders map[string]bool) (*string, error)

func (*Signature) SignRequest

func (s *Signature) SignRequest(r *http.Request, signedHeaders map[string]bool) error

SignRequest set Authorization header

Jump to

Keyboard shortcuts

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