Beispiel #1
0
func (verification *Verification) Run() error {
	utils.PrintMessage("Sending approval request to your device... ")
	request, err := verification.SendOneTouchRequest()
	if err != nil {
		utils.PrintMessage(err.Error())
		return ErrInvalidVerification
	}

	utils.PrintMessage(ansi.Color("[sent]\n", "green+h"))
	status, err := verification.api.WaitForApprovalRequest(request.UUID, ApprovalTimeout, url.Values{})
	if err != nil {
		utils.PrintMessage(err.Error())
		return ErrInvalidVerification
	}

	if status == authy.OneTouchStatusApproved {
		runShell()
		return nil
	}

	if status == authy.OneTouchStatusExpired && utils.IsInteractiveConnection() {
		utils.PrintMessage("You didn't confirm the request. ")

		code := verification.askTOTPCode()
		if verification.verifyCode(code) {
			runShell()
			return nil
		}
	}

	return ErrInvalidVerification
}
Beispiel #2
0
import (
	"os"

	"github.com/dcu/onetouch-ssh/ssh"
	"github.com/dcu/onetouch-ssh/utils"
	"github.com/spf13/cobra"
)

// shellCmd represents the shell command
var shellCmd = &cobra.Command{
	Use:   "shell <authy id>",
	Short: "Runs a shell if approved with OneTouch",
	Long:  `When invoked this command sends a OneTouch request to the user.`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) != 1 {
			if utils.IsInteractiveConnection() {
				cmd.Help()
			}
			os.Exit(1)
		}

		authyID := args[0]

		verification := ssh.NewVerification(authyID)
		err := verification.Run()
		if err != nil {
			os.Exit(1)
		}
	},
}