为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

Go
慕森卡 2022-10-17 17:20:01
我正在尝试使用该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 方法,我想使用另一种公钥类型,我该怎么做?提前致谢。
查看完整描述

2 回答

?
呼唤远方

TA贡献1856条经验 获得超11个赞

我发现为什么客户端和服务器不能通信,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 一起使用。


查看完整回答
反对 回复 2022-10-17
?
慕后森

TA贡献1802条经验 获得超5个赞

这是一种简单的方法,让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("", ""))

}


查看完整回答
反对 回复 2022-10-17
  • 2 回答
  • 0 关注
  • 67 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信