util

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2022 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Overview

Package util implements miscellaneous utility functions needed by the identity HTTP server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HTTPBadRequest

func HTTPBadRequest(w http.ResponseWriter, req *http.Request, err error)

HTTPBadRequest sends an HTTP 400 error on 'w' and renders a pretty page. If err is not nil, it also renders the string representation of err in the response page.

func HTTPServerError

func HTTPServerError(w http.ResponseWriter, err error)

ServerError sends an HTTP 500 error on 'w' and renders a pretty page that also has the string representation of err.

func RootCertificateDetails

func RootCertificateDetails(b security.Blessings) (string, []byte, error)

Circuitious route to obtain the certificate chain because the use of security.MarshalBlessings is discouraged.

func WriteCertAndKey

func WriteCertAndKey(host string, duration time.Duration) (string, string, error)

WriteCertAndKey creates a certificate and private key for a given host and duration and writes them to cert.pem and key.pem in tmpdir. It returns the locations of the files, or an error if one is encountered.

Types

type CSRFCop

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

CSRFCop implements utilities for generating and validating tokens for cross-site-request-forgery prevention (also called XSRF).

func NewCSRFCop

func NewCSRFCop(ctx *context.T) *CSRFCop

func (*CSRFCop) MaybeSetCookie

func (c *CSRFCop) MaybeSetCookie(w http.ResponseWriter, req *http.Request, cookieName string) ([]byte, error)

func (*CSRFCop) NewToken

func (c *CSRFCop) NewToken(w http.ResponseWriter, r *http.Request, cookieName string, data interface{}) (string, error)

NewToken creates an anti-cross-site-request-forgery, aka CSRF aka XSRF token with some data bound to it that can be obtained by ValidateToken. It returns an error if the token could not be created.

func (*CSRFCop) ValidateToken

func (c *CSRFCop) ValidateToken(token string, req *http.Request, cookieName string, decoded interface{}) error

ValidateToken checks the validity of the provided CSRF token for the provided request, and extracts the data encoded in the token into 'decoded'. If the token is invalid, return an error. This error should not be shown to end users, it is meant for the consumption by the server process only.

type Macaroon

type Macaroon string

Macaroon encapsulates an arbitrary slice of data signed with a Private Key. Term borrowed from http://research.google.com/pubs/pub41892.html.

func NewMacaroon

func NewMacaroon(principal security.Principal, data []byte) (Macaroon, error)

NewMacaroon creates an opaque token that encodes "data".

Input can be extracted from the returned token only if the Signature is valid.

func (Macaroon) Decode

func (m Macaroon) Decode(principal security.Principal) (input []byte, err error)

Decode returns the input if the macaroon was signed by the current principal.

type MacaroonMessage

type MacaroonMessage struct {
	Data []byte
	Sig  security.Signature
}

Jump to

Keyboard shortcuts

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