ssh/terminal: handle non-ASCII characters when reading passwords

ReadPassword uses Windows ReadFile to read from console handle.
But ReadFile does not split input into UTF-8 characters, so ReadFile
only works when input is ASCII. Use os.File instead of Windows
ReadFile, because os.File reads console and parses it into UTF-8.

Fixes golang/go#22828

Change-Id: Ifeed3e8048b51f46706c28d4154a3e4b10111a3e
Reviewed-on: https://go-review.googlesource.com/79335
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/util_windows.go b/util_windows.go
index 60979cc..92944f3 100644
--- a/util_windows.go
+++ b/util_windows.go
@@ -17,6 +17,8 @@
 package terminal
 
 import (
+	"os"
+
 	"golang.org/x/sys/windows"
 )
 
@@ -71,13 +73,6 @@
 	return int(info.Size.X), int(info.Size.Y), nil
 }
 
-// passwordReader is an io.Reader that reads from a specific Windows HANDLE.
-type passwordReader int
-
-func (r passwordReader) Read(buf []byte) (int, error) {
-	return windows.Read(windows.Handle(r), buf)
-}
-
 // ReadPassword reads a line of input from a terminal without local echo.  This
 // is commonly used for inputting passwords and other sensitive data. The slice
 // returned does not include the \n.
@@ -98,5 +93,5 @@
 		windows.SetConsoleMode(windows.Handle(fd), old)
 	}()
 
-	return readPasswordLine(passwordReader(fd))
+	return readPasswordLine(os.NewFile(uintptr(fd), "stdin"))
 }