Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/crypto/ssh/terminal: ReadPassword broken on windows #11914

Closed
Joshua-Anderson opened this issue Jul 29, 2015 · 3 comments
Closed

x/crypto/ssh/terminal: ReadPassword broken on windows #11914

Joshua-Anderson opened this issue Jul 29, 2015 · 3 comments

Comments

@Joshua-Anderson
Copy link

@Joshua-Anderson Joshua-Anderson commented Jul 29, 2015

On go1.4.2 windows/amd64 with golang.org/x/crypto/ssh/terminal revision 56474dfd625f18739b46f075b138fd0133717491.

ReadPassword seems to be broken.

Reproduction Case:

package main

import (
  "fmt"
  "golang.org/x/crypto/ssh/terminal"
)

func main() {
  fmt.Print("password: ")
  password, err := terminal.ReadPassword(0)

  if err != nil {
    fmt.Println(err)
  }

  fmt.Println(string(password))
}

When I run this code on Windows 10, ReadPassword() throws the following error: The handle is invalid.

The same code works on linux and osx.

@ianlancetaylor ianlancetaylor added this to the Unreleased milestone Jul 29, 2015
@ianlancetaylor ianlancetaylor changed the title x/tools/crypto/ssh/terminal: ReadPassword broken on windows x/crypto/ssh/terminal: ReadPassword broken on windows Jul 29, 2015
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jul 29, 2015

Does it work if you use terminal.ReadPassword(syscall.Stdin) ?

The fact that 0 == syscall.Stdin on Unix system does not mean that that holds true on Windows.

@Joshua-Anderson
Copy link
Author

@Joshua-Anderson Joshua-Anderson commented Jul 29, 2015

You're correct, I made the mistake of assuming that syscall.Stdin was 0 on windows. I never considered that it would be different on windows (silly windows), and the docs on stdin were a little misleading. Thank you for the clarification!

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Apr 14, 2020

A lightly edited note from @cadethacker:

There are actually two reason this might be caused.

The first is documented above and correct that the handle ids on Windows are not the same as Unix.

But the second reason is…. if you are using Cygwin/mintty/git-bash on Windows, those Windows shells are unable to reach down to the OS API, and will throw the exact same error of the “handle is invalid”.

This issue is not directly fixable and really not an issue with Go. If you switch to Powershell or even CMD then executing ReadPassword will work as expected. You may then switch back to your shell for all other commands that don’t invoke ReadPassword. If you must stay in Cygwin/minty/git-bash then take a look at https://github.com/rprichard/winpty project, it might solve your issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.