auth

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package auth computes the Authorization headers of the HTTP authentication schemes beyond Basic: AWS Signature Version 4, Digest, NTLM and Negotiate (SPNEGO). It only builds header values; the client sends them and runs the challenge exchanges.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoTicket = errors.New("negotiate: no Kerberos ticket (run kinit, or set KRB5CCNAME)")

ErrNoTicket reports that Negotiate has no Kerberos credentials to use.

Functions

func NTLMAuthenticate

func NTLMAuthenticate(values []string, user, password string) (string, error)

NTLMAuthenticate answers the server's Type-2 challenge among the WWW-Authenticate values with an NTLMv2 Type-3 message, for user ("DOMAIN\user", or a user alone) and password; both may be empty, as with curl's -u ":". The target name is not read, and no session key is exchanged, as curl does.

func NTLMNegotiate

func NTLMNegotiate() (string, error)

NTLMNegotiate returns the Authorization value that opens an NTLM exchange: the Type-1 message, with curl's flags and no domain or workstation.

func NewCnonce

func NewCnonce() string

NewCnonce returns a random client nonce.

Types

type Digest

type Digest struct {
	Realm, Nonce, Opaque, Algorithm string
	// QOP is the protection chosen among the offered ones: "auth",
	// "auth-int", or "" for none (RFC 2069).
	QOP string
	// UserHash asks for the hashed user name (RFC 7616).
	UserHash bool
}

Digest is a Digest challenge (RFC 7616) from a WWW-Authenticate header.

func ParseDigest

func ParseDigest(values []string) (*Digest, error)

ParseDigest reads the Digest challenge among WWW-Authenticate values.

func (*Digest) Authorization

func (d *Digest) Authorization(user, password, method, uri string, body []byte, cnonce string, nc int) string

Authorization returns the Authorization header value answering the challenge for a request (method, request-target uri, body), with client nonce cnonce and nonce count nc.

type Negotiator

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

Negotiator makes Negotiate (SPNEGO) tokens from the Kerberos credential cache (KRB5CCNAME, else the default file cache) and configuration (KRB5_CONFIG, else /etc/krb5.conf); service tickets are cached.

func NewNegotiator

func NewNegotiator() (*Negotiator, error)

NewNegotiator loads the configuration and the credential cache.

func (*Negotiator) Close

func (n *Negotiator) Close()

Close ends the Kerberos client.

func (*Negotiator) Token

func (n *Negotiator) Token(host string) (string, error)

Token returns the Authorization value of a request to host; the service principal is HTTP/host.

type SigV4

type SigV4 struct {
	Provider1, Provider2, Region, Service string
}

SigV4 is a parsed --aws-sigv4 value: provider1[:provider2[:region[:service]]], as curl reads it.

func ParseSigV4

func ParseSigV4(spec, host string) (SigV4, error)

ParseSigV4 reads spec; a missing region or service is taken from host (service.region.provider.tld, as curl infers them).

func (SigV4) Sign

func (s SigV4) Sign(r SigV4Request) []exchange.Header

Sign returns the headers to add to the request: the date (unless the request has its own x-<provider2>-date, which is used as is) and the content hash for S3, then Authorization.

type SigV4Request

type SigV4Request struct {
	Method string
	URL    *url.URL
	Host   string // the Host header sent
	// Headers are signed with Host and the date header, names lower-case.
	Headers []exchange.Header
	Body    []byte
	// AccessKey and SecretKey sign. A session token is a header of the
	// request (x-amz-security-token), signed with the others.
	AccessKey, SecretKey string
	Time                 time.Time
}

SigV4Request is what a signature covers.

Jump to

Keyboard shortcuts

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