digest

package
v0.0.0-...-cffc47d Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: Apache-2.0 Imports: 16 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilTransport      = errors.New("transport is nil")
	ErrBadChallenge      = errors.New("challenge is bad")
	ErrAlgNotImplemented = errors.New("alg not implemented")
	ErrQopNotSupported   = errors.New("qop not supported")

	// The Algs supported by this digester
	Algs = map[string]func() hash.Hash{
		"":            md5.New,
		"MD5":         md5.New,
		"SHA-256":     sha256.New,
		"SHA-512":     sha512.New,
		"SHA-512-256": sha512.New512_256,
	}
	QopFirst = func(qops []string) string {
		for _, qop := range qops {
			return qop
		}
		return ""
	}
	Cnoncer16 = func() (string, error) {
		b := make([]byte, 16)
		_, err := io.ReadFull(rand.Reader, b)
		return hex.EncodeToString(b), err
	}
)

Functions

func DefaultHTTPTransport

func DefaultHTTPTransport() *http.Transport

NewHTTPTransport ...

Types

type Challenge

type Challenge struct {
	Scheme    string
	Realm     string
	Domain    string
	Nonce     string
	Opaque    string
	Stale     string
	Algorithm string
	Qop       []string
	Charset   string
	Userhash  string
}

Challenge is the digest response www-authenticate header parsed (rfc 7616)

func NewChallenge

func NewChallenge(wwwAuth string) (*Challenge, error)

NewChallenge parses the www-authenticate header

type Cnoncer

type Cnoncer func() (string, error)

Cnoncer generates a cnonce

type Credentials

type Credentials struct {
	// our creds
	Username string
	Password string

	// from the challenge
	Realm      string
	Nonce      string
	NonceCount int // times we've responded to this nonce
	Opaque     string
	Qop        string // the chosen auth from the server list
	Algorithm  string // <alg>-sess implies session-keying ()

	// session-keying
	CnoncePrime string
	NoncePrime  string

	// per response
	Method string
	URI    string
	Body   string // used for auth-int
	Cnonce string
}

Credentials holds the per request response params

func (*Credentials) Authorization

func (c *Credentials) Authorization() (string, error)

func (*Credentials) Hasher

func (c *Credentials) Hasher() Hasher

type Hasher

type Hasher func(string) string

type QopPref

type QopPref func([]string) string

OopPref prefs implemented

type Transport

type Transport struct {
	Username  string
	Password  string
	Transport http.RoundTripper

	// NoncePrime is for session keying 'MD5-sess'
	NoncePrime string
	// CnoncePrime is for session keying 'MD5-sess'
	CnoncePrime string
	// NonCounter tracks the count of all nonces we've sent a request for
	NonceCounter map[string]int
	// QopPref provides a seem for qop selection
	QopPref QopPref
	// Cnoncer provides a seem for cnonce generation
	Cnoncer Cnoncer
	// contains filtered or unexported fields
}

Transport is an implementation of http.RoundTripper that takes care of http digest authentication.

func NewTransport

func NewTransport(username, password string, transport http.RoundTripper) *Transport

NewTransport creates a new digest transport using the http.DefaultTransport.

func (*Transport) Increment

func (t *Transport) Increment(nonce string) int

Increment tracks the count of the given nonce

func (*Transport) NewCredentials

func (t *Transport) NewCredentials(method, uri, body, cnonce string, c *Challenge) *Credentials

NewCredentials ...

func (*Transport) NewHTTPClient

func (t *Transport) NewHTTPClient() (*http.Client, error)

NewHTTPClient returns an HTTP client that uses the digest transport.

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip sends our request and intercepts a 401

Jump to

Keyboard shortcuts

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