Documentation ¶
Overview ¶
Package util implements miscellaneous utility functions needed by the identity HTTP server.
Index ¶
- func HTTPBadRequest(w http.ResponseWriter, req *http.Request, err error)
- func HTTPServerError(w http.ResponseWriter, err error)
- func RootCertificateDetails(b security.Blessings) (string, []byte, error)
- func WriteCertAndKey(host string, duration time.Duration) (string, string, error)
- type CSRFCop
- func (c *CSRFCop) MaybeSetCookie(w http.ResponseWriter, req *http.Request, cookieName string) ([]byte, error)
- func (c *CSRFCop) NewToken(w http.ResponseWriter, r *http.Request, cookieName string, data interface{}) (string, error)
- func (c *CSRFCop) ValidateToken(token string, req *http.Request, cookieName string, decoded interface{}) error
- type Macaroon
- type MacaroonMessage
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 ¶
Circuitious route to obtain the certificate chain because the use of security.MarshalBlessings is discouraged.
func WriteCertAndKey ¶
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 (*CSRFCop) MaybeSetCookie ¶
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 ¶
NewMacaroon creates an opaque token that encodes "data".
Input can be extracted from the returned token only if the Signature is valid.