Commit Graph
401 Commits
Author SHA1 Message Date
Russ Cox 5ea612d1eb all: go fmt ./...
Make all our package sources use Go 1.17 gofmt format
(adding //go:build lines).

Not strictly necessary but will avoid spurious changes
as files are edited.

Part of //go:build change (#41184).
See https://golang.org/design/draft-gobuild

Change-Id: I70526bf588bf4078887e567795867ece785d666b
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/294415
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-02-20 03:31:48 +00:00
Roland Shoemaker 8b5274cf68 ssh: disallow gssapi-with-mic if GSSAPIWithMICConfig is not set
The ability to trigger the 'gssapi-with-mic' authentication method is
not properly gated by the presence of the GSSAPIWithMICConfig field of
the ServerConfig type. If this field is not set and a client sends a
'gssapi-with-mic' request, regardless of if the server advertises it,
the server will panic.

This issue was discovered and reported by Joern Schneewesiz, GitLab
Security Research Team.

Fixes CVE-2020-29652

Change-Id: Ie25de2766e442c8ab46680aae3ac89b0823cdeed
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/278852
Trust: Roland Shoemaker <roland@golang.org>
Run-TryBot: Roland Shoemaker <roland@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2020-12-16 22:30:49 +00:00
Filippo Valsorda 4be66e5b65 ssh/terminal: replace with a golang.org/x/term wrapper
The package moved to x/term in CL 258001.

Fixes golang/go#31044

Change-Id: I9d39bfb6f54f09de60e2669fb0d939968af79b40
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/258003
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Katie Hockman <katie@golang.org>
Trust: Filippo Valsorda <filippo@golang.org>
2020-11-16 15:36:03 +00:00
Mahdi Hosseini Moghaddam 0c6587e931 ssh/terminal: add support for zos
Fixes golang/go#42496

Change-Id: Iae2ddb916904d9b3947bec9638c9fbf892df7b7c
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/269177
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Trust: Michael Munday <mike.munday@ibm.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
2020-11-12 15:50:50 +00:00
Aidan Coyle 9e8e0b3908 ssh: improve error message for KeyboardInteractiveChallenge
Fixes golang/go#41823

Change-Id: I4653f23239bdf2ab472d3d15c6653b89ebf7ccd4
GitHub-Last-Rev: 179b3ee0efc7b4733da9fbbd8e5ec73a72ef8156
GitHub-Pull-Request: golang/crypto#158
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/259902
Trust: Roland Shoemaker <roland@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2020-10-16 22:06:09 +00:00
Emmanuel T Odeke 84dcc777aa crypto/ssh: add Client.Close in Dial example
Fixes golang/go#41906

Change-Id: I2eee82160a4450f531f11d5ba7bd6ed19c019992
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/261417
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
Reviewed-by: Kevin Burke <kev@inburke.com>
Trust: Roland Shoemaker <roland@golang.org>
2020-10-12 17:37:05 +00:00
Daniel Cohen afb6bcd081 ssh: remove slow unnecessary diffie-hellman-group-exchange primality check
The existing implementation validates that the prime returned by the server is, in fact, prime, which is extremely slow, especially for large key sizes.

As other implementations, including OpenSSH, do not verify the primality of the provided parameters, this change removes that check.

Fixes golang/go#41151

Change-Id: I7539714c690f08b5792a0c540cbf46c3e81f13ba
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/252337
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Roland Shoemaker <roland@golang.org>
2020-09-30 16:06:38 +00:00
Julian Kornberger 75b288015a ssh: Make error message deterministic
By using a slice instead of a map for tried authentication methods the order is always the same. Small slices are also faster than maps.

Before the change sometimes I get the error:

    ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain

and sometimes:

    ssh: handshake failed: ssh: unable to authenticate, attempted methods [publickey none], no supported methods remain

Change-Id: I06507d57e9eef497ff05bce088d52607e69dde3e
GitHub-Last-Rev: 3a46aae4c6e3e5f52ca4b04384b3cc4efc039aa6
GitHub-Pull-Request: golang/crypto#142
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/239171
Reviewed-by: Han-Wen Nienhuys <hanwen@google.com>
Run-TryBot: Han-Wen Nienhuys <hanwen@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-06-22 21:36:23 +00:00
Erick Tryzelaar 279210d13f ssh: don't err out on channel request msgs to unknown channels
rfc4254 section 5.4 states that channel request messages sent to an
unrecognized channel should be replied with a `SSH_MSG_CHANNEL_FAILURE`,
rather than erring out and closing the mux. This can occur with servers
like openssh-portable, which can begin to close a channel and also use
that channel for keepalives before it has received a closed response
from the client.

Fixes golang/go#38908

Change-Id: Id68b77e16b2889d3a21d505ed8018f9f457e067a
GitHub-Last-Rev: 8a92f87dc30697d9e3805af695efdf1b1dc8409b
GitHub-Pull-Request: golang/crypto#136
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/232659
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2020-06-02 18:02:16 +00:00
Lily Chung 729f1e841b ssh: improve docs on Certificate.SignCert
Document the fact that SignCert sets the Nonce field.  This makes it
clear that callers need not set it themselves.

Original change by Jakob Weisblat <jakobw@mit.edu> in CL 57051.

Fixes golang/go#21384

Change-Id: I161e0909ba6c8d07be5f8e68dc6e0f0392bea63f
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/230212
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2020-04-27 16:56:52 +00:00
Bob McNaughton 884d27f428 Update reference to CBC vulnerability in cipher.go
The original referenced paper is no longer available. I contacted the author, and this is the reference he supplied.

Change-Id: Ib5ad88932f2bfc12ff62639f7fb7c3ee568610d6
GitHub-Last-Rev: 2cf7d15c63a114952c90a018ea5afe085965202e
GitHub-Pull-Request: golang/crypto#132
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/228638
Reviewed-by: Han-Wen Nienhuys <hanwen@google.com>
Run-TryBot: Han-Wen Nienhuys <hanwen@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-04-20 10:45:11 +00:00
Hana (Hyang-Ah) Kim 4f8f47aa79 ssh/terminal: handle ctrl+C, ctrl+F, ctrl+B
ctrl+C: terminate readline, which may result in application termination.
ctrl+F: keyRight
ctrl+B: keyLeft

Update golang/go#27147

Change-Id: If319ef79708b98c030cbce102400a785d15137f8
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/228223
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-04-14 15:58:20 +00:00
Alex Gaynor 056763e48d ssh/agent: handle ed25519.PrivateKey by value in AddedKey
Also document that ed25519 is supported.

Change-Id: Ibc4f44069eae4ff1aad27f22fc651a2f7611679d
GitHub-Last-Rev: ee2ce0ae9900b11e1fa891e3587b111168f708c9
GitHub-Pull-Request: golang/crypto#119
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/219506
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-04-06 17:35:13 +00:00
Ross Kinsey 0ec3e9974c ssh: support aes256-cbc for passphrase-protected OpenSSH keys
The existing code for decrypting OpenSSH-format keys only allows aes256-ctr, the current ssh-keygen default.
However, the default encryption scheme was aes256-cbc until relatively recently, and some of these keys are still in use.
Support for aes256-cbc has been added.

Fixes golang/go#37939

Change-Id: I3730347109c5dd18e4cbe61b48bbca9566ad61d2
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/224817
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2020-03-23 16:52:09 +00:00
Lucas Bremgartner 1b76d66859 ssh: fix data race in dh group exchange sha256
Fixes golang/go#37607

Change-Id: Iedf6522ec9b9a676ac51c054407a6aef894885f5
GitHub-Last-Rev: 8cb2460c59d2e32bc3f0480bcd7867a113361c67
GitHub-Pull-Request: golang/crypto#126
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/222078
Reviewed-by: Han-Wen Nienhuys <hanwen@google.com>
Run-TryBot: Han-Wen Nienhuys <hanwen@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-03-17 14:21:12 +00:00
Filippo Valsorda bac4c82f69 ssh: return an error for malformed ed25519 public keys rather than panic
An attacker can craft an ssh-ed25519 or sk-ssh-ed25519@openssh.com
public key, such that the library will panic when trying to verify a
signature with it. Clients can deliver such a public key and signature
to any golang.org/x/crypto/ssh server with a PublicKeyCallback, and
servers can deliver them to any golang.org/x/crypto/ssh client.

This issue was discovered and reported by Alex Gaynor, Fish in a Barrel,
and is tracked as CVE-2020-9283.

Change-Id: Ie25b78a0b0181fbbc8cc7de4f4e27d908777529c
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/220357
Run-TryBot: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Katie Hockman <katie@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-02-20 18:36:23 +00:00
Alex Brainman ecb85df213 ssh/terminal: adjust ReadConsole rules on windows
CL 212377 changed end of input character on windows - from \n to \r.
But CL 212377 did not adjust ReadConsole accordingly. For example,
after CL 212377 \n was still used to end of password processing,
and \r was ignored.

This CL swaps these rules - \r is now used to end password processing,
and \n are ignored. The change only affects windows, all non windows
code should work as before.

This CL also adjusts TestReadPasswordLineEnd to fit new rules.

Fixes golang/go#36609

Change-Id: I027bf80d10e7d4d4b17ff0264935d14b8bea9097
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/215417
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2020-02-08 06:05:01 +00:00
Mariano Cano a95e85b341 ssh: support ECDSA private keys in OpenSSH format
This adds support for parsing OpenSSH ECDSA private keys. It
implements parsing for P-256, P-384, and P-521 keys.

Fixes golang/go#36722

Change-Id: I77c8e0a23ed6353f6667686cc79ec14661cb10db
GitHub-Last-Rev: 2324b920d080fc7ac35fbcf0a79e25161b6a7f82
GitHub-Pull-Request: golang/crypto#114
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/215540
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-02-07 20:58:29 +00:00
Filippo Valsorda c9f3fb736b ssh: support encrypted OpenSSH private keys
Includes the bcrypt_pbkdf package by Dmitry Chestnykh,
submitted with permission on his behalf under the CLA:
https://go-review.googlesource.com/c/crypto/+/207600/2#message-6a035dd62ff76f6c9367299b911076a1be237fb8

Fixes golang/go#18692

Change-Id: I74e3ab355a8d720948d64d87adc009783a9d9732
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/207600
Run-TryBot: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Han-Wen Nienhuys <hanwen@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Han-Wen Nienhuys <hanwen@google.com>
2020-02-04 10:40:54 +00:00
Yasuhiro Matsumoto 6d4e4cb37c ssh/terminal: stop using ENABLE_LINE_INPUT
ReadConsole does not read more than 254 bytes when ENABLE_LINE_INPUT is
enabled.

Fixes golang/go#36071

Change-Id: If5c160404b855387a80f1d57638aac3f2db1a097
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/212377
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2020-01-15 08:54:10 +00:00
Filippo Valsorda 0a08dada0f ssh: reject unencrypted keys from ParsePrivateKeyWithPassphrase
The behavior of ParsePrivateKeyWithPassphrase when the key is
unencrypted is unspecified. Currently, it just parses them like
ParsePrivateKey, which is unlikely to be what anyone wants: for us to
ignore a passphrase that they explicitly passed. It also makes the
implementation of encrypted OpenSSH keys in the next CL more confused.

Instead, make ParsePrivateKey return a PassphraseNeededError, so the
application logic can be ParsePrivateKey -> detect encrypted key ->
obtain passphrase -> ParsePrivateKeyWithPassphrase. That error will also
let us return the public key for OpenSSH keys.

Change-Id: Ife4fb2499ae538bef36e353adf9bc8e902662386
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/207599
Run-TryBot: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Han-Wen Nienhuys <hanwen@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Han-Wen Nienhuys <hanwen@google.com>
2019-12-05 16:18:47 +00:00
Sebastian Kinne 86a70503ff ssh: add sk-ecdsa-sha2-nistp256 and sk-ed25519
This adds server-side support for the newly introduced OpenSSH
keytypes sk-ecdsa-sha2-nistp256@openssh.com and sk-ed25519@openssh.com
(including their corresponding certificates), which are backed
by U2F/FIDO2 tokens.

Change-Id: I53d5ed3d0457ae4758ee986055e187ee5787a2d1
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/208017
Reviewed-by: Han-Wen Nienhuys <hanwen@google.com>
Run-TryBot: Han-Wen Nienhuys <hanwen@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-02 14:38:27 +00:00
Fazlul Shahriar b544559bb6 ssh/agent: fix TestServerResponseTooLarge on Plan 9
First, modify the test to report a better error by waiting for the
Marshal+Write goroutine to finish before returning from the test. If we
return too early, a failure inside that goroutine can generate a panic.

Second, we workaround plan9 not returning the actual number of bytes
written on the connection in case of a hangup (due to closed
connection). I've verified that syscall.Pwrite returns -1 on hangup in
this particular case even when some data did get written.

Fixes golang/go#35888

Change-Id: I7998cff926295f0d577b125c137021a9adc1be5a
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/209298
Reviewed-by: Han-Wen Nienhuys <hanwen@google.com>
Run-TryBot: Han-Wen Nienhuys <hanwen@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-11-28 16:05:24 +00:00
Filippo Valsorda ac88ee75c9 ssh/agent: fix example
Since there is no ClientAgent identifier, ExampleClientAgent wasn't
displayed as an example by godoc.

Change-Id: Ied8df7d8412c4aa483d42315986af49ba8fdbcef
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/208480
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2019-11-22 22:04:53 +00:00
Bryan C. Mills 4f8c1d86b1 ssh/agent: clear the environment when starting ssh-agent in client_test
Certain environment variables can influence the behavior of ssh-agent,
causing the test to fail. Avoid that influence by using a consistent
environment.

This fixes a locally-observed test failure for me.

Change-Id: I0f5e8d643199519f88e80825335ee8e6eb08e3af
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/207901
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Han-Wen Nienhuys <hanwen@google.com>
2019-11-19 21:36:27 +00:00
Lars Lehtonen 497ca9f6d6 ssh/test: fix test goroutine error handling
Adds an error channel to the test helper function
testPortForward() to collect errors that happen inside
a goroutine.

Change-Id: I6db1d24b935fdfad637c971581ae80beaebd8a1f
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/207462
Run-TryBot: Han-Wen Nienhuys <hanwen@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-11-17 06:32:00 +00:00
Filippo Valsorda e0829623af chacha20: expose internal/chacha20 package
const KeySize = 32
const NonceSize = 12
func HChaCha20(key, nonce []byte) ([]byte, error)
type Cipher struct {}
func NewUnauthenticatedCipher(key, nonce []byte) (*Cipher, error)
func (s *Cipher) XORKeyStream(dst, src []byte)

Small performance hit in chacha20poly1305, probably due to the loss
of the Advance API, which we might consider adding later. No new
allocations, thanks to the mid-stack inliner.

name                            old time/op    new time/op    delta
Chacha20Poly1305/Open-64-8        1.60µs ± 0%    1.68µs ± 1%  +4.94%  (p=0.000 n=9+10)
Chacha20Poly1305/Seal-64-8        1.56µs ± 0%    1.64µs ± 1%  +5.21%  (p=0.000 n=8+10)
Chacha20Poly1305/Open-64-X-8      2.10µs ± 1%    2.22µs ± 1%  +5.81%  (p=0.000 n=10+10)
Chacha20Poly1305/Seal-64-X-8      2.07µs ± 1%    2.17µs ± 0%  +4.88%  (p=0.000 n=10+10)
Chacha20Poly1305/Open-1350-8      15.4µs ± 0%    15.7µs ± 1%  +1.65%  (p=0.000 n=10+10)
Chacha20Poly1305/Seal-1350-8      15.6µs ± 2%    15.9µs ± 1%  +1.58%  (p=0.028 n=10+9)
Chacha20Poly1305/Open-1350-X-8    16.0µs ± 1%    16.3µs ± 2%  +2.00%  (p=0.000 n=10+10)
Chacha20Poly1305/Seal-1350-X-8    15.9µs ± 0%    16.3µs ± 1%  +1.91%  (p=0.000 n=10+8)
Chacha20Poly1305/Open-8192-8      85.6µs ± 0%    86.6µs ± 1%  +1.21%  (p=0.000 n=10+10)
Chacha20Poly1305/Seal-8192-8      85.7µs ± 0%    86.3µs ± 0%  +0.68%  (p=0.001 n=9+9)
Chacha20Poly1305/Open-8192-X-8    86.4µs ± 1%    87.1µs ± 1%  +0.76%  (p=0.035 n=10+9)
Chacha20Poly1305/Seal-8192-X-8    86.0µs ± 0%    87.0µs ± 1%  +1.14%  (p=0.000 n=9+9)

Updates golang/go#24485

Change-Id: I2ec2ef487a03f013049915d9063751c75a78408b
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/185980
Reviewed-by: Michael Munday <mike.munday@ibm.com>
2019-11-11 21:38:06 +00:00
Lars Lehtonen 6e5058baad ssh: fix dropped error
This fixes an error variable that was being dropped
prior to the return of dhGroup.Server().

Change-Id: I8ddef1832cd7a62a69b61bb1c98bc1ceb561f985
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/205420
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2019-11-08 23:12:17 +00:00
Brad Fitzpatrick cea2066c64 Revert "ssh/terminal: account for win32 api changes"
This reverts commit CL 196897 (commit 9ee001bba3)

Reason for revert: we're reverting the API change instead
in https://go-review.googlesource.com/c/sys/+/197597

Change-Id: I41741c85bb7a07b9ce13264ebb26ee3f968772fa
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/197598
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
2019-09-26 18:03:35 +00:00
Jason A. Donenfeld 9ee001bba3 ssh/terminal: account for win32 api changes
The API changed for this function, since the call always succeeds.
Update this user of it accordingly.

Fixes: golang/go#34461

Change-Id: I9d19b70767fc6b1b9292ad8732dd8e54bb6a8ae0
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/196897
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-09-23 03:51:54 +00:00
Eric Brown 094676da4a ssh: drop dh-group1-sha1 from default key exchanges
This removes diffie-hellman-group1-sha1 from the list of default
key exchange algorithms. This kex is considered weak and potentially
vulnerable to the Logjam attack.

Note: This is a backwards incompatible change: if you connect to ssh
servers that do not support any key exchanges except for dh-group1-sha1,
you must now specify config.KeyExchanges explicity.

See also:
https://www.openssh.com/legacy.html
https://blog.gdssecurity.com/labs/2015/8/3/ssh-weak-diffie-hellman-group-identification-tool.html

Fixes golang/go#12955

Change-Id: I032d5175d63ab5d1912de72957a80200eb396bc9
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/123595
Reviewed-by: Han-Wen Nienhuys <hanwen@google.com>
2019-09-09 09:17:59 +00:00
Michael Hudson-Doyle 9756ffdc24 ssh/test: delete TestInvalidTerminalMode
This test just tests the behaviour of the host sshd in the face of
invalid terminal modes, and the RFCs say that the server "MAY" ignore
such modes (and newer openssh does in fact ignore these modes rather
than terminating the connection).

Fixes golang/go#33919

Change-Id: I3f915aed22651e2eb33ec34044af8b125aeb82fa
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/192217
Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-08-29 04:30:50 +00:00
Agniva De Sarker 4def268fd1 ssh: skip testHandshakeErrorHandlingN on js/wasm
The wasm runtime cannot schedule a GC run on tight loops.
Therefore it runs out of memory if such a loop allocates memory.

Skip such a test for now.

Updates golang/go#32840

Change-Id: I922b6e02710915776d2820573fd1584a5941185b
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/184397
Run-TryBot: Agniva De Sarker <agniva.quicksilver@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Han-Wen Nienhuys <hanwen@google.com>
2019-07-01 09:49:42 +00:00
Lucas Bremgartner 57b3e21c3d ssh: add diffie-hellman-group-exchange-sha256
Add the diffie-hellman-group-exchange-sha256 defined in RFC 4419 to
the list of supported key exchange algorithms for ssh.
The server half is only a minimal implementation to satisfy the automated tests.

Fixes golang/go#17230

Change-Id: I25880a564347fd9b4738dd2ed1e347cd5d2e21bb
GitHub-Last-Rev: 9f0b8d02c0c96e9baf00cdf1cf063ff834245443
GitHub-Pull-Request: golang/crypto#87
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/174257
Run-TryBot: Han-Wen Nienhuys <hanwen@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Han-Wen Nienhuys <hanwen@google.com>
2019-06-17 13:33:40 +00:00
yanweizhi cbcb750295 ssh/gss: support kerberos authentication for ssh server and client
Change-Id: I20e3356476dc50402dd34d2b39ad030c1e63a9ef
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/170919
Run-TryBot: Han-Wen Nienhuys <hanwen@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Han-Wen Nienhuys <hanwen@google.com>
2019-05-10 10:41:15 +00:00
chigotc f162ad860c ssh/test: add port for aix/ppc64
Fixes golang/go#31413

Change-Id: I52105280a2237f23cd91b8ec92fd89cf62564572
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/171917
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-04-26 14:52:10 +00:00
Han-Wen Nienhuys df01cb2cc4 ssh: invert algorithm choices on the server
At the protocol level, SSH lets client and server specify different
algorithms for the read and write half of the connection. This has
never worked correctly, as Client-to-Server was always interpreted as
the "write" side, even if we were the server.

This has never been a problem because, apparently, there are no
clients that insist on different algorithm choices running against Go
SSH servers.

Since the SSH package does not expose a mechanism to specify
algorithms for read/write separately, there is end-to-end for this
change, so add a unittest instead.

Change-Id: Ie3aa781630a3bb7a3b0e3754cb67b3ce12581544
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/172538
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-04-18 16:56:55 +00:00
Tobias Klauser b43e412143 ssh/test: skip test on js/wasm
This should fix the build on the js/wasm builder.

Change-Id: I02a0ae00dcfd2691fbb4c7cf038b12988f3b4b85
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/172717
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-04-18 16:12:25 +00:00
Han-Wen Nienhuys 88737f569e ssh/test: use t.Run for MAC/kex/pubkey tests
Change-Id: Ic57625964b6d40d63acade476a0f99c00d598267
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/171681
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-04-11 19:13:39 +00:00
Han-Wen Nienhuys e7b772b700 ssh: print server exit reason in tests
This helps debugging protocol violations by the client

Change-Id: I8e5486b49515b719bbe3de44daa489fb7434875a
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/171680
Run-TryBot: Han-Wen Nienhuys <hanwen@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-04-11 14:19:40 +00:00
Han-Wen Nienhuys 9732e03de3 ssh: add packetTypeNames map for better debug info
Change-Id: Ie1f58e00982568382e09d8f1dd12bf8a1dc1a9ed
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/171679
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-04-11 14:12:12 +00:00
Han-Wen Nienhuys d99183c9a7 ssh: rename ExampleHostKeyCheck to ExampleClientConfig_HostKeyCallback
Change-Id: I6d0f3396f06871286e3d48ec5af38770663dbed2
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/171678
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-04-11 14:11:56 +00:00
Han-Wen Nienhuys 184a689644 ssh: remove testing.T from ExampleRetryableAuthMethod
Change-Id: I9cb821827b16d60b0a8c4fff9caec78748f3a495
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/171677
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-04-11 14:11:41 +00:00
Han-Wen Nienhuys 457ee04da3 ssh: rename methods in packetCipher interface
The new name readCipherPacket/writeCipherPacket disambiguates method
calls from packetConn.{read,write}Packet, which has a different
signature, and is called in different layers of the stack.

Change-Id: I02ca83e28f74f0a347a1cde665efdfb78f3f51bb
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/171657
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-04-11 14:11:16 +00:00
Brad Fitzpatrick 38d8ce5564 ssh/test: skip test to fix build on solaris and aix
Change-Id: I734bf1f709a259889eeb9243079edb90d6751f67
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/170677
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2019-04-04 16:44:18 +00:00
Andrey Petrov a5d413f772 ssh/terminal: Use move-N sequences for >1 cursor moves
Before, we emitted N single-move sequences on a cursor move. For
example, "move 4 left" would emit "^[[D^[[D^[[D^[[D". With this change,
it would emit "^[[4D".

Using variable move sequences when possible reduces the amount of
rendering output that the terminal implementation produces. This can
have some low-level performance benefits, but also helps consumers
reason through the produced output.

Includes a test with a couple of cases.

Note: The old implementation used ^[[D instead of ^[D which is also
valid. This is true in several unrelated places, so this implementation
continues to use ^[[D for consistency.

Change-Id: If38eaaed8fb4075499fdda54c06681dc34c3ad70
GitHub-Last-Rev: 92ef2538d33a9493f3df09984c277dfd8bf0abf4
GitHub-Pull-Request: golang/crypto#82
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/169077
Reviewed-by: Adam Langley <agl@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-03-25 15:42:30 +00:00
Max Semenik 31a3858548 ssh/terminal: fix GetSize on Windows
Return window size instead of buffer size.

Fixes golang/go#27743

Change-Id: Ib1cd249f5680d86d505032e51d9102c2718ddf6f
Reviewed-on: https://go-review.googlesource.com/c/163538
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-02-28 05:08:51 +00:00
Ian Haken 7f87c0fbb8 ssh/agent: add checking for empty SSH requests
Previously empty SSH requests would cause a panic.

Change-Id: I8443fee50891b3d2b3b62ac01fb0b9e96244241f
GitHub-Last-Rev: 64f00d2bf2ee722f53e68b6bd4f70c722d7694bd
GitHub-Pull-Request: golang/crypto#58
Reviewed-on: https://go-review.googlesource.com/c/140237
Reviewed-by: Han-Wen Nienhuys <hanwen@google.com>
Run-TryBot: Han-Wen Nienhuys <hanwen@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-02-25 12:45:18 +00:00
Michael Cook b8fe1690c6 all: fix ineffectual assignments
audited using ineffassign tool from
github.com/gordonklaus/ineffassign
go generate does not generate any changes

Change-Id: Iabbec9ec1aae39081289d503d79fd7b4caadf17b
GitHub-Last-Rev: acd17cce410e9c68ce3c87b5546261be9153e3ea
GitHub-Pull-Request: golang/crypto#70
Reviewed-on: https://go-review.googlesource.com/c/155942
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2019-01-31 18:25:04 +00:00
Michal Bohuslávek c7b33c32a3 ssh/terminal: support ^N and ^P
This makes it possible to navigate the history without leaving
the home row on the keyboard.

Change-Id: Id24c43f8eb6090520ab37bf8126264901b70c489
Reviewed-on: https://go-review.googlesource.com/c/33618
Run-TryBot: Matt Layher <mdlayher@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matt Layher <mdlayher@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-01-28 19:33:16 +00:00