AutoTLS和Gin(gin-gonic)无法读取SSL证书
创始人
2024-11-12 16:00:22
0

这可能是因为证书格式不正确或与密钥不匹配导致的。可以使用以下代码片段来生成正确的证书格式:

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout key.pem -out cert.pem
openssl pkcs12 -inkey key.pem -in cert.pem -export -out cert.p12

在Gin的代码中将下面的代码替换为正确的证书路径和密码:

router := gin.Default()
router.Use(TlsHandler())
router.RunAutoTLS(":443")
// ...
func TlsHandler() gin.HandlerFunc {
    certFile := "/path/to/cert.p12"
    certPassword := "my_password"
    return func(c *gin.Context) {
        c.Request.TLS = &tls.ConnectionState{}
        cert, err := tls.LoadX509KeyPair(certFile, certFile)
        if err != nil {
            log.Fatal(err)
        }
        certBytes, err := ioutil.ReadFile(certFile)
        if err != nil {
            log.Fatal(err)
        }
        pool := x509.NewCertPool()
        if !pool.AppendCertsFromPEM(certBytes) {
            log.Fatal("Failed to append certs")
        }
        c.Request.TLS.Certificates = []tls.Certificate{cert}
        c.Request.TLS.RootCAs = pool
        c.Request.TLS.ClientCAs = pool
        c.Request.TLS.ServerName = ""
    }
}

确保证书路径和密码正确,然后重新运行代码。

相关内容

热门资讯

总算了解!aapoker透视怎... 总算了解!aapoker透视怎么用,约局吧能不能开挂,细节方法(有挂神器)是一款可以让一直输的玩家,...
教程辅助!wepoker到底有... 教程辅助!wepoker到底有没有透视,aapoker公共底牌,教你教程(有挂技巧);科技安装教程;...
我来教教大家!wpk刷入池率脚... 自定义wpk刷入池率脚本系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专用辅助器,不...
玩家科普!wepoker透视脚... 玩家科普!wepoker透视脚本,aapoker怎么选牌,规律教程(有挂透视)1、玩家可以在aapo...
关于!pokemmo手机脚本,... 此外,数据分析德州(newpoker怎么安装脚本)辅助神器app还具备辅助透视行为开挂功能,通过对客...
重大发现!hhpoker破解工... 《重大发现!hhpoker破解工具,wepoker辅助插件功能,力荐教程(有挂方法)》 wepoke...
关于!wpk透视辅助方法,po... 关于!wpk透视辅助方法,pokemmo脚本最新版,解密教程(有挂透明)是一款可以让一直输的玩家,快...
一起来讨论!约局吧怎么看有没有... 一起来讨论!约局吧怎么看有没有挂,uupoker透视,透明教程(有挂技巧);科技安装教程;13670...
我来向大家传授!德州局hhpo... 我来向大家传授!德州局hhpoker,约局吧开挂,必备教程(有挂方法)1、许多玩家不知道德州局hhp...
科技揭秘!德普辅助器辅助器怎么... 科技揭秘!德普辅助器辅助器怎么用,pokermaster脚本,2025新版总结(有挂技巧)1、点击下...