func init() { auth.AddMechanism("PLAIN", func(e *auth.AuthElement, stream stream.ServerStream) error { var auth_state *auth.AuthState if err := stream.State().Get(&auth_state); err != nil { return err } b, err := auth.DecodeBase64(e.Data, stream) if err != nil { return err } user_password := bytes.Split(b, usernamePasswordSeparator) if pass := auth_state.GetPasswordByUserName(string(user_password[1])); pass == string(user_password[2]) { if err := stream.WriteElement(mechanisms.SuccessElement{}); err != nil { return err } auth_state.UserName = string(user_password[1]) auth_state.Mechanism = "PLAIN" stream.ReOpen() return nil } else { return errors.New("AUTH FAILED") } }) }
func init() { auth.AddMechanism("SCRAM-SHA-1", func(e *auth.AuthElement, strm stream.ServerStream) error { var auth_state *auth.AuthState if err := strm.State().Get(&auth_state); err != nil { log.Println("SHAM-SHA-1 AuthState is not set can't get auth data") return err } auth_data, err := auth.DecodeBase64(e.Data, strm) if err != nil { return err } scram := scram.NewServer(sha1.New, nil) if err := scram.ParseClientFirst(auth_data); err != nil { return err } scram.SaltPassword([]byte(auth_state.GetPasswordByUserName(scram.UserName()))) handler := newSHAHandler(strm, scram, auth_state) return handler.Handle() }) }
func init() { auth.AddMechanism("DIGEST-MD5", func(e *auth.AuthElement, strm stream.ServerStream) error { handler, err := newDigestMD5Handler(strm) if err != nil { return err } return handler.Handle() }) }