Skip to content

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

Closed
@Joshua-Anderson

Description

@Joshua-Anderson

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.

Activity

added this to the Unreleased milestone on Jul 29, 2015
changed the title [-]x/tools/crypto/ssh/terminal: ReadPassword broken on windows[/-] [+]x/crypto/ssh/terminal: ReadPassword broken on windows[/+] on Jul 29, 2015
ianlancetaylor

ianlancetaylor commented on Jul 29, 2015

@ianlancetaylor
Contributor

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

Joshua-Anderson commented on Jul 29, 2015

@Joshua-Anderson
Author

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!

locked and limited conversation to collaborators on Aug 5, 2016
ianlancetaylor

ianlancetaylor commented on Apr 14, 2020

@ianlancetaylor
Contributor

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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ianlancetaylor@Joshua-Anderson@gopherbot

        Issue actions

          x/crypto/ssh/terminal: ReadPassword broken on windows · Issue #11914 · golang/go