【问题标题】:Sending a self-signed certificate from proxy secure websocket to a secure websocket connection(wss)将自签名证书从代理安全 websocket 发送到安全 websocket 连接(wss)
【发布时间】:2021-08-06 01:47:51
【问题描述】:

我正在尝试使用 wscat 和浏览器通过自签名证书连接到 wss(proxy),但它给了我错误。

  • https 使用证书 cert.pem 在 8443 上运行
  • 代理在 8080 上运行,具有安全真值

我已尝试确保我的安全服务器正常运行。

  • 我可以访问 https://localhost:8443 并收到“来自安全世界的你好”
  • 我可以使用 wscat wscat -c wss://localhost:8443 --ca cert.pem 连接到 wss://localhost:8443 并且可以正常工作

我得到的错误:

  • 我无法从浏览器访问代理 https://localhost:8080。我收到此站点无法提供安全连接和 500 状态代码
  • 我无法使用wscat -c wss://localhost:8080 --ca cert.pem 连接到 wss://localhost:8080 我得到error: write EPROTO 140266887743360:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332:

我认为问题在于我的代理服务器无法获取 cert.pem 并将其传递给 https 服务器。我到处寻找,但找不到如何使用自签名证书连接到 wss(proxy)。我无法抑制

/服务器

const app = express()
app.use('/', function (req, res) {
  res.writeHead(200);
  res.end("hello from a secure world\n");
})

export const server = https.createServer({
  cert: fs.readFileSync(path.resolve(__dirname, 'cert.pem'), 'utf-8'),
  ca: fs.readFileSync(path.resolve(__dirname, 'cert.pem'), 'utf-8'),
  key: fs.readFileSync(path.resolve(__dirname, 'server.key'), 'utf-8')
}, app)

const wss = new WebSocket.Server({ server });
wss.on('connection', function connection(ws) {
  console.log("connected");
  ws.on('message', function incoming(message) {
      console.log('received: %s', message);
      ws.send('hello from server!, the time is: ' + timestamp());
    });
});

/代理

const wsProxy = createProxyMiddleware('/', {
    target: `https://localhost:8443`,
    changeOrigin: true,
    secure: true,
    ws: true,
    ssl: {
        cert: fs.readFileSync(path.resolve(__dirname, 'cert.pem')),
    }
});

const app = express();
app.use(wsProxy);

const proxy = app.listen(8080)    
proxy.on('upgrade', wsProxy.upgrade); // <-- subscribe to http 'upgrade'

【问题讨论】:

    标签: ssl websocket proxy self-signed-certificate


    【解决方案1】:

    好吧,原来我在那里遗漏了一些重要的东西。没有真正的“代理 websocket” 我将 https 代理与 websocket 代理混淆了。一旦我明白了这一点,它就解决了我的问题。我必须使用 https 服务器(带有证书和密钥)创建一个 websocket,然后我可以使用相同的证书和密钥连接到 wss :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-18
      • 2014-07-06
      • 2014-04-30
      • 2014-10-27
      • 2018-08-03
      • 2018-01-04
      • 2020-03-04
      • 2015-05-25
      相关资源
      最近更新 更多