SSL/TLS 使用 Websockets 服务器 - go lang

SSL/TLS with Websockets Server - go lang

我正在使用对撞机(https://github.com/webrtc/apprtc/tree/master/src/collider - 一个 websockets 服务器)并且我正在尝试添加 SSL/TLS 支持。我为此生成了自签名证书:

openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365

Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
Country Name (2 letter code) [AU]:US
State or Province Name (full name) [Some-State]:CA
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:testwebsite.com
Organizational Unit Name (eg, section) []:Engineering
Common Name (e.g. server FQDN or YOUR name) []:www.testwebsite.com
Email Address []:testwebsite@gmail.com

当我 运行 对撞机时,我看到这个错误:

2017/06/05 21:25:50 Error Run: crypto/tls: failed to parse private key

当我生成时使用(基于http://www.kaihag.com/https-and-go/):

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout key.pem -out cert.pem

我收到这个错误:

2017/06/05 22:11:31 http: TLS handshake error from <some-ip>:1082: remote error: unknown certificate

如何解决这个问题?

注:collider使用golangorg/x/net/websocket

我最终从以下位置获得了证书:https://certbot.eff.org/#ubuntuxenial-other

certbot certonly --standalone -d example.com -d www.example.com

我必须使用 fullchain.pem 而不是 cert.pem 才能让这个对撞机工作:

https://github.com/webrtc/apprtc/issues/442