go 中的 ssh 服务器:如何提供不同于 rsa 的公钥类型?

我正在尝试使用该x/crypto/ssh模块创建一个 ssh 服务器,但我无法使公钥身份验证工作。
我尝试了文件中的ExampleNewServerConn()函数ssh/example_test.go(在https://go.googlesource.com/crypto repo 中),但公钥方法不起作用,看起来服务器没有宣传正确的算法,因为我得到了这一行尝试与 ssh 客户端连接时:

debug1: send_pubkey_test: no mutual signature algorithm

如果我添加-o PubkeyAcceptedKeyTypes=+ssh-rsa公钥登录有效,但不推荐使用此 rsa 方法,我想使用另一种公钥类型,我该怎么做?

提前致谢。


慕森卡
浏览 69回答 2
2回答

呼唤远方

我发现为什么客户端和服务器不能通信,rsa-sha2 算法还没有在 x/crypto 库中实现。github上有一个关于它的问题:https ://github.com/golang/go/issues/49952 。临时解决方案是添加replace golang.org/x/crypto => github.com/rmohr/crypto v0.0.0-20211203105847-e4ed9664ac54在你的 go.mod 文件的末尾,它使用来自@rmohr 的 ax/crypto fork,它与 rsa-sha2 一起使用。

慕后森

这是一种简单的方法,让letsencrypt为您处理证书:)func main() {    r := mux.NewRouter()    r.HandleFunc("/index", index)    certManager := autocert.Manager{        Prompt:     autocert.AcceptTOS,        HostPolicy: autocert.HostWhitelist("www.example.com"), // replace with your domain        Cache:      autocert.DirCache("certs"),    }    srv := &http.Server{        Handler:      r,        Addr:         ":https",        WriteTimeout: 5 * time.Second,        ReadTimeout:  5 * time.Second,        TLSConfig: &tls.Config{            GetCertificate: certManager.GetCertificate,        },    }    go http.ListenAndServe(":http", certManager.HTTPHandler(nil)) //nolint    log.Fatal(srv.ListenAndServeTLS("", ""))}
打开App,查看更多内容
随时随地看视频慕课网APP