Connection to Redis cache failing - javascript

I have a node app connecting to a redis cache hosted on azure but whenever I'm trying to connect to it, the connection fails with an error message
I have enabled secure connection through a port and configured my node app accordingly
// This is my client module
const Redis = require("ioredis");
var client = new Redis(
{
port: 6380,
tls: true,
host: process.env.REDIS_HOST,
password: process.env.REDIS_PASSWORD,
family:
db: 0
}
);
module.exports = client;
This is the error I encounter whenever I start my app:
[ioredis] Unhandled error event: Error: unable to get local issuer certificate
at TLSSocket.onConnectSecure (_tls_wrap.js:1317:34)
at TLSSocket.emit (events.js:209:13)
at TLSSocket._finishInit (_tls_wrap.js:792:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:606:12)
The API ran for a while without any problems but then started throwing this error. My colleague is not having a problem running the same service and I'm assuming this is my machines certificates or lack of causing the issue. Any solutions or suggestions?

The problem was with the company wifi network I was using. The firewall did not allow me to connect to the cache.

Related

ERR_SSL_SSLV3_ALERT_CERTIFICATE_UNKNOWN thrown by wss server when client tries to connect to it

recently I've been trying to create a WebSocket server (using the ws library for node.js). At first I used the ws unencrypted protocol, but then I had to switch to wss. This brought some client authentication issues. When the client (running on a browser)
(client.js)
this.socket = new WebSocket(`wss://ipv4.address:port`);
... tries to connect to the Node.js-based server
(server.mjs:)
const server = createServer({
cert: readFileSync('/path/to/ssl_certificate.cer'),
key: readFileSync('/path/to/private_key.key'),
ca: [
readFileSync('/etc/ssl/certs/ca-certificates.crt'),
readFileSync('/path/to/ssl_certificate_INTERMEDIATE.cer')
],
rejectUnauthorized: false
});
const wss = new WebSocketServer({ server });
server.listen(port, "hostname", () => {
//the server actually listens, so this line of code is printed
console.log(`listening on wss://${wss.address().address}:${server.address().port}`);
});
server.on("tlsClientError", (err, tlsSocket) => {
console.error("TLS client error", err);
tlsSocket.destroy();
});
... it goes into "tlsClientError", printing this:
TLS client error [Error: C0D71E8ECB7F0000:error:0A000416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown:../deps/openssl/openssl/ssl/record/rec_layer_s3.c:1584:SSL alert number 46
] {
library: 'SSL routines',
reason: 'sslv3 alert certificate unknown',
code: 'ERR_SSL_SSLV3_ALERT_CERTIFICATE_UNKNOWN'
}
This looks like the server isn't willing to accept the client's certificates. How do I set them? Is there something I'm not understanding about WebSockets over TLS?
I tried following the advice of many answers from StackOverflow, disabling rejectUnauthorized, but the node https server is still failing, even after adding the same SSL certificates my website is using (same hostname, different port)
EDIT:
I forgot to mention, that connecting from the same host as the server works (i.e. using the ws client part on the node side), as per https://github.com/websockets/ws/blob/master/examples/ssl.js, and even when disabling rejectUnauthorized (because I'm not using a self-signed certificate)

Node Server Data Base Connection Lost

I'm developing a web app using express, and MySQL. I was able to publish the app on heroku for testing. The problem came after few minutes or seconds, the server throws the following error:
Error: Connection lost: The server closed the connection.
at Protocol.end (/app/node_modules/mysql/lib/protocol/Protocol.js:112:13)
at Socket.<anonymous> (/app/node_modules/mysql/lib/Connection.js:94:28)
at Socket.<anonymous> (/app/node_modules/mysql/lib/Connection.js:526:10)
at Socket.emit (events.js:327:22)
When I restart the server, I'm able to execute some successful calls to database, but after some minutes, the connection get lost.
This is the connection file I'm currently using, I will, change my credentials for placeholders, only for security purppose.
module.exports = {
HOST: 'mysql5044hostname',
USER: 'myUserName',//root
PASSWORD: 'thisIsMyPassword',
DB: 'default_schema'
};
Any help regarding this matter, will be appreciated.
#vodolaz095 and #riscarrott thanks to both of you, I changed the logic based on the documentation you sent, and I was able to successfully connect to database without losing the communication with the server.

Nodemailer Error that may be result of port error?

