awssig

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package awssig signs AWS Signature Version 4 requests without an SDK dependency.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoCredentials = errors.New("aws: no credentials")

ErrNoCredentials means a request cannot be signed because a key pair is absent.

Functions

func CanonicalQuery

func CanonicalQuery(u *url.URL) (string, error)

CanonicalQuery renders a query exactly as AWS's signer does.

func Presign

func Presign(
	req *http.Request,
	creds Credentials,
	region, service string,
	expires time.Duration,
	now time.Time,
) (string, error)

Presign puts the whole signature in the query string, so a URL alone is the credential.

A DIFFERENT SIGNATURE FROM Sign, NOT A REARRANGEMENT OF ONE. The six X-Amz-* parameters are part of the canonical request rather than headers, the payload hash is the literal UNSIGNED-PAYLOAD rather than a digest, and only Host is signed -- a presigned URL is fetched by something billet does not control and cannot make send a particular header.

EXPIRY IS THE ONLY THING BOUNDING IT. Anyone holding the URL can fetch the object until it lapses, so callers pass the shortest window that covers the fetch and stage nothing behind one that a longer secret would protect.

func SHA256Hex

func SHA256Hex(body []byte) string

SHA256Hex returns the lowercase payload digest SigV4 uses.

func Sign

func Sign(
	req *http.Request,
	body []byte,
	creds Credentials,
	region, service string,
	now time.Time,
) error

Sign adds SigV4 headers for one AWS service and region.

Its output is exercised by the EC2 package's vector generated with AWS's own signer. Keeping services on this one implementation prevents a second reading of the signing specification from becoming a second security boundary.

Types

type Credentials

type Credentials struct {
	AccessKeyID     string
	SecretAccessKey string
	SessionToken    string
}

Credentials are the material SigV4 needs. Every rendering path redacts secrets.

func (Credentials) Format

func (c Credentials) Format(f fmt.State, _ rune)

Format catches every fmt verb.

func (Credentials) GoString

func (c Credentials) GoString() string

GoString covers %#v.

func (Credentials) LogValue

func (c Credentials) LogValue() slog.Value

LogValue is the slog-safe rendering.

func (Credentials) MarshalJSON

func (c Credentials) MarshalJSON() ([]byte, error)

MarshalJSON prevents structural serializers from exposing the secret fields.

func (Credentials) String

func (c Credentials) String() string

String renders only the diagnostic key identifier.

Jump to

Keyboard shortcuts

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