NodeJS keep throwing `UNABLE_TO_VERIFY_LEAF_SIGNATURE` no matter what - javascript

I have a basic nodeJS application that connects to a server via a secured websocket (ws library) connection. When connecting the server keeps throwing a UNABLE_TO_VERIFY_LEAF_SIGNATURE error. I have no control over the server, it's external. The endpoint starts with wss:// (not sure if it makes a difference)
I have tried so many things, but none of them seem to work:
rejectUnauthorized: false works, but connection breaks after x time with 1006
export NODE_EXTRA_CA_CERTS=[your CA certificate file path] doesn't work
npm config set cafile [your CA certificate file path] doesn't work
npm modules syswide-cas or node-ssl-root-cas don't work
adding ca: [fs.readFileSync("ca.ca-bundle", {encoding: 'utf-8'})] in socket options doesn't work
However, when I navigate in a browser to the endpoint, the connection is valid and secured. I tried extracting the certificates from the browser and included into nodeJS, no results, same error. The same goes for when I use the website https://whatsmychaincert.com/ to get the certificates ...
Basic code:
this.websocket = new WebSocket(this.apiUrl, this.applicationId, {
rejectUnauthorized: true,
});
...
this.websocket.on('open', () => {
console.log('Connection successfully opened');
});
this.websocket.on('error', error => {
console.log(error);
});
No matter what I do, it seems that regardless the included certificates NodeJS keeps throwing me the UNABLE_TO_VERIFY_LEAF_SIGNATURE error.
Somebody any idea what is happening?

After days and days of trying to solve this I finally managed to solve this issue!
I was using the wrong certificate chain the whole time. The endpoint which I'm connecting to has a wss:// prefix. But I was getting the certificates from the url with the https:// prefix. Apparently this has a different certificate chain.

Related

connecting to Robson server

Error attempting to connect to function of contract deployed to Robson server.
Error: Invalid JSON RPC response: {"size":0,"timeout":0}
This is my code.
const call = () => {
const CONTRACT_ADDRESS = "0xEF7D71764b5fe95f8584D70bF3B1Ead15CAF89eD";
const address = "";
const fundRasing = new web3.eth.Contract(abi, CONTRACT_ADDRESS);
fundRasing.methods.beneficiary().call({from: address}).then(console.log);
};
call();
please help me
It seems an issue with connecting to your server or an issue with geth (or the Ethereum client) configuration. But web3.js did not report the issue clearly.
And to confirm that the issue is with the geth configuration (or the Ethereum client you are using), and how it is being accessed, try running geth with --rpcaddr 0.0.0.0 and --rpccorsdomain "*". And you are supposed to not face this error again. If this did not work try running geth on your local machine to be able to investigate.
However, it is extremely dangerous to have this mentioned configuration (--rpcaddr 0.0.0.0 and --rpccorsdomain "*"). But I recommend you do this in a test machine to confirm the issue's root cause. But for a production environment, you would need different setups and configurations according to your exact case.
You nay follow up with the issue here: https://github.com/web3/web3.js/issues/5661#issuecomment-1332506572

Connecting SOCKET.IO-client (angular) to SOCKET.IO-server (node.js) over https net::ERR_CONNECTION_CLOSED

Our website has been running on an internal test machine where it could be accessed by all computers inside the network.
Now we want to deploy this website on a webserver (Apache2) to make it available to our clients. We want to use https and this is where we encountered a problem.
The Socket.io client canĀ“t connect to the node.js server since switching to https. We are using a signed certificate from a trusted CA. I have tried every solution I could find but none seem to work for our case.
Constructor used with ngx-socket-io in angular:
constructor() {
super({url: 'https://mywebPage.com:8080',options:{secure: true, origin: '*', transport:['websocket']}})
}
Our certificate seems to be valid since it works for our angular page. We are also able to make HTTPS GET/POST requests to our API which is located on the same server.
node.js socket.io server code:
var options = {
key: fs.readFileSync('/etc/apache2/folder/certificate.com.key'),
cert: fs.readFileSync('/etc/apache2/folder/certificate.com.public.crt'),
ca: fs.readFileSync('/etc/apache2/folder/certificate-intermediate.crt'),
requestCert: true
};
let server = require('https').createServer(options);
let io = require('socket.io')(server);
server.listen(8080);
console.log("Server started on Port 8080");
the client tries to connect to the socket-Server but fails and gets the net::ERR_CONNECTION_CLOSED the rest of the web page loads fine and has a valid certificate
We have also tested to see if the port on the web server is accesible and it seems to be open in netstat and nma.
If any more information is needed I am glad to provide.
EDIT: have tested the setup with rejectUnauthorized:false on the client side but that does not change the error.
similar stack overflow questions which i have considered in solving the problem:
socket.io net::ERR_CONNECTION_CLOSED
Setup Server-Server SSL communication using socket.io in node.js
EDIT 2: added requestCert: false, rejectUnauthorized: false into my node.js options.
Now the previous Error has been resolved now:
error during WebSocket handshake: Unexpected response code: 400

