go x/crypto: 当远程密钥指数大于24b时,ssh/client.NewSession()失败,

kx5bkwkv  于 2个月前  发布在  Go
关注(0)|答案(4)|浏览(25)

你正在使用哪个版本的Go( go version )?

go version go1.17.5 linux/amd64

这个问题在最新版本中是否重现?

是的

你正在使用什么操作系统和处理器架构( go env )?

go env 输出

$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.5"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/gedix/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build309787458=/tmp/go-build -gno-record-gcc-switches"

你做了什么?

尝试打开一个SSH会话到LSH服务器( lshd-1.4.3, secsh protocol version 2.0 )。

package main

import (
	"golang.org/x/crypto/ssh"
	"log"
)

func main() {
	user := "REDACTED"
	password := "REDACTED"
	host := "REDACTED"

	sshConfig := &ssh.ClientConfig{
		User:            user,
		Auth:            []ssh.AuthMethod{ssh.Password(password)},
		HostKeyCallback: ssh.InsecureIgnoreHostKey(),
	}

	client, dialErr := ssh.Dial("tcp", host, sshConfig)
	if dialErr != nil {
		log.Fatalf("dial: %s\n", dialErr)
	}

	if _, sessErr := client.NewSession(); sessErr != nil {
		log.Fatalf("session: %s\n", sessErr)
	}
	defer client.Close()
}

你期望看到什么?

NewSession() 上没有错误

你看到了什么?

2022/01/20 12:02:05 dial: ssh: handshake failed: ssh: exponent too large
然而,openssh客户端成功连接,这是因为我为 KexAlgorithmsHostKeyAlgorithms 指定了预期的值(在Go的ssh配置中设置这些值并没有帮助)。

> ssh -v [HOST]
OpenSSH_8.8p1, OpenSSL 1.1.1m  14 Dec 2021
debug1: Connection established.
[...]
debug1: Local version string SSH-2.0-OpenSSH_8.8
debug1: Remote protocol version 2.0, remote software version lshd_1.4.3 lsh - a free ssh
debug1: compat_banner: no match: lshd_1.4.3 lsh - a free ssh
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: diffie-hellman-group1-sha1
debug1: kex: host key algorithm: ssh-rsa
debug1: kex: server->client cipher: aes256-ctr MAC: hmac-sha1 compression: none
debug1: kex: client->server cipher: aes256-ctr MAC: hmac-sha1 compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-rsa SHA256:lWlSUxbsOy5xtg3vvLTJaI1IrmwMjgoANXnFL+8sSzI
[...]
debug1: Authentications that can continue: password,publickey
[...]
debug1: Next authentication method: password
[success]

作为解决方法,我通过将最大位长度更改为31(而不是实际的24)来成功建立会话,在 ParseRSA() 中的 x/crypto/ssh/keys.go:353。

q8l4jmvw

q8l4jmvw1#

cc @FiloSottile@agl@katiehockman@rolandshoemaker

5w9g7ksd

5w9g7ksd2#

为什么你使用了一个具有如此大指数的密钥?这是lshd的默认设置,还是你自己生成的密钥?
我们明确不支持如此大的指数,因为它们几乎没有什么好处。请参阅#3161https://codereview.appspot.com/5650067之前的讨论(还有https://www.imperialviolet.org/2012/03/16/rsae.html)。

06odsfpq

06odsfpq3#

嘿,谢谢你花时间看这个。

为什么你使用了一个具有如此大指数的密钥?这是lshd的默认设置,还是你自己生成的密钥?

实际上我对此没有发言权,我试图连接到一个密钥保持不变且无法更改的服务器(它是一个由BigCorp提供的设备)。我不确定密钥是如何生成的。

我们明确不支持如此大的指数,因为它们几乎没有什么好处。参见#3161https://codereview.appspot.com/5650067之前的讨论(还有https://www.imperialviolet.org/2012/03/16/rsae.html)。

感谢你的反馈,因为了解这个背景信息是很有价值的。

你认为不处理大指数的决定是否容易在当前问题上重新评估?否则我会继续前进,至少我们在这里可以引用一个可搜索的问题,参考exponent too large;)

ddrv8njm

ddrv8njm4#

感谢上下文。
自从这个问题首次被讨论以来,在过去的十年里很少出现。鉴于它是多么罕见,而且没有一些严重的RSA问题需要大家切换到巨大的指数,我认为我们不会重新考虑这个决定。

相关问题