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: terminal.ReadPassword doesn't work when using Bash for Windows (from Git installation) #34612

Open
Hades32 opened this issue Sep 30, 2019 · 7 comments
Labels
help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Milestone

Comments

@Hades32
Copy link

Hades32 commented Sep 30, 2019

What version of Go are you using (go version)?

$ go version
go version go1.12.5 windows/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\mrausc\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\mrausc\go
set GOPROXY=
set GORACE=
set GOROOT=C:\MyProgs\Go
set GOTMPDIR=
set GOTOOLDIR=C:\MyProgs\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=X:\swda\play\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\mrausc\AppData\Local\Temp\go-build325358090=/tmp/go-build -gno-record-gcc-switches

What did you do?

func main() {
	_, err := terminal.ReadPassword(int(os.Stdin.Fd()))
	fmt.Println(err)
}

What did you expect to see?

no echo of password

What did you see instead?

"The handle is invalid."

@gopherbot gopherbot added this to the Unreleased milestone Sep 30, 2019
@bcmills
Copy link
Contributor

bcmills commented Sep 30, 2019

CC @hanwen @FiloSottile

@bcmills bcmills added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 30, 2019
@Or-Geva
Copy link

Or-Geva commented Oct 27, 2019

I got the same issue.

@mattn
Copy link
Member

mattn commented Nov 10, 2019

Do you use third-party terminal application? If you use mintty, an application which use Windows Console APIs does not work. you must use winpty to run the application.

@EtienneM
Copy link

EtienneM commented Oct 7, 2022

We are facing the same issue but found out something slightly odd. First, we use the new golang.org/x/term package rather than x/crypto/ssh/terminal as mentioned in the title of this issue.

We face the same issue as described in this issue in Git Bash. The code is here: https://github.com/Scalingo/cli/blob/master/term/password.go#L13

But if we run Git Bash from within the terminal tab of VS Code, we no longer face the same issue, everything works as expected.

Does anyone know what is the difference between Git Bash and Git Bash inside VS Code?

@mattn
Copy link
Member

mattn commented Oct 7, 2022

I can't reproduce this. Windows 11 21H2 64Bit amd64.

@EtienneM
Copy link

EtienneM commented Oct 7, 2022

I uploaded the smallest example which reproduces the issue here: https://github.com/EtienneM/mwe_read_password/blob/master/main.go

I'm not exactly sure about what information may be needed. My OS version:

C:\Users\Administrator>systeminfo | findstr /B /C:"OS Name" /C:"OS Version"

OS Name:                   Microsoft Windows Server 2019 Datacenter
OS Version:                10.0.17763 N/A Build 17763

The Go version:

C:\Users\Administrator>go version
go version go1.19.2 windows/amd64

The golang.org/x/term version is:

$ cat go.mod | grep "golang.org/x/term"
require golang.org/x/term v0.0.0-20220919170432-7a66f970e087

With this example, in Git Bash in VS Code I can type a password and the output is:

$ go build && ./mwe.exe
<nil>

In Git Bash outside of VS Code, I can't type the password and immediately get the error:

$ go build && ./mwe.exe
The handle is invalid.

@sunshine69
Copy link

sunshine69 commented Oct 27, 2022

I hit this problem as well. Run on mingw64 shell - If I run on windows cmd then it works. It is both on window 8 and windows 10 at my work place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Projects
None yet
Development

No branches or pull requests

8 participants