Ejemplo n.º 1
0
func promptPassphraseWithArg(g *libkb.GlobalContext, arg keybase1.GUIEntryArg, promptConfirm string) (keybase1.GetPassphraseRes, error) {
	prompter := newClientPrompter(g)

	firstPrompt := arg.Prompt

	for i := 0; i < 10; i++ {
		// get the first passphrase
		res, err := libkb.GetPassphraseUntilCheck(arg, prompter, &libkb.CheckPassphraseNew)
		if err != nil {
			return keybase1.GetPassphraseRes{}, err
		}

		// get confirmation passphrase
		arg.RetryLabel = ""
		arg.Prompt = promptConfirm
		confirm, err := libkb.GetPassphraseUntilCheck(arg, prompter, &libkb.CheckPassphraseNew)
		if err != nil {
			return keybase1.GetPassphraseRes{}, err
		}

		if res.Passphrase == confirm.Passphrase {
			// success
			return res, nil
		}

		// setup the prompt, label for new first attempt
		arg.Prompt = firstPrompt
		arg.RetryLabel = "Passphrase mismatch"
	}

	return keybase1.GetPassphraseRes{}, libkb.RetryExhaustedError{}
}
Ejemplo n.º 2
0
func GetPassphraseUntilCheck(arg keybase1.GUIEntryArg, prompter PassphrasePrompter, checker *Checker) (keybase1.GetPassphraseRes, error) {
	for i := 0; i < 10; i++ {
		res, err := prompter.Prompt(arg)
		if err != nil {
			return keybase1.GetPassphraseRes{}, err
		}
		if checker == nil {
			return res, nil
		}
		if checker.F(res.Passphrase) {
			return res, nil
		}
		arg.RetryLabel = checker.Hint
	}

	return keybase1.GetPassphraseRes{}, RetryExhaustedError{}
}
Ejemplo n.º 3
0
func GetPassphraseUntilCheck(g *GlobalContext, arg keybase1.GUIEntryArg, prompter PassphrasePrompter, checker PassphraseChecker) (keybase1.GetPassphraseRes, error) {
	for i := 0; i < 10; i++ {
		res, err := prompter.Prompt(arg)
		if err != nil {
			return keybase1.GetPassphraseRes{}, err
		}
		if checker == nil {
			return res, nil
		}
		err = checker.Check(g, res.Passphrase)
		if err == nil {
			return res, nil
		}
		arg.RetryLabel = err.Error()
	}

	return keybase1.GetPassphraseRes{}, RetryExhaustedError{}
}
Ejemplo n.º 4
0
func promptPassphraseWithArg(g *libkb.GlobalContext, arg keybase1.GUIEntryArg, promptConfirm string) (keybase1.GetPassphraseRes, error) {
	prompter := newClientPrompter(g)
	res, err := libkb.GetPassphraseUntilCheck(arg, prompter, &libkb.CheckPassphraseNew)
	if err != nil {
		return keybase1.GetPassphraseRes{}, err
	}

	// get confirmation
	match := &libkb.Checker{
		F: func(s string) bool {
			return s == res.Passphrase
		},
		Hint: "Passphrase mismatch",
	}
	arg.RetryLabel = ""
	arg.Prompt = promptConfirm
	_, err = libkb.GetPassphraseUntilCheck(arg, prompter, match)
	if err != nil {
		return keybase1.GetPassphraseRes{}, err
	}

	return res, nil
}