143 Commits

Author SHA1 Message Date
Yasuhiro Matsumoto
a21c5dde4c 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>
2017-11-24 09:08:02 +00:00
Tobias Klauser
a1a083ff5a terminal/ssh: use ioctl wrappers from x/sys/unix
Use the ioctl wrapper functions from x/sys/unix instead of manually
re-implementing them.

Change-Id: I224de0c6ec7439dfd8c45c72071c947be8813d6a
Reviewed-on: https://go-review.googlesource.com/75991
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-11-06 16:30:40 +00:00
Kevin Burke
aa45bf8df0 README: add links to useful resources
Move the README to README.md so Gerrit can render it; currently
Gerrit only renders files named exactly "README.md" (for example at
https://go.googlesource.com/go).

Add more links to the README explaining how to file issues,
how to submit code changes, where to download the code to and
how to get it. Hopefully this should help people who go to
https://go.googlesource.com/term or https://github.com/golang/term
figure out how to get started with development.

Change-Id: I8e1b1f1204f4c80acc5fd2cd28ab2efe4403c015
Reviewed-on: https://go-review.googlesource.com/49890
Reviewed-by: Kevin Burke <kev@inburke.com>
2017-09-27 05:45:33 +00:00
Tobias Klauser
5cd87de7cc ssh/terminal: set termios VMIN and VTIME in MakeRaw
The Solaris version of MakeRaw already sets VMIN and VTIME explicitly
such that a read returns when one character is available.
cfmakeraw (whose behavior MakeRaw replicate) in glibc and the BSD's libc
also set these values explicitly, so it should be done in the Linux/BSD
versions of MakeRaw as well to be consistent.

Change-Id: I531641ec87fd6a21b7a544b9a464bb90045b0bb1
Reviewed-on: https://go-review.googlesource.com/53570
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Avelino <t@avelino.xxx>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-08-18 13:51:34 +00:00
Tobias Klauser
073b14d8cc ssh/terminal: use console functions, types and consts from x/sys/windows
Use GetConsoleMode, SetConsoleMode and GetConsoleScreenBufferInfo and
the corresponding types and constants from golang.org/x/sys/windows
instead of locally defining them.

Change-Id: I69292a47114d071be261ffda6ca620a0b9820d00
Reviewed-on: https://go-review.googlesource.com/52990
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2017-08-04 07:50:21 +00:00
Tobias Klauser
d45e3a0228 ssh/terminal: use termios ioctl read/write constants from x/sys/unix
Use the TCGETS/TCSETS and TIOCGETA/TIOCSETA definitions from x/sys/unix
instead of manually declaring them or using the corresponding
definitions from syscall.

Change-Id: I37c2c8124d251eb47467b4184a7cc39781775f11
Reviewed-on: https://go-review.googlesource.com/51690
Reviewed-by: Matt Layher <mdlayher@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Matt Layher <mdlayher@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-07-28 18:30:02 +00:00
Rick Sayre
9d2f68fd6d ssh/terminal: implement missing functions for Solaris/OmniOS
terminal.MakeRaw
    terminal.Restore
    terminal.GetState
    terminal.GetSize

Fixes golang/go#20062

Change-Id: I9ccf194215998c5b80dbedc4f248b481f0ca57a6
Reviewed-on: https://go-review.googlesource.com/41297
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-04-21 04:31:20 +00:00
Adam Langley
efcab1a52e ssh/terminal: consume data before checking for an error.
According to the io.Reader docs, Alex had it right the first time. (See
discussion on https://golang.org/cl/25355.)

Change-Id: Ib6fb9dfb99009e034263574e82d7e9d4828df38f
Reviewed-on: https://go-review.googlesource.com/35242
TryBot-Result: Gobot Gobot <gobot@golang.org>
Run-TryBot: Adam Langley <agl@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Adam Langley <agl@golang.org>
2017-01-17 00:48:27 +00:00
Alex Brainman
038bd0bb6d ssh/terminal: fix line endings handling in ReadPassword
Fixes golang/go#16552

Change-Id: I18a9c9b42fe042c4871b3efb3f51bef7cca335d0
Reviewed-on: https://go-review.googlesource.com/25355
Reviewed-by: Adam Langley <alangley@gmail.com>
Reviewed-by: Adam Langley <agl@golang.org>
2017-01-16 17:16:45 +00:00
Peter Morjan
a5e02a7a6f ssh/terminal: consistent return value for Restore
This patch makes the Restore function return nil
on success to be consistent with other functions
like MakeRaw.

Change-Id: I81e63f568787dd88466a5bb30cb87c4c3be75a5c
Reviewed-on: https://go-review.googlesource.com/34952
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-01-07 18:00:30 +00:00
Joe Tsai
3acf1ca968 all: fix some vet warnings
Change-Id: I85c2912a6862c6c251450f2a0926ecd33a9fb8e7
Reviewed-on: https://go-review.googlesource.com/34815
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-01-04 23:09:04 +00:00
Mikio Hara
426ef97d77 ssh/terminal: fix a typo
Change-Id: Iafe2ebb6d37afd2a64aa72750a722d4860bb735e
Reviewed-on: https://go-review.googlesource.com/34535
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-12-19 06:01:35 +00:00
Adam Langley
3ea8c23763 x/crypto/ssh/terminal: replace \n with \r\n.
18e6eb769a made MakeRaw match C's behaviour. This included clearing the
OPOST flag, which means that one now needs to write \r\n for a newline,
otherwise the cursor doesn't move back to the beginning and the terminal
prints a staircase.

(Dear god, we're still emulating line printers.)

This change causes the terminal package to do the required
transformation.

Fixes golang/go#17364.

Change-Id: Ida15d3cf701a21eaa59161ab61b3ed4dee2ded46
Reviewed-on: https://go-review.googlesource.com/33902
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-12-07 22:17:40 +00:00
Fazal Majid
d7ffdd5ca2 ssh/terminal: implement ReadPassword and IsTerminal
Fixes golang/go#13085.

Change-Id: I2fcdd60e5e8db032d6fa3ce76198bdc7a63f3cf6
Reviewed-on: https://go-review.googlesource.com/16722
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2016-10-03 20:04:50 +00:00
Faiyaz Ahmed
18e6eb769a x/crypto/ssh/terminal: have MakeRaw mirror cfmakeraw.
Rather than guessing at which terminal flags should be set or cleared by
MakeRaw, this change tries to make it mirror the behaviour documented
for cfmakeraw() in the termios(3) manpage.

Fixes golang/go#15625

Change-Id: Icd6b18ffb57ea332147c8c9b25eac5e41eb0863a
Reviewed-on: https://go-review.googlesource.com/22964
Run-TryBot: Adam Langley <agl@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Faiyaz Ahmed <ahmedf@vmware.com>
Reviewed-by: Adam Langley <agl@golang.org>
2016-07-18 21:10:49 +00:00
Brad Fitzpatrick
fcc174f3e9 term: add a Go file to make the builders happy
Change-Id: I01ba8ed54557791bf780d5e0f5260a57f6393a3b
Reviewed-on: https://go-review.googlesource.com/24908
Reviewed-by: Quentin Smith <quentin@golang.org>
2016-07-13 20:15:19 +00:00
John Schnake
896bd7dad4 x/crypto/ssh/terminal: ensure windows MakeRaw returns previous state
The MakeRaw method should be returning the original state so that
it can be restored.  However, the current implementation is returning
the new, "raw" state.

Fixes golang/go#15155

Change-Id: I8e0b87229b7577544e1118fa4b95664d3a9cf5da
Reviewed-on: https://go-review.googlesource.com/21612
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-04-08 16:30:10 +00:00
John Schnake
caba55058b x/crypto/ssh/terminal: create stubs for plan9 methods
To facilitate testing of methods in other GOOSs we need plan9 to
be able to build and run the test without a errors due to
undefined methods.

Fixes golang/go#15195

Change-Id: Ida334676f92db6fb4652af3e3a9f6bc13a96052c
Reviewed-on: https://go-review.googlesource.com/21711
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
2016-04-08 15:58:03 +00:00
Andrew Gerrand
0d63f7188e initial commit 2015-11-18 15:07:36 +11:00
Derek Che
fd5a52a5d8 ssh/terminal: fix SetSize when nothing on current line
SetSize has a problem may cause the following ReadPassword setting
temporary prompt not working, when changing width the current
SetSize will call clearAndRepaintLinePlusNPrevious which would
print an old prompt whatever the current line has, causing a following
ReadPassword with temporary prompt not printing the different prompt.

When running code like this, the nt.SetSize prints a "> " as
prompt then the temporary "Password: " prompt would never show up.

```go
        oldState, err := terminal.MakeRaw(int(os.Stdin.Fd()))
        width, height, _ = terminal.GetSize(int(os.Stdin.Fd()))
        nt := terminal.NewTerminal(os.Stdin, "> ")
        nt.SetSize(width, height)
        password, err = nt.ReadPassword("Password: ")
```

the new test cases is to test SetSize with different terminal sizes,
either shrinking or expanding, a following ReadPassword should get the
correct temporary prompt.

Change-Id: I33d13b2c732997c0c88670d53545b8c0048b94b6
Reviewed-on: https://go-review.googlesource.com/1861
Reviewed-by: Adam Langley <agl@golang.org>
2014-12-19 22:48:49 +00:00
David Symonds
3c38914b08 crypto: add import comments.
Change-Id: I33240faf1b8620d0cd600de661928d8e422ebdbc
Reviewed-on: https://go-review.googlesource.com/1235
Reviewed-by: Andrew Gerrand <adg@golang.org>
2014-12-09 23:26:36 +00:00
Adam Langley
d037c2cd54 go.crypto/ssh/terminal: support bracketed paste mode.
Some terminals support a mode where pasted text is bracketed by escape sequences. This is very useful for terminal applications that otherwise have no good way to tell pastes and typed text apart.

This change allows applications to enable this mode and, if the terminal supports it, will suppress autocompletes during pastes and indicate to the caller that a line came entirely from pasted text.

LGTM=bradfitz
R=bradfitz
CC=golang-codereviews
https://golang.org/cl/171330043
2014-11-16 14:01:45 -08:00
Adam Langley
21bda07dd6 go.crypto/ssh/terminal: fix Home and End.
In my notes I had Home and End down as OH and OF. But that's nonsense, they are [H and ]F.
I never noticed before because I don't have Home and End keys on my keyboard.

LGTM=bradfitz
R=bradfitz
CC=golang-codereviews
https://golang.org/cl/172100043
2014-11-07 19:20:14 -08:00
Adam Langley
e82ff8040c go.crypto/ssh/terminal: remove \r from passwords on Windows.
Fixes golang/go#9040.

(Note: can't compile or test this one prior to committing.)

LGTM=iant, bradfitz
R=bradfitz, mathias.gumz, iant
CC=golang-codereviews
https://golang.org/cl/171000043
2014-11-04 10:58:06 -08:00
Adam Langley
2a0b1644c0 go.crypto/ssh/terminal: fix crash when terminal narrower than prompt.
Previously, if the current line was "empty", resizes wouldn't trigger
repaints. However, the line can be empty when the prompt is non-empty
and the code would then panic after a resize because the cursor position
was outside of the terminal.

LGTM=bradfitz
R=bradfitz
CC=golang-codereviews
https://golang.org/cl/158090043
2014-10-25 11:16:08 -07:00
Adam Langley
e0a9d256f7 go.crypto/ssh/terminal: better handling of window resizing.
There doesn't appear to be perfect behaviour for line editing
code in the face of terminal resizing. But this change works
pretty well on xterm and gnome-terminal and certainly a lot
better than it used to.

LGTM=bradfitz
R=bradfitz
CC=golang-codereviews
https://golang.org/cl/105580043
2014-08-01 11:22:47 -07:00
Dave Cheney
196543343b go.crypt/ssh/terminal: declare TCGETS, TCSETS constants locally.
Currently the ssh/terminal package cannot be compiled under gccgo. Even though gccgo may be running on linux, its syscall package is slightly different and does not contain these constants.

This proposal resolves the issue by declaring the two constants locally, as we've done for the *BSDs.

LGTM=hanwen, iant
R=hanwen, iant, gobot
CC=golang-codereviews
https://golang.org/cl/101670043
2014-07-07 10:24:36 +10:00
Adam Langley
d47901289b go.crypto/ssh/terminal: support ^U, ^D and ^L.
LGTM=bradfitz
R=bradfitz, marios.nikolaou
CC=golang-codereviews
https://golang.org/cl/92220043
2014-05-27 19:45:07 -07:00
Mikio Hara
ea2b43b38e go.crypto/ssh/terminal: add support for BSD variants
LGTM=agl
R=golang-codereviews, agl
CC=golang-codereviews
https://golang.org/cl/97850043
2014-05-05 12:07:22 -07:00
Adam Langley
d5f42d23b5 go.crypto/ssh: import gosshnew.
See https://groups.google.com/d/msg/Golang-nuts/AoVxQ4bB5XQ/i8kpMxdbVlEJ

R=hanwen
CC=golang-codereviews
https://golang.org/cl/86190043
2014-04-09 13:57:52 -07:00
Brad Fitzpatrick
218fdea9b7 undo CL 51690043 / abf8f8812575
Breaks FreeBSD build of subrepo for non-tip users.

««« original CL description
go.crypto/ssh/terminal: enable freebsd build

syscall.Termios, which was the only thing breaking the build, is
available in go tip now
(https://code.google.com/p/go/source/detail?r=873d664b00ec)

R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/51690043

»»»

R=golang-codereviews, dave
CC=golang-codereviews
https://golang.org/cl/51100044
2014-01-13 15:00:50 -08:00
Michael Gehring
1fcadde6c1 go.crypto/ssh/terminal: enable freebsd build
syscall.Termios, which was the only thing breaking the build, is
available in go tip now
(https://code.google.com/p/go/source/detail?r=873d664b00ec)

R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/51690043
2014-01-13 14:35:19 -08:00
Frithjof Schulze
879e955024 go.crypto/ssh/terminal: Allow ^A and ^E as synonyms for Home and End.
I understand that ssh/terminal can't implement everybodys
favorite keyboard shortcuts, but I think these are very
widespread. They exist not only in Emacs or Readline, but also
in Acme and Sam. Also they almost come for free.

R=golang-dev
CC=agl, golang-dev
https://golang.org/cl/13839047
2013-09-30 16:06:07 -04:00
Adam Langley
4986295c47 go.crypto/ssh/terminal: fix non-ASCII history.
The length of history buffer entries (which are stored as strings) was
being used as the number of runes. This was correct until ff9ce887b46b,
which allowed unicode entry, but can now cause a panic when editing
history that contains non-ASCII codepoints.

R=golang-dev, sfrithjof, r
CC=golang-dev
https://golang.org/cl/13255050
2013-09-15 12:48:02 -04:00
Adam Langley
1b08228a8a go.crypto/ssh/terminal: support Unicode entry.
Previously, terminal only supported ASCII characters. This change
alters some []byte to []rune so that the full range of Unicode is
supported. The only thing that doesn't appear to work correctly are
grapheme clusters as the code still assumes one rune per glyph. Still,
this change allows many more languages to work than did previously.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/13704043
2013-09-13 14:33:00 -04:00
Adam Langley
78276a84ee go.crypto/ssh/terminal: handle ^W, ^K and ^H
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/13207043
2013-08-28 07:36:04 -04:00
Adam Langley
89c74edf66 go.crypto/ssh/terminal: support Go 1.0.
For those still stuck on Go 1.0.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/11297043
2013-07-15 18:01:31 -04:00
Adam Langley
3293448389 go.crypto/ssh/terminal: don't save passwords in history.
The history buffer would recall previously entered lines: including passwords. With this change, lines entered while echo is disabled are no longer put into the history.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/10853043
2013-07-02 19:46:13 -04:00
Adam Langley
7d4f6f0986 ssh/terminal: support home, end, up and down keys.
R=golang-dev, dave
CC=golang-dev
https://golang.org/cl/9777043
2013-06-07 10:21:53 -04:00
Adam Langley
78f827c126 ssh/terminal: add darwin support.
terminal contains a number of utility functions that are currently only
implemented for Linux. Darwin uses different named constants for
getting and setting the terminal state so this change splits them off
as constants and defines them for each arch.

R=golang-dev, minux.ma
CC=golang-dev
https://golang.org/cl/7286043
2013-02-04 10:36:09 -05:00
Adam Langley
ae4bfd41ff ssh/terminal: add GetState and make ReadPassword work in raw mode.
GetState is useful for restoring the terminal in a signal handler.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6990043
2012-12-22 11:02:28 -05:00
Dave Cheney
24437a6651 go.crypto: various: fix appengine compatibility
Fixes golang/go#4102.

R=russross, minux.ma, rsc, agl
CC=golang-dev
https://golang.org/cl/6623053
2012-10-09 13:15:42 +11:00
David Symonds
34e6ae6050 go.crypto: add exp/terminal as code.google.com/p/go.crypto/ssh/terminal.
This removes the sole "exp/foo" import in the Go subrepos.
A separate CL will remove exp/terminal from the standard Go repository.

R=golang-dev, dave, r
CC=golang-dev
https://golang.org/cl/5966045
2012-03-30 15:27:01 +11:00