Do not set rejectUnauthorized by default in wsProxy.

This commit is contained in:
Julien Fontanet 2015-05-19 12:27:02 +02:00
parent 523a30afb4
commit 65daa23a74
2 changed files with 19 additions and 22 deletions

View File

@ -324,7 +324,9 @@ const setUpConsoleProxy = (webServer, xo) => {
// FIXME: lost connection due to VM restart is not detected. // FIXME: lost connection due to VM restart is not detected.
webSocketServer.handleUpgrade(req, socket, head, connection => { webSocketServer.handleUpgrade(req, socket, head, connection => {
wsProxy(connection, url) wsProxy(connection, url, {
rejectUnauthorized: false
})
}) })
}) })
} }

View File

@ -6,46 +6,41 @@ const debug = createDebug('xo:wsProxy')
const defaults = { const defaults = {
// Automatically close the client connection when the remote close. // Automatically close the client connection when the remote close.
autoClose: true, autoClose: true
// Reject secure connections to unauthorized remotes (bad CA).
rejectUnauthorized: false
} }
// Proxy a WebSocket `client` to a remote server which has `url` as // Proxy a WebSocket `client` to a remote server which has `url` as
// address. // address.
export default function wsProxy (client, url, opts) { export default function wsProxy (client, url, opts) {
opts = assign({}, defaults, opts) opts = assign({}, defaults, opts)
const autoClose = !!opts.autoClose
delete opts.autoClose
const remote = new WebSocket(url, { function onClientSendError (error) {
protocol: opts.protocol || client.protocol, debug('client send error', error)
rejectUnauthorized: opts.rejectUnauthorized }
}).once('open', function () { function onRemoteSendError (error) {
debug('connected to', url) debug('remote send error', error)
}
const remote = new WebSocket(url, opts).once('open', function () {
debug('connected to %s', url)
}).once('close', function () { }).once('close', function () {
debug('remote closed') debug('remote closed')
if (opts.autoClose) { if (autoClose) {
client.close() client.close()
} }
}).once('error', function (error) { }).once('error', function (error) {
debug('remote error', error) debug('remote error: %s', error)
}).on('message', function (message) { }).on('message', function (message) {
client.send(message, function (error) { client.send(message, onClientSendError)
if (error) {
debug('client send error', error)
}
})
}) })
client.once('close', function () { client.once('close', function () {
debug('client closed') debug('client closed')
remote.close() remote.close()
}).on('message', function (message) { }).on('message', function (message) {
remote.send(message, function (error) { remote.send(message, onRemoteSendError)
if (error) {
debug('remote send error', error)
}
})
}) })
} }