func (app *Application) adminAuthToken() (string, error) { app.RLock() secret := app.config.WebSecret app.RUnlock() s := securecookie.New([]byte(secret), nil) return s.Encode(AuthTokenKey, AuthTokenValue) }
// checkAdminAuthToken checks admin connection token which Centrifugo returns after admin login func (app *Application) checkAdminAuthToken(token string) error { app.RLock() secret := app.config.WebSecret app.RUnlock() if secret == "" { logger.ERROR.Println("provide web_secret in configuration") return ErrUnauthorized } if token == "" { return ErrUnauthorized } s := securecookie.New([]byte(secret), nil) var val string err := s.Decode(AuthTokenKey, token, &val) if err != nil { return ErrUnauthorized } if val != AuthTokenValue { return ErrUnauthorized } return nil }
package main import ( "fmt" "io" "math/rand" "os" "reflect" "testing/quick" "github.com/shilkin/centrifugo/Godeps/_workspace/src/github.com/gorilla/securecookie" ) var hashKey = []byte("very-secret12345") var blockKey = []byte("a-lot-secret1234") var s = securecookie.New(hashKey, blockKey) type Cookie struct { B bool I int S string } func main() { var c Cookie t := reflect.TypeOf(c) rnd := rand.New(rand.NewSource(0)) for i := 0; i < 100; i++ { v, ok := quick.Value(t, rnd) if !ok { panic("couldn't generate value")