Electron doesnt execute https call to local spring server, curl works

I'm simply trying to connect to a local Spring configured with SSL / TLS 1.2.
Context (Server): Server is built with Spring, logs when creating a request via curl. Also requires a certificate from the client (X.509 certificate based authentication)
Client (CURL, command-line):
Works fine!
Client (Electron):
When the code below gets executed nothing happens. No requests are being made to the spring (nothing logs), nor is any error occuring. Nothing. Electron is such a drag to debug..
Code:
let options = {
hostname: 'localhost',
port: 8443,
path: '/',
cert: fs.readFileSync(global.relativePaths.config + 'client.crt'),
key: fs.readFileSync(global.relativePaths.config + 'clientprivate.key'),
passphrase: '[phrase_here]',
rejectUnauthorized: false,
requestCert: true
};
let request = https.request(options);
request.on('error', () => {
console.log("Error!");
})
Also, this is just localhost, hence the rejectUnauthorized - I'm working with self-signed certificates until ready for production. :)
Thank you in advance. :)
EDIT:
using the test-code on the wiki (call to github) outputs with no problem.. what could it be?...
also, im doing this on the main process (not on the renderer)
Try using the http-client library like [axios][1]. axios is a promise-based HTTP client for the browser and node.js. It worths giving a try to most used libraries like axios, it's simple to use. If the issue still persists, try setting the User-Agent header in your request.

WebSockets working on localhost, but do not work on remote Ubuntu host

I have two applications - browser based client and NodeJS based server that are both communicating using WebSockets (I'm using ColyseusJS library). Problem is, that everything works fine while I'm testing them on localhost but when I deploy the application to my Ubuntu VPS server it stops working.
The message I receive in the browser while trying to connect is:
WebSocket connection to 'ws://X.X.X.X:8001/?colyseusid=' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET
So it reaches the server (because when server is disabled the message is "Error in connection establishment: net::ERR_CONNECTION_REFUSED") but it looks like it fails on Upgrade connection operation.
What is strange is that I managed to make it work yesterday (don't know how exactly), but had so much mess on my VPS that I decided to revert machine to it's starting state. After that it stopped working (code is unchanged). Maybe there are some additional dependencies that I need to install in order to make it work on my Ubuntu Server?
I would really appreciate your help.
Have you tried to port forward the port to the ip address of the said VPS in your router config? And also check out the firewalls.

WebSocket connection failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

I am new to WebRTC and WebSockets and was following this tutorial to create a WebRTC demo project, but I am unable to create a WebSocket connection. I have followed the same steps as mentioned in the project.
His project is running on port 8080 and he mentioned ws://localhost:9090. My project is running on port 8081, but I copied his URL ws://localhost:9090 because I didn't know the significance of 9090 and I received this error and my server is node.js. i changed local host to 8081 as well but then i am getting hand shake error.
WebSocket connection to 'ws://localhost:9090/' failed: Error in
connection establishment: net::ERR_CONNECTION_REFUSED.
Chrome doesn't allow unsecure websocket (ws) connections to localhost (only wss, so you should setup a TLS certificate for your local web/websocket server).
However the same should work fine with Firefox.
You need to use ws://yourIp:9090/, where yourIP is like 192.168.?.?.
Usually WebRTC requires a secure connection (that is https).
The error you have got is due to TLS/SSL certificates occupied, may be they are not properly configured in your project.
Provide a valid TLS/SSL certificate and also configure it correctly in project, then it will work without the above error.
try to change the port to 8080
const ws = new WebSocket('ws://localhost:8080/chat')
I guess this is a generic websocket issue.
Change the url to a dynamic name using the built-in location.host variable and change the protocol to secure websocket wss if you have set-up the TLS:
const ws = new WebSocket("wss://" + location.host + "/")
Port 9090 is used by reactotron. Probably you are using it in your project and your app cannot connect with reactotron because it is closed. Just open reactotron and the error will disappear.
also you could easily change the mappings of IP addresses to host names,
on windows go to C:\Windows\System32\drivers\etc\hosts and uncomment this line
127.0.0.1 localhost
save and restart.
WebSocket connection to 'ws://localhost:8080/' failed
Must ensure server file is running
I git this above problem
maybe you forgot to start websocket server, check it again, with configuration in my project, run:
php artisan websocket:init

Categories

Resources