Documentation ¶
Index ¶
- Constants
- Variables
- func NewDefaultAuthChecker(token AuthToken) *defaultAuthChecker
- func NewDefaultAuthToken(authTokenName string, secret []byte) *defaultAuthToken
- func RegisterAuthenticator(name string, a Authenticator)
- func RegisterLocalHandler(name string, a LocalHandler)
- func SniProxy(keyStoreFile *string, keyStorePass *string, minTLSVer *uint, bindAddr *string, ...) (*http.Server, error)
- type AuthChecker
- type AuthToken
- type AuthTokenType
- type AuthenticatedPrincipal
- type Authenticator
- type DefaultAuthorizationErrorRedirectPathLocalHandler
- type DefaultAuthorizationFailedRedirectPathLocalHandler
- type HostMap
- type LocalHandler
- type MethodPathMap
- type ResponseFulfilledFlag
- type RouteMap
- type TokenSetter
Constants ¶
const ( //DefaultAuthTokenName is SniProxyAuth DefaultAuthTokenName = "SniProxyAuth" //DefaultAuthTokenEncryptionKeySize is 32 DefaultAuthTokenEncryptionKeySize = 32 //DefaultAuthTokenExpirationDurationInHours is 12 DefaultAuthTokenExpirationDurationInHours = 12 )
const ( //COOKIE is used when authtoken should be handled as a http Cookie. COOKIE defaultAuthTokenType = iota //HEADER is used when authtoken should be handled in a http header (mobile apps) HEADER //EITHER choose this when you are not sure where the authtoken needs to be handled. // It will put the authtoken both in the cookie and as a header in the response and // also checks both places to find the authtoken in subsequent requests EITHER )
const ( ECDSA = 1 RSA = 2 )
ECDSA, RSA and DSA declared as enums
Variables ¶
var ( //AuthorizationErrorRedirectPath is the path where all requests are redirected // that return authChecker errors AuthorizationErrorRedirectPath = "/authorizationError/" //AuthorizationFailedRedirectPath is the path where all requests are redirected // when authChecker has returned that the request was unauthorized AuthorizationFailedRedirectPath = "/requestUnauthorized/" )
var ( //DefaultAuthCheckerErr is returned when an unknown error occurs during authChecker run DefaultAuthCheckerErr = errors.New("Unknown Error occurred in DefaultAuthChecker") //DefaultAuthCheckerTokenMakerErr is returned when an error occurs during tokenMaker run DefaultAuthCheckerTokenMakerErr = errors.New("Error occurred while baking a token") //DefaultAuthCheckerTokenValidationErr is returned when an error occurs during token validation DefaultAuthCheckerTokenValidationErr = errors.New("Error occured while validating the token") //DefaultAuthCheckerTokenExpiredErr is returned when an authToken has expired its lifetime DefaultAuthCheckerTokenExpiredErr = errors.New("AuthToken has expired") )
var ( //ECDSAdefaultExists is a boolean that represents whether a ECDSA cert for the //default alias exists or not ECDSAdefaultExists = false //ECDSAdefault is used to hold ECDSA cert for default alias. Certs of default //alias are optimized to be grabbed this way instead of being part of certMap ECDSAdefault = &tls.Certificate{} //RSAdefaultExists is a boolean that represents whether a RSA cert for the //default alias exists or not RSAdefaultExists = false //RSAdefault is used to hold RSA cert for default alias. Certs of default //alias are optimized to be grabbed this way instead of being part of certMap RSAdefault = &tls.Certificate{} )
declaring pointers to point at default cert to optimize for seeking default
var ( //CiphersECDSA lists cipherSuite (as per http://www.iana.org/assignments/tls-parameters/tls-parameters.xml) //that allow for ECDSA signature based server authentication in TLS handshake CiphersECDSA = []uint16{ 0xC007, 0xC009, 0xC00A, 0xC023, 0xC02B, 0xC02C, 0xCCA9, 0xC02D, 0xC02E, 0xC024, 0xC025, 0xC026, 0xC008} //CiphersRSA lists cipherSuite (as per http://www.iana.org/assignments/tls-parameters/tls-parameters.xml) //that allow for RSA signature based server authentication in TLS handshake CiphersRSA = []uint16{ 0xc011, 0xc012, 0xc013, 0xc014, 0xc02f, 0xc030, 0xC027, 0x009C, 0x009D, 0x0035, 0x003C, 0xCCA8, 0x002F, 0x000A, 0x0005, 0x003C, 0xC027, 0xC028} )
var HopByHopHeaders = map[string]struct{}{
"Connection": {},
"Keep-Alive": {},
"Proxy-Authenticate": {},
"Proxy-Authorization": {},
"TE": {},
"Trailer": {},
"Transfer-Encoding": {},
"Upgrade": {},
}
Functions ¶
func NewDefaultAuthChecker ¶
func NewDefaultAuthChecker(token AuthToken) *defaultAuthChecker
NewDefaultAuthChecker function returns a new instance of defaultAuthChecker
func NewDefaultAuthToken ¶
NewDefaultAuthToken generates a defaultAuthToken. Empty value for authTokenName will default its value to the DefaultAuthTokenName whereas nil value for secret results in choosing a random and ephemeral secret that remains active only for as long as the memory lives
func RegisterAuthenticator ¶
func RegisterAuthenticator(name string, a Authenticator)
RegisterAuthenticator registers a new authenticator to the pool of authenticators available. Further, the main function of any consuming app should also declare a (non-referencing) import on the implementor package
func RegisterLocalHandler ¶
func RegisterLocalHandler(name string, a LocalHandler)
RegisterLocalHandler is a function for any new LocalHandler to be registered and be made available in the localHandlers map. Further, the main function of any consuming app should also declare a (non-referencing) import on the implementor package
Types ¶
type AuthChecker ¶
type AuthChecker interface { // CheckAuth function takes http.Request, http.ResponseWriter and the // authenticationScheme // Returns whether the request is authorized or not. // If the response had already been fulfilled in doing so, // the AuthChecker should return the responseFulfilled flag as True. CheckAuth(req *http.Request, rw http.ResponseWriter, authScheme string, tokenType string) (authorized bool, tokenSetter TokenSetter, responseFulfilledFlag bool, checkAuthError error) }
AuthChecker is an interface that implements the CheckAuth function. A default implementation is provided
type AuthToken ¶
type AuthToken interface { //Validate() function takes a token and the authScheme string arguments, // and returns whether the token is valid as a boolean, the AuthenticatedPrincipal // as a string and any error generated. Validate(encodedToken string, authScheme string) (validated bool, principal string, err error) //GetTokenName function should return the tokenName for the implementation of AuthToken GetTokenName() (tokenName string) //TokenMaker function takes the request, principal (userid) as a string, an expiry // parameter as time, authScheme as a string, an AuthTokenType implementation and returns // a token in the form of a string and any error generated. TokenMaker(r *http.Request, principal string, expiry time.Time, authScheme string, tokenType AuthTokenType) (token string, err error) }
AuthToken is a generic interface for implementations to satisfy as a stand-in for it.
type AuthTokenType ¶
type AuthTokenType interface { //Implementations of AuthTokenType should expose a String() function String() string }
AuthTokenType is a generic interface for implementations to satisfy as a stand-in for it.
type AuthenticatedPrincipal ¶
type AuthenticatedPrincipal string
AuthenticatedPrincipal is the principal ID of the authenticated caller
type Authenticator ¶
type Authenticator interface { //Authenticate and return the principal's identity, fulfill the request in the process if need be. //If the user could not be authenticated/authentication fails, set the authenticatedPrincipal to empty //If request is fulfilled while authenticating, set the ResponseFulfilledFlag as true else set as false. Authenticate(r *http.Request, w http.ResponseWriter) (AuthenticatedPrincipal, ResponseFulfilledFlag, error) }
Authenticator is a generic interface for implementations to satisfy as a stand-in for it.
type DefaultAuthorizationErrorRedirectPathLocalHandler ¶
type DefaultAuthorizationErrorRedirectPathLocalHandler struct { }
DefaultAuthorizationErrorRedirectPathLocalHandler to handle authorization errors
func (*DefaultAuthorizationErrorRedirectPathLocalHandler) Handle ¶
func (c *DefaultAuthorizationErrorRedirectPathLocalHandler) Handle(w http.ResponseWriter, r *http.Request)
Handle handles authorization errors by returning a forbidden status
type DefaultAuthorizationFailedRedirectPathLocalHandler ¶
type DefaultAuthorizationFailedRedirectPathLocalHandler struct { }
DefaultAuthorizationFailedRedirectPathLocalHandler to handle authorization failures
func (*DefaultAuthorizationFailedRedirectPathLocalHandler) Handle ¶
func (c *DefaultAuthorizationFailedRedirectPathLocalHandler) Handle(w http.ResponseWriter, r *http.Request)
Handle handles authorization failures and returns Unauthorized status
type HostMap ¶
type HostMap struct { Host string `json:"Host"` MethodPathMaps []MethodPathMap `json:"MethodPathMaps"` }
HostMap lists the MethodPathMaps to each Host
type LocalHandler ¶
type LocalHandler interface { //Handle handles the request and responds back on the writer Handle(w http.ResponseWriter, r *http.Request) }
LocalHandler is a generic interface for implementations to satisfy as a stand-in for it.
type MethodPathMap ¶
type MethodPathMap struct { Method string `json:"Method"` Path string `json:"Path"` Route []interface{} `json:"Route"` AuthenticatorScheme string `json:"AuthenticatorScheme"` TokenType string `json:"TokenType"` MaxRequestBodyBytes *int64 `json:"MaxRequestBodyBytes,omitempty"` }
MethodPathMap maps each inbound method+path combination to backend route
type ResponseFulfilledFlag ¶
type ResponseFulfilledFlag bool
ResponseFulfilledFlag is used to indicate to the callers if a request's response has been fulfilled during the function's run
type RouteMap ¶
type RouteMap struct {
Routes []HostMap `json:"Routes"`
}
RouteMap is a collection of HostMap called Routes
type TokenSetter ¶
type TokenSetter interface { //SetToken takes the responsewriter rw and a tokenType string that indicates //placement of the token in the response (cookie, header, etc) inferred from //routemap json. SetToken(rw http.ResponseWriter, r *http.Request, tokenType string) }
TokenSetter is a generic interface for implementations to satisfy as a stand-in for it.