douxing9641 2019-02-03 15:10
浏览 104

使用autocert保护安全的Websocket服务器

I am trying to setup a secure websocket server (wss://) in go using acme/autocert. The program starts, but when I try to connect to it I get the following error:

http: TLS handshake error from <IP>: acme/autocert: 
unable to authorize "<my domain>"; challenge "tls-alpn-01" failed with error: 
acme: authorization error for <my domain>: 403 urn:acme:error:unauthorized:
Cannot negotiate ALPN protocol "acme-tls/1" for tls-alpn-01 challenge

This is the code I am using to start the websocket server:

func Run() {

    hub = newHub()
    go hub.run()

    mux := http.NewServeMux()

    mux.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) {
        serveWs(hub, w, r)
    })

    certManager := autocert.Manager{
        Prompt: autocert.AcceptTOS,
        Cache:  autocert.DirCache("certs"),
    }

    server := &http.Server{
        Addr:    ":8080",
        Handler: mux,
        TLSConfig: &tls.Config{
            GetCertificate: certManager.GetCertificate,
        },
    }

    go server.ListenAndServeTLS("", "")
}

It should automatically get a new certificate when there is none in the cache (certs folder). The error message tells me that there is a problem while negotiating the protocol when creating a new certificate. Do I need to add supported protocols somewhere?

  • 写回答

1条回答 默认 最新

  • douxianxing5712 2019-02-03 16:50
    关注

    I'm not sure what is your issue but trying to add the HostPolicy in order to let to the manager know which host is allowed to respond to. here an example https://github.com/kjk/go-cookbook/blob/master/free-ssl-certificates/main.go#L77

    Note: as a suggestion try to use 443 or 8443 as a secure ports.

    评论

报告相同问题?

悬赏问题

  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器