func main() { cloudy, _ := ioutil.ReadFile("cloudy") if cloudy != nil { fmt.Println(string(cloudy)) } login, err := speakeasy.Ask("enter your apple id: ") if err != nil { panic(err) } pass, err := speakeasy.Ask("enter your icloud pass: "******"root") if err != nil { panic(err) } fitems_links, err := drive.GetFileItemsUrls(fitems, eng, cookie, token) if err != nil { panic(err) } fmt.Println("================================================================") fmt.Println("================================================================") fmt.Println("================================================================") for i := range fitems_links.Items { fmt.Println("name: ", fitems.Items[i].Name) fmt.Println("type: ", fitems.Items[i].Type) fmt.Println("url: ", fitems.Items[i].Url) fmt.Println("id: ", fitems.Items[i].Id) } /* iclouddrive, err2 := drive.NewD(eng) if err2 != nil { panic(err2) } fmt.Println(iclouddrive.Urls) if err := photos.PrintContent(total); err != nil { panic(err) } if err := photos.DownloadContent(total); err != nil { panic(err) } */ }
// walletloadseedcmd adds a seed to the wallet's list of seeds func walletloadseedcmd() { password, err := speakeasy.Ask("Wallet password: "******"Reading password failed:", err) } seed, err := speakeasy.Ask("New Seed: ") if err != nil { die("Reading seed failed:", err) } qs := fmt.Sprintf("encryptionpassword=%s&seed=%s&dictionary=%s", password, seed, "english") err = post("/wallet/seed", qs) if err != nil { die("Could not add seed:", err) } fmt.Println("Added Key") }
func actionUserPasswd(c *cli.Context) { api, user := mustUserAPIAndName(c) ctx, cancel := context.WithTimeout(context.Background(), client.DefaultRequestTimeout) currentUser, err := api.GetUser(ctx, user) cancel() if currentUser == nil { fmt.Fprintln(os.Stderr, err.Error()) os.Exit(1) } pass, err := speakeasy.Ask("New password: "******"Error reading password:"******"Password updated\n") }
func preDecrypt(cmd *cobra.Command, args []string) { p := path.Dir(params.SettingsFile) diaryStore, err := ioutil.ReadFile(path.Join(p, "diary.md")) if err != nil { log.Printf("Unable to load stored diary") os.Exit(1) } tmp, err := ioutil.TempFile("", "diary") if err != nil { log.Printf("Unable to open a temp file") os.Exit(1) } tmpFile = tmp.Name() if set.Encrypt { pwd, err := speakeasy.Ask("Password: "******"Unable to read password.") os.Exit(1) } tmpPass = pwd if len(diaryStore) > 0 { o := openssl.New() diaryStore, err = o.DecryptString(tmpPass, string(diaryStore)) if err != nil { log.Printf("Unable to decrypt diary") os.Exit(1) } } } fmt.Fprintf(tmp, string(diaryStore)) tmp.Close() }
func authCfgFromCmd(cmd *cobra.Command) *authCfg { userFlag, err := cmd.Flags().GetString("user") if err != nil { ExitWithError(ExitBadArgs, err) } if userFlag == "" { return nil } var cfg authCfg splitted := strings.SplitN(userFlag, ":", 2) if len(splitted) < 2 { cfg.username = userFlag cfg.password, err = speakeasy.Ask("Password: ") if err != nil { ExitWithError(ExitError, err) } } else { cfg.username = splitted[0] cfg.password = splitted[1] } return &cfg }
func main() { prog := os.Args[0] if len(os.Args) != 3 { usage(prog) os.Exit(1) } verb := os.Args[1] object := os.Args[2] password, err := speakeasy.Ask("Password: "******"upload": upload(object, password) case "download": download(object, password) default: usage(prog) os.Exit(1) } }
// apiGet wraps a GET request with a status code check, such that if the GET does // not return 2xx, the error will be read and returned. The response body is // not closed. func apiGet(call string) (*http.Response, error) { if host, port, _ := net.SplitHostPort(addr); host == "" { addr = net.JoinHostPort("localhost", port) } resp, err := api.HttpGET("http://" + addr + call) if err != nil { return nil, errors.New("no response from daemon") } // check error code if resp.StatusCode == http.StatusUnauthorized { resp.Body.Close() // Prompt for password and retry request with authentication. password, err := speakeasy.Ask("API password: "******"http://"+addr+call, password) if err != nil { return nil, errors.New("no response from daemon - authentication failed") } } if resp.StatusCode == http.StatusNotFound { resp.Body.Close() return nil, errors.New("API call not recognized: " + call) } if non2xx(resp.StatusCode) { err := decodeError(resp) resp.Body.Close() return nil, err } return resp, nil }
func (l *login) populateCreds(e *env) error { if l.credentials.email != "" && l.credentials.password != "" { return nil } fmt.Fprint(e.Out, "Email: ") fmt.Fscanf(e.In, "%s\n", &l.credentials.email) var ( password string err error ) if e.In == os.Stdin { password, err = speakeasy.Ask("Password (will be hidden): ") if err != nil { return err } } else { // NOTE: only for testing fmt.Fscanf(e.In, "%s\n", &password) } if password != "" { l.credentials.password = password } return nil }
func runLogin(cmd *Command, args []string) { var endpoint ForceEndpoint = EndpointProduction currentEndpoint, customUrl, err := CurrentEndpoint() if err == nil && ¤tEndpoint != nil { endpoint = currentEndpoint if currentEndpoint == EndpointCustom && customUrl != "" { *instance = customUrl } } switch *instance { case "login": endpoint = EndpointProduction case "test": endpoint = EndpointTest case "pre": endpoint = EndpointPrerelease default: if *instance != "" { //need to determine the form of the endpoint uri, err := url.Parse(*instance) if err != nil { ErrorAndExit("no such endpoint: %s", *instance) } // Could be short hand? if uri.Host == "" { uri, err = url.Parse(fmt.Sprintf("https://%s", *instance)) //fmt.Println(uri) if err != nil { ErrorAndExit("no such endpoint: %s", *instance) } } CustomEndpoint = uri.Scheme + "://" + uri.Host endpoint = EndpointCustom fmt.Println("Loaded Endpoint: (" + CustomEndpoint + ")") } } if len(*userName) != 0 { // Do SOAP login if len(*password) == 0 { var err error *password, err = speakeasy.Ask("Password: ") if err != nil { ErrorAndExit(err.Error()) } } _, err := ForceLoginAndSaveSoap(endpoint, *userName, *password) if err != nil { ErrorAndExit(err.Error()) } } else { // Do OAuth login _, err := ForceLoginAndSave(endpoint) if err != nil { ErrorAndExit(err.Error()) } } }
func readPassword(prompt string) (password string, err error) { if acceptPasswordFromStdin && !isTerminalIn { _, err = fmt.Scanln(&password) return } // NOTE: speakeasy may not support multi-byte chars on Windows return speakeasy.Ask("Enter password: ") }
func getPassword(question string) string { password, err := speakeasy.Ask(fmt.Sprintf("%s", question)) if err != nil { fmt.Printf("\nERROR: %s\n", err.Error()) return getPassword(question) } return password }
func main() { password, err := speakeasy.Ask("Please enter a password: "******"Password result: %q\n", password) fmt.Printf("Password len: %d\n", len(password)) }
func (ctx *SecureContext) GetPassword() (string, error) { var password string var err error if password, err = speakeasy.Ask(DefaultPrompt); err != nil { return "", err } ctx.Password = password return ctx.Password, nil }
func (cred *Credentials) FetchPassWord() { // Grab password password, err := speakeasy.Ask("Enter password: ") if err != nil { log.Fatal(err) os.Exit(1) } cred.Password = password }
func main() { var ( secret string pin string err error nowStr string hash string ) secret, err = speakeasy.Ask("Secret (not echoed): ") if err != nil { fmt.Println(err.Error()) os.Exit(2) } pin, err = speakeasy.Ask("PIN (not echoed): ") if err != nil { fmt.Println(err.Error()) os.Exit(2) } c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt) go func() { for _ = range c { terminal.Stdout.Reset() os.Exit(3) } }() for { // 10-sec granularity nowStr = strconv.FormatInt(time.Now().Unix()/10, 10) hash = fmt.Sprintf("%x\n", md5.Sum([]byte(nowStr+secret+pin))) //fmt.Printf("OTP: %s\n", hash[:6]) refresh("OTP", hash[:6]) time.Sleep(10 * time.Second) } }
func loadPrivateKey(path string) (ssh.AuthMethod, error) { // Read file keyData, err := ioutil.ReadFile(path) if err != nil { log.Printf("error: could not read key file '%s': %s", path, err) return nil, err } // Get first PEM block block, _ := pem.Decode(keyData) if err != nil { log.Printf("error: no key found in file '%s': %s", path, err) return nil, err } // If it's encrypted... var ( signer ssh.Signer signerErr error ) if x509.IsEncryptedPEMBlock(block) { // Get the passphrase prompt := fmt.Sprintf("Enter passphrase for key '%s': ", path) pass, err := speakeasy.Ask(prompt) if err != nil { log.Printf("error: error getting passphrase: %s", err) return nil, err } block.Bytes, err = x509.DecryptPEMBlock(block, []byte(pass)) if err != nil { log.Printf("error: error decrypting key: %s", err) return nil, err } key, err := ParsePEMBlock(block) if err != nil { log.Printf("error: could not parse PEM block: %s", err) return nil, err } signer, signerErr = ssh.NewSignerFromKey(key) } else { signer, signerErr = ssh.ParsePrivateKey(keyData) } if signerErr != nil { log.Printf("error: error parsing private key '%s': %s", path, signerErr) return nil, signerErr } return ssh.PublicKeys(signer), nil }
// walletloadsiagcmd loads a siag key set into the wallet. func walletloadsiagcmd(keyfiles string) { password, err := speakeasy.Ask("Wallet password: "******"Reading password failed:", err) } qs := fmt.Sprintf("keyfiles=%s&encryptionpassword=%s", keyfiles, password) err = post("/wallet/siagkey", qs) if err != nil { die("Loading siag key failed:", err) } fmt.Println("Wallet loading successful.") }
// walletunlockcmd unlocks a saved wallet func walletunlockcmd() { password, err := speakeasy.Ask("Wallet password: "******"Reading password failed:", err) } qs := fmt.Sprintf("encryptionpassword=%s&dictonary=%s", password, "english") err = post("/wallet/unlock", qs) if err != nil { die("Could not unlock wallet:", err) } fmt.Println("Wallet unlocked") }
func getAccount(r io.Reader) (string, string, error) { scanner := bufio.NewScanner(r) for { fmt.Print("User: "******"Password: ") return username, password, err }
// walletload033xcmd loads a v0.3.3.x wallet into the current wallet. func walletload033xcmd(source string) { password, err := speakeasy.Ask("Wallet password: "******"Reading password failed:", err) } qs := fmt.Sprintf("source=%s&encryptionpassword=%s", abs(source), password) err = post("/wallet/033x", qs) if err != nil { die("Loading wallet failed:", err) } fmt.Println("Wallet loading successful.") }
func main() { var ( currentUser *user.User outFile string output string vpnUser string hash string otp string secret string pin string err error nowStr string ) currentUser, _ = user.Current() flag.StringVar(&vpnUser, "u", currentUser.Name, "OpenVPN user") flag.StringVar(&outFile, "o", "", "Output file path") flag.Parse() if outFile == "" { fmt.Println("Must provide output file path to write OTP to.") os.Exit(1) } if secret, err = speakeasy.Ask("Secret (not echoed): "); err != nil { fmt.Println(err.Error()) os.Exit(1) } if pin, err = speakeasy.Ask("PIN (not echoed): "); err != nil { fmt.Println(err.Error()) os.Exit(1) } nowStr = strconv.FormatInt(time.Now().Unix()/10, 10) hash = fmt.Sprintf("%x", md5.Sum([]byte(nowStr+secret+pin))) otp = hash[:6] output = fmt.Sprintf("%s\n%s", vpnUser, otp) ioutil.WriteFile(outFile, []byte(output), 0644) }
func registerUser(ctx *app.Context) { username := ctx.RequireIndexValue(0) userVal, _ := newEmptyUser(ctx) updating := false if ctx.Orm().MustOne(ByUsername(username), userVal.Interface()) { // Updating existing user updating = true } else { // Creating a new one userVal = newUser(ctx, username) } var askPassword bool ctx.ParseParamValue("p", &askPassword) if !updating || askPassword { password1, err := speakeasy.Ask("Password:"******"Confirm Password:"******"passwords don't match")) } setUserValue(userVal, "Password", password.New(password1)) } var admin bool ctx.ParseParamValue("s", &admin) setUserValue(userVal, "Admin", admin) var email string ctx.ParseParamValue("e", &email) if email != "" { setUserValue(userVal, "Email", email) } ctx.Orm().MustSave(userVal.Interface()) ctx.Logger().Infof("saved user as %+v", userVal.Interface()) }
func InputPassword() (passwd string, err error) { passwd, err = speakeasy.Ask("Enter password: "******"" { return passwd, errors.New("Empty password") } return passwd, err }
func makePassphraseFn(passphrase string, out *string) func() (string, error) { return func() (val string, err error) { if passphrase == "" { val, err = speakeasy.Ask("Passphrase: ") } else { val, err = passphrase, nil } if out != nil { *out = val } return val, err } }
// walletload033xcmd loads a v0.3.3.x wallet into the current wallet. func walletload033xcmd(filepath string) { password, err := speakeasy.Ask("Wallet password: "******"Reading password failed") return } qs := fmt.Sprintf("filepath=%s&encryptionpassword=%s", filepath, password) err = post("/wallet/load/033x", qs) if err != nil { fmt.Println("loading error:", err) return } fmt.Println("Wallet loading successful.") }
// walletloadsiagcmd loads a siag key set into the wallet. func walletloadsiagcmd(keyfiles string) { password, err := speakeasy.Ask("Wallet password: "******"Reading password failed") return } qs := fmt.Sprintf("keyfiles=%s&encryptionpassword=%s", keyfiles, password) err = post("/wallet/load/siag", qs) if err != nil { fmt.Println("loading error:", err) return } fmt.Println("Wallet loading successful.") }
func readPasswordInteractive(name string) string { prompt1 := fmt.Sprintf("Password of %s: ", name) password1, err1 := speakeasy.Ask(prompt1) if err1 != nil { ExitWithError(ExitBadArgs, fmt.Errorf("failed to ask password: %s.", err1)) } if len(password1) == 0 { ExitWithError(ExitBadArgs, fmt.Errorf("empty password")) } prompt2 := fmt.Sprintf("Type password of %s again for confirmation: ", name) password2, err2 := speakeasy.Ask(prompt2) if err2 != nil { ExitWithError(ExitBadArgs, fmt.Errorf("failed to ask password: %s.", err2)) } if strings.Compare(password1, password2) != 0 { ExitWithError(ExitBadArgs, fmt.Errorf("given passwords are different.")) } return password1 }
// userAddCommandFunc executes the "user add" command. func userAddCommandFunc(cmd *cobra.Command, args []string) { if len(args) != 1 { ExitWithError(ExitBadArgs, fmt.Errorf("user add command requires user name as its argument.")) } var password string if !passwordInteractive { fmt.Scanf("%s", &password) } else { prompt1 := fmt.Sprintf("Password of %s: ", args[0]) password1, err1 := speakeasy.Ask(prompt1) if err1 != nil { ExitWithError(ExitBadArgs, fmt.Errorf("failed to ask password: %s.", err1)) } if len(password1) == 0 { ExitWithError(ExitBadArgs, fmt.Errorf("empty password")) } prompt2 := fmt.Sprintf("Type password of %s again for confirmation: ", args[0]) password2, err2 := speakeasy.Ask(prompt2) if err2 != nil { ExitWithError(ExitBadArgs, fmt.Errorf("failed to ask password: %s.", err2)) } if strings.Compare(password1, password2) != 0 { ExitWithError(ExitBadArgs, fmt.Errorf("given passwords are different.")) } password = password1 } _, err := mustClientFromCmd(cmd).Auth.UserAdd(context.TODO(), args[0], password) if err != nil { ExitWithError(ExitError, err) } }
func getUsernamePassword(prompt, usernameFlag string) (username string, password string, err error) { colon := strings.Index(usernameFlag, ":") if colon == -1 { username = usernameFlag // Prompt for the password. password, err = speakeasy.Ask(prompt) if err != nil { return "", "", err } } else { username = usernameFlag[:colon] password = usernameFlag[colon+1:] } return username, password, nil }
func readParameter(reader *bufio.Reader, prompt string, private bool) string { var str string if stdinIsatty() { if private { str, _ = speakeasy.Ask(prompt) } else { fmt.Print(prompt) str, _ = reader.ReadString('\n') } } else { str, _ = reader.ReadString('\n') } return strings.TrimSpace(str) }