diff --git a/cmd/async/main.go b/cmd/async/main.go index e40caa4..91a2542 100644 --- a/cmd/async/main.go +++ b/cmd/async/main.go @@ -1,12 +1,15 @@ package main import ( + "bufio" "context" "flag" "fmt" + "io" "os" "os/signal" "path" + "strings" "syscall" "git.defalsify.org/vise.git/engine" @@ -186,11 +189,19 @@ func main() { os.Exit(1) } fmt.Println("") - _, err = fmt.Scanln(&rqs.Input) + in := bufio.NewReader(os.Stdin) + //_, err = fmt.Scanln(&rqs.Input) + s, err := in.ReadString('\n') if err != nil { + if err == io.EOF { + break + } logg.ErrorCtxf(ctx, "error in input", "err", err) fmt.Errorf("error in input: %v", err) os.Exit(1) } + rqs.Input = []byte{} + s = strings.TrimSpace(s) + rqs.Input = []byte(s) } } diff --git a/handlers/application/menuhandler.go b/handlers/application/menuhandler.go index 17acfe9..dc3326b 100644 --- a/handlers/application/menuhandler.go +++ b/handlers/application/menuhandler.go @@ -320,12 +320,16 @@ func (h *MenuHandlers) VerifyNewPin(ctx context.Context, sym string, input []byt return res, fmt.Errorf("missing session") } flag_valid_pin, _ := h.flagManager.GetFlag("flag_valid_pin") - pinInput := string(input) - // Validate that the PIN is a 4-digit number. - if pin.IsValidPIN(pinInput) { - res.FlagSet = append(res.FlagSet, flag_valid_pin) + if !h.st.Back() { + pinInput := string(input) + // Validate that the PIN is a 4-digit number. + if pin.IsValidPIN(pinInput) { + res.FlagSet = append(res.FlagSet, flag_valid_pin) + } else { + res.FlagReset = append(res.FlagReset, flag_valid_pin) + } } else { - res.FlagReset = append(res.FlagReset, flag_valid_pin) + res.FlagSet = append(res.FlagSet, flag_valid_pin) } return res, nil @@ -414,6 +418,11 @@ func (h *MenuHandlers) CheckBlockedNumPinMisMatch(ctx context.Context, sym strin if !ok { return res, fmt.Errorf("missing session") } + if h.st.Back() { + res.FlagReset = append(res.FlagReset, flag_pin_mismatch) + return res, nil + } + // Get blocked number from storage. store := h.userdataStore blockedNumber, err := store.ReadEntry(ctx, sessionId, storedb.DATA_BLOCKED_NUMBER) @@ -444,6 +453,11 @@ func (h *MenuHandlers) ConfirmPinChange(ctx context.Context, sym string, input [ } flag_pin_mismatch, _ := h.flagManager.GetFlag("flag_pin_mismatch") + if h.st.Back() { + res.FlagReset = append(res.FlagReset, flag_pin_mismatch) + return res, nil + } + store := h.userdataStore hashedTemporaryPin, err := store.ReadEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE) if err != nil { @@ -575,6 +589,11 @@ func (h *MenuHandlers) ValidateBlockedNumber(ctx context.Context, sym string, in if !ok { return res, fmt.Errorf("missing session") } + + if h.st.Back() { + res.FlagReset = append(res.FlagReset, flag_unregistered_number) + return res, nil + } blockedNumber := string(input) _, err = store.ReadEntry(ctx, blockedNumber, storedb.DATA_PUBLIC_KEY) if !phone.IsValidPhoneNumber(blockedNumber) { @@ -1213,7 +1232,9 @@ func (h *MenuHandlers) Authorize(ctx context.Context, sym string, input []byte) logg.ErrorCtxf(ctx, "failed to read AccountPin entry with", "key", storedb.DATA_ACCOUNT_PIN, "error", err) return res, err } - if len(input) == 4 { + str := string(input) + _, err = strconv.Atoi(str) + if len(input) == 4 && err == nil { if pin.VerifyPIN(string(AccountPin), string(input)) { if h.st.MatchFlag(flag_account_authorized, false) { res.FlagReset = append(res.FlagReset, flag_incorrect_pin) @@ -1231,7 +1252,7 @@ func (h *MenuHandlers) Authorize(ctx context.Context, sym string, input []byte) } } } else { - err := h.incrementIncorrectPINAttempts(ctx, sessionId) + err = h.incrementIncorrectPINAttempts(ctx, sessionId) if err != nil { return res, err } @@ -1248,11 +1269,13 @@ func (h *MenuHandlers) Authorize(ctx context.Context, sym string, input []byte) // Setback sets the flag_back_set flag when the navigation is back. func (h *MenuHandlers) SetBack(ctx context.Context, sym string, input []byte) (resource.Result, error) { var res resource.Result + flag_back_set, _ := h.flagManager.GetFlag("flag_back_set") //TODO: //Add check if the navigation is lateral nav instead of checking the input. if string(input) == "0" { - flag_back_set, _ := h.flagManager.GetFlag("flag_back_set") res.FlagSet = append(res.FlagSet, flag_back_set) + } else { + res.FlagReset = append(res.FlagReset, flag_back_set) } return res, nil } diff --git a/handlers/application/menuhandler_test.go b/handlers/application/menuhandler_test.go index 2e426aa..4e7ec0d 100644 --- a/handlers/application/menuhandler_test.go +++ b/handlers/application/menuhandler_test.go @@ -1843,12 +1843,14 @@ func TestVerifyNewPin(t *testing.T) { sessionId := "session123" fm, _ := NewFlagManager(flagsPath) + mockState := state.NewState(16) flag_valid_pin, _ := fm.GetFlag("flag_valid_pin") mockAccountService := new(mocks.MockAccountService) h := &MenuHandlers{ flagManager: fm, accountService: mockAccountService, + st: mockState, } ctx := context.WithValue(context.Background(), "SessionId", sessionId) @@ -1886,6 +1888,7 @@ func TestVerifyNewPin(t *testing.T) { func TestConfirmPin(t *testing.T) { sessionId := "session123" + mockState := state.NewState(16) ctx, store := InitializeTestStore(t) ctx = context.WithValue(ctx, "SessionId", sessionId) @@ -1896,6 +1899,7 @@ func TestConfirmPin(t *testing.T) { userdataStore: store, flagManager: fm, accountService: mockAccountService, + st: mockState, } tests := []struct { diff --git a/services/registration/confirm_others_new_pin.vis b/services/registration/confirm_others_new_pin.vis index 9132dc4..8409418 100644 --- a/services/registration/confirm_others_new_pin.vis +++ b/services/registration/confirm_others_new_pin.vis @@ -8,7 +8,7 @@ RELOAD save_others_temporary_pin MOUT back 0 HALT INCMP _ 0 -LOAD check_pin_mismatch 0 +LOAD check_pin_mismatch 6 RELOAD check_pin_mismatch CATCH others_pin_mismatch flag_pin_mismatch 1 INCMP pin_entry * diff --git a/services/registration/confirm_pin_change.vis b/services/registration/confirm_pin_change.vis index cf485a1..09b12f8 100644 --- a/services/registration/confirm_pin_change.vis +++ b/services/registration/confirm_pin_change.vis @@ -1,5 +1,7 @@ -CATCH invalid_pin flag_valid_pin 0 +LOAD confirm_pin_change 0 MOUT back 0 HALT INCMP _ 0 +RELOAD confirm_pin_change +CATCH pin_reset_mismatch flag_pin_mismatch 1 INCMP * pin_reset_success diff --git a/services/registration/enter_other_number.vis b/services/registration/enter_other_number.vis index 0957165..9447678 100644 --- a/services/registration/enter_other_number.vis +++ b/services/registration/enter_other_number.vis @@ -4,4 +4,7 @@ RELOAD reset_account_authorized MOUT back 0 HALT INCMP _ 0 +LOAD validate_blocked_number 6 +RELOAD validate_blocked_number +CATCH unregistered_number flag_unregistered_number 1 INCMP enter_others_new_pin * diff --git a/services/registration/enter_others_new_pin.vis b/services/registration/enter_others_new_pin.vis index 7711c97..3f8a5c6 100644 --- a/services/registration/enter_others_new_pin.vis +++ b/services/registration/enter_others_new_pin.vis @@ -1,6 +1,3 @@ -LOAD validate_blocked_number 6 -RELOAD validate_blocked_number -CATCH unregistered_number flag_unregistered_number 1 LOAD retrieve_blocked_number 0 RELOAD retrieve_blocked_number MAP retrieve_blocked_number diff --git a/services/registration/new_pin.vis b/services/registration/new_pin.vis index 29013a9..56705d7 100644 --- a/services/registration/new_pin.vis +++ b/services/registration/new_pin.vis @@ -1,13 +1,7 @@ -LOAD authorize_account 12 -RELOAD authorize_account -CATCH incorrect_pin flag_incorrect_pin 1 -CATCH old_pin flag_allow_update 0 MOUT back 0 HALT INCMP _ 0 -LOAD save_temporary_pin 6 -LOAD verify_new_pin 0 RELOAD save_temporary_pin RELOAD verify_new_pin +CATCH invalid_pin flag_valid_pin 0 INCMP * confirm_pin_change - diff --git a/services/registration/no_admin_privilege.vis b/services/registration/no_admin_privilege.vis index 3cf1e4c..a7f9c4d 100644 --- a/services/registration/no_admin_privilege.vis +++ b/services/registration/no_admin_privilege.vis @@ -1,5 +1,5 @@ MOUT quit 9 MOUT back 0 HALT -INCMP pin_management 0 +INCMP ^ 0 INCMP quit 9 diff --git a/services/registration/old_pin.vis b/services/registration/old_pin.vis index 1e99f4f..2addb56 100644 --- a/services/registration/old_pin.vis +++ b/services/registration/old_pin.vis @@ -1,7 +1,7 @@ -LOAD reset_allow_update 0 +RELOAD reset_incorrect MOUT back 0 HALT -RELOAD reset_allow_update INCMP _ 0 +RELOAD authorize_account +CATCH incorrect_pin flag_incorrect_pin 1 INCMP new_pin * - diff --git a/services/registration/pin_management.vis b/services/registration/pin_management.vis index 5eb7d5a..f7b7a81 100644 --- a/services/registration/pin_management.vis +++ b/services/registration/pin_management.vis @@ -1,8 +1,15 @@ +LOAD confirm_pin_change 7 +LOAD set_back 6 +LOAD authorize_account 5 +LOAD reset_allow_update 4 +LOAD verify_new_pin 2 +LOAD save_temporary_pin 1 +LOAD reset_incorrect 0 MOUT change_pin 1 MOUT reset_pin 2 MOUT back 0 HALT -INCMP my_account 0 +INCMP _ 0 INCMP old_pin 1 INCMP enter_other_number 2 INCMP . * diff --git a/services/registration/pin_reset_mismatch.vis b/services/registration/pin_reset_mismatch.vis index 5dc7e7c..78318f2 100644 --- a/services/registration/pin_reset_mismatch.vis +++ b/services/registration/pin_reset_mismatch.vis @@ -1,6 +1,6 @@ MOUT retry 1 MOUT quit 9 HALT -INCMP confirm_pin_change 1 +INCMP _ 1 INCMP quit 9 diff --git a/services/registration/pin_reset_result.vis b/services/registration/pin_reset_result.vis index 34b9789..de877e5 100644 --- a/services/registration/pin_reset_result.vis +++ b/services/registration/pin_reset_result.vis @@ -4,5 +4,5 @@ LOAD reset_others_pin 6 MOUT back 0 MOUT quit 9 HALT -INCMP pin_management 0 +INCMP ^ 0 INCMP quit 9 diff --git a/services/registration/pin_reset_success.vis b/services/registration/pin_reset_success.vis index 96dee73..537a511 100644 --- a/services/registration/pin_reset_success.vis +++ b/services/registration/pin_reset_success.vis @@ -1,6 +1,3 @@ -LOAD confirm_pin_change 0 -RELOAD confirm_pin_change -CATCH pin_reset_mismatch flag_pin_mismatch 1 MOUT back 0 MOUT quit 9 HALT diff --git a/services/registration/unregistered_number.vis b/services/registration/unregistered_number.vis index 0ff96be..c7ba24b 100644 --- a/services/registration/unregistered_number.vis +++ b/services/registration/unregistered_number.vis @@ -1,7 +1,8 @@ LOAD reset_unregistered_number 0 RELOAD reset_unregistered_number -MOUT back 0 +MOUT retry 1 MOUT quit 9 HALT -INCMP ^ 0 +INCMP _ 1 INCMP quit 9 +INCMP . *