I'm using Nodemailer and I get an error that I can't seem to solve. Some sites say it's my firewall blocking ports, I opened the ports and used different ports, didn't solve much.
Below are logs of the errors Nodemailer emitted.
[2020-10-07 03:38:23] DEBUG Creating transport: nodemailer (6.4.13; +https://nodemailer.com/; SMTP/6.4.13[client:6.4.13])
[2020-10-07 03:38:23] DEBUG Sending mail using SMTP/6.4.13[client:6.4.13]
[2020-10-07 03:38:23] DEBUG [TNYM4ZexJbo] Resolved smtp.mailtrap.io as 34.224.73.100 [cache miss]
[2020-10-07 03:38:44] ERROR [TNYM4ZexJbo] connect EACCES 34.224.73.100:25
[2020-10-07 03:38:44] DEBUG [TNYM4ZexJbo] Closing connection to the server using "destroy"
[2020-10-07 03:38:44] ERROR Send Error: connect EACCES 34.224.73.100:25

how to bind to privileged port 443 using node on Windows Server

First post on SO! When trying to start my node server I'm getting an unhandled exception:
throw er; // Unhandled 'error' event
Error: listen EACCES: permission denied 0.0.0.0:443
How can I enable node server to run on a 'privileged' port?
When setting the port to anything above 1000, everything works perfectly, but this is problematic because of customer regulations on which ports can be open, so I'm trying to stick to 443.
I see others have solved this using sudo for Linux environments, and I tried running mine as Administrator but had no luck.
Client connects with
ws = new WebSocket('wss://subdomain.website.com');
ws.onopen = function() {
ws.close();
}
node server starts with
'use strict'
var detectedSampleRate = 0;
const https = require("https");
const fs = require("fs");
const options = {
key: fs.readFileSync("privateKey.key"),
cert: fs.readFileSync("cert.pem")
};
var express = require('express');
const app = express();
var session = require('express-session');
app.use(express.static(__dirname + '/public'));
app.use(session({
secret : '##########',
resave : false,
saveUninitialized: true
}));
var server = https.createServer(options,app).listen(443);
Additional info:
Website hosted on IIS serves index.html to user over https.
index.html then opens a websocket connection to a node server running on the IIS server.
index.html and node server talk to each other.
(IIS) --> index.html
node <--> webconnection within index.html
The client side of this connection that's served to the user is working correctly, and calls the connection via 443 with proper certificates.
The server side (node server) fails to start due to this permission issue.
Thank you in advance!
I ended up figuring it out. Turns out the IIS server was hogging the 443 port and when node gives the error
throw er; // Unhandled 'error' event
Error: listen EACCES: permission denied 0.0.0.0:443
It meant that the port was currently in use.
Because of my strange setup, I ended up leaving the index.html to be served from IIS, and the internal webconnection to connect with the node server running on a separate machine within the same domain.
For others, if you run into this unhandled exception on Windows, check if you're doing anything weird with your implementation, or if the port is being used by anything else.

iceConnectionState is disconnected - VP9 Coded is null - PeerServer

I have an application which is using PeerJS for video streaming, and I'm using a node based Peer Server running on an Ubuntu Server instance, over HTTPS (SSL certificates installed on the server).
This is how I instanciate my PeerServer :
var server = PeerServer({
port:55127,
path:'/',
debug:true,
ssl:{
key: fs.readFileSync('/etc/apache2/ssl/mykey.key'),
cert: fs.readFileSync('/etc/apache2/ssl/mycert.crt')
}
});
This is how I create a peer connection :
var peer = new Peer('peerHost',{host: 'myhost.com', port: 55127, path: '/'})
Regarding ports, I have allowed 55127 both in UFW and in the router.
For some strange reason, my peer connections and video streaming are working perfectly in the LAN, but failing over the internet - although sometimes they work, for instance in occasions over a 3G mobile network.
While debugging the Peer connection, I stumbled upon these "errors":
PeerJS: VP9 Codec: null
PeerJS: iceConnectionState is disconnected, closing connections to (...)
No errors on the server side, all these are either on the host or on the client.
This issue is similar to this, this and this.
Does anyone have any idea of what could be wrong and how it could be fixed ?
Thanks in advance.
OK, seems that I was suffering from this issue, where a very common NAT/Firewall scenario, in any home-used router would block the ports that my PeerJS server needed to access, thus inhibiting the broker connection, and not allowing the video to be streamed.
The solution was to use an intermediate TURN server in order to override the NAT settings.
var peer = new Peer({host: 'host.com', port: 55127, path: '/', debug:true, config: {'iceServers': [{ url: 'stun:stun.l.google.com:19302' },{ url: 'turn:numb.viagenie.ca', username: 'username#gmail.com', credential: 'password' }]}});

Categories