How to use TLSv1.3 with nodejs 10.x - node.js

I was trying to make an external api call using https and got the following error.
Error: Client network socket disconnected before secure TLS connection was established
at TLSSocket.onConnectEnd (_tls_wrap.js:1092:19)
at Object.onceWrapper (events.js:286:20)
at TLSSocket.emit (events.js:203:15)
at endReadableNT (_stream_readable.js:1129:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
code: 'ECONNRESET',
On further investigation I came to know that my api endpoint uses TLSv1.3 and since I am using nodejs 10.x, I need to set
tls.DEFAULT_MAX_VERSION = 'TLSv1.3';
after which it is throwing the following error
TypeError [ERR_TLS_INVALID_PROTOCOL_VERSION]: "TLSv1.3" is not a valid maximum TLS protocol version
at toV (_tls_common.js:49:9)
at new SecureContext (_tls_common.js:74:23)
at Object.createSecureContext (_tls_common.js:100:13)
at Object.connect (_tls_wrap.js:1127:48)
at Agent.createConnection (https.js:120:22)
at Agent.createSocket (_http_agent.js:227:26)
at Agent.addRequest (_http_agent.js:185:10)
at new ClientRequest (_http_client.js:249:16)
at request (https.js:289:10)
at Object.get (https.js:293:15)

Related

Using REST API for Jira with node

I'd like to collect information from privately installed Jira server but I've got a problem doing it.
Of course, I can connect the the site using my Chrome browser and it also find calling REST API from the browser address bar - https://myjiraaddr/rest/api/2/search
Sending REST API request using curl works okay with -u option(username:password) from command line.
But if I try it using nodejs and got an error says self signed certificate in certificate chain.
Can anybody please explain what makes these differences and how to fix it?
Thanks in advance :)
JiraApi = require('jira').JiraApi;
var jira = new JiraApi('https', 'myjiraaddress', 443, 'username', 'password', '2.0.alpha1');
jira.getCurrentUser(function(error, issue) {
console.log(error);
});
it prints...
Status: Error: self signed certificate in certificate chain
And error if I use jira-client npm package...
RequestError: Error: self signed certificate in certificate chain
at new RequestError (/Users/hyoon/dev/node/work-tracker/node_modules/request-promise-core/lib/errors.js:14:15)
at Request.plumbing.callback (/Users/hyoon/dev/node/work-tracker/node_modules/request-promise-core/lib/plumbing.js:87:29)
at Request.RP$callback [as _callback] (/Users/hyoon/dev/node/work-tracker/node_modules/request-promise-core/lib/plumbing.js:46:31)
at self.callback (/Users/hyoon/dev/node/work-tracker/node_modules/request/request.js:185:22)
at Request.emit (events.js:310:20)
at Request.onRequestError (/Users/hyoon/dev/node/work-tracker/node_modules/request/request.js:877:8)
at ClientRequest.emit (events.js:310:20)
at TLSSocket.socketErrorListener (_http_client.js:426:9)
at TLSSocket.emit (events.js:310:20)
at emitErrorNT (internal/streams/destroy.js:92:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
cause: Error: self signed certificate in certificate chain
at TLSSocket.onConnectSecure (_tls_wrap.js:1474:34)
at TLSSocket.emit (events.js:310:20)
at TLSSocket._finishInit (_tls_wrap.js:917:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:687:12) {
code: 'SELF_SIGNED_CERT_IN_CHAIN'
},
error: Error: self signed certificate in certificate chain
at TLSSocket.onConnectSecure (_tls_wrap.js:1474:34)
at TLSSocket.emit (events.js:310:20)
at TLSSocket._finishInit (_tls_wrap.js:917:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:687:12) {
code: 'SELF_SIGNED_CERT_IN_CHAIN'
},
If you're dealing with a self-signed certificate you can bypass the strict-check by setting the strictSSL option to false, as described in the docs:
const jira = new JiraApi('https', 'myjiraaddress', 443, 'username', 'password', '2.0.alpha1', false, false);
If you do not want to bypass the check, you probably have to fork the library and modify the way the request is set up in order to add your certificate. See this question for more information: How do I use the node.js request module to make an SSL call with my own certificate?

Vercel Serverless function with nuxtjs ECONNRESET Client network socket disconnected before secure TLS connection was established

so i'm having this problem on a nuxt implementation with vercel, at random moments the site doesn't load and throws a 502 http error
this is the stacktrace of vercel:
ERROR Unhandled Promise Rejection {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"FetchError: request to {api_url} failed, reason: Client network socket disconnected before secure TLS connection was established","reason":{"errorType":"FetchError","errorMessage":"request to {api_url} failed, reason: Client network socket disconnected before secure TLS connection was established","code":"ECONNRESET","message":"request to {api_url} failed, reason: Client network socket disconnected before secure TLS connection was established","type":"system","errno":"ECONNRESET","stack":["FetchError: request to {api_url} failed, reason: Client network socket disconnected before secure TLS connection was established"," at ClientRequest.<anonymous> (server.js:16011:11)"," at ClientRequest.emit (events.js:315:20)"," at ClientRequest.EventEmitter.emit (domain.js:483:12)"," at TLSSocket.socketErrorListener (_http_client.js:426:9)"," at TLSSocket.emit (events.js:315:20)"," at TLSSocket.EventEmitter.emit (domain.js:483:12)"," at emitErrorNT (internal/streams/destroy.js:92:8)"," at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)"," at processTicksAndRejections (internal/process/task_queues.js:84:21)"]},"promise":{},"stack":["Runtime.UnhandledPromiseRejection: FetchError: request to {api_url} failed, reason: Client network socket disconnected before secure TLS connection was established"," at process.<anonymous> (/var/runtime/index.js:35:15)"," at process.emit (events.js:327:22)"," at process.EventEmitter.emit (domain.js:483:12)"," at processEmit [as emit] (/var/task/node_modules/signal-exit/index.js:161:32)"," at processPromiseRejections (internal/process/promises.js:209:33)"," at processTicksAndRejections (internal/process/task_queues.js:98:32)"]}
Unknown application error occurred
So the error it's about a connection with the api, for what i found this is a Node error but my api is developed on Laravel so i'm really lost
Thanks for the help
I ran into this issue (with a Next.js project on Vercel) and fixed it. I was calling an external API but forgot to await one of the handlers, so the Lambda eventually stopped waiting for the API call response once my code finished running.

cannot connect to SQLExpress usign node.js

I am using SQL Server (SQL EXPRESS) 2005 9.0.3042
I have poured through lots of examples.
Made sure TCP port 1433 open for all IP.
Made sure browser is started
Tried all kinds of config settings
using tedious or mssql
Just trying to find something that will work !!
But all I get is the following errors
ConnectionError: Failed to connect to localhost:1433 - Cannot call write after a stream was destroyed
at ConnectionError (C:\git\adv_energy\sql_node_js\node_modules\tedious\lib\errors.js:13:12)
at Connection.socketError (C:\git\adv_energy\sql_node_js\node_modules\tedious\lib\connection.js:1628:56)
at Socket.<anonymous> (C:\git\adv_energy\sql_node_js\node_modules\tedious\lib\connection.js:1395:14)
at Socket.emit (events.js:327:22)
at errorOrDestroy (internal/streams/destroy.js:108:12)
at onwriteError (_stream_writable.js:418:5)
at onwrite (_stream_writable.js:445:5)
at doWrite (_stream_writable.js:399:11)
at writeOrBuffer (_stream_writable.js:387:5)
at Socket.Writable.write (_stream_writable.js:318:11) {
code: 'ESOCKET'
}

Node.js Error: Unexpected server response: 301 - Running a Node.js Websocket server on Namecheap Webhost

I'm trying to setup a Node.js Websocket server over at my webhost (Namecheap). However, I am getting this error:
events.js:292
throw er; // Unhandled 'error' event
^
Error: Unexpected server response: 301
at ClientRequest.<anonymous> (D:\****\node_modules\ws\lib\websocket.js:576:7)
at ClientRequest.emit (events.js:315:20)
at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:596:27)
at HTTPParser.parserOnHeadersComplete (_http_common.js:119:17)
at TLSSocket.socketOnData (_http_client.js:469:22)
at TLSSocket.emit (events.js:315:20)
at addChunk (_stream_readable.js:295:12)
at readableAddChunk (_stream_readable.js:271:9)
at TLSSocket.Readable.push (_stream_readable.js:212:10)
at TLSWrap.onStreamRead (internal/stream_base_commons.js:186:23)
Emitted 'error' event on WebSocket instance at:
at abortHandshake (D:\****\node_modules\ws\lib\websocket.js:694:15)
at ClientRequest.<anonymous> (D:\****\node_modules\ws\lib\websocket.js:576:7)
[... lines matching original stack trace ...]
at TLSSocket.Readable.push (_stream_readable.js:212:10)
The code for the client and server came from here:
https://github.com/websockets/ws#Simple server
https://github.com/websockets/ws#sending-and-receiving-text-data
with ws://www.host.com/path changed to ws://<mydomainname>/<dir1>/<dir2>
Both client and server code runs properly when run locally. Http related code runs properly when used on my webhost. I am trying to get the client code to run locally and connect via websockets to my server hosted at Namecheap.
I suspect something related to the server is preventing connection. I'd ask support but I doubt if they can resolve this. Maybe there's a locked feature or something? Is there something else I could have missed?
Websockets cannot work on Namecheap's hosted servers. Their incoming ports are blocked and cannot be opened for security reasons per their customer's support.
If anyone is looking for a solution just in case, try out a Heroku free account.

NodeJs Unable to make Self Signed Cert work with windows 10

I've been working on this issue on and off for a few months now I am a point where I need this to work. I have solved this issue with git but not nodejs. An Internal url we have is using a Self-Signed cert because its internal use only. I need to use node to communicate with the url. I've tried to set NODE_EXTRA_CA_CERTS many times with nothing working. One way was suggected to set the environemnt value this way
[Environment]::SetEnvironmentVariable("NODE_EXTRA_CA_CERTS", "C:\Temp\NodeCertFix\selfSignedCert.cer", "Machine") I have confirmed that the cert is a base64 cert, same as a .pem in Linux. No Matter what i do i can't get it to work.
events.js:180
throw er; // Unhandled 'error' event
^
Error: unable to get local issuer certificate
at TLSSocket.onConnectSecure (_tls_wrap.js:1317:34)
at TLSSocket.emit (events.js:203:13)
at TLSSocket._finishInit (_tls_wrap.js:792:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:606:12) Emitted 'error' event at:
at TLSSocket.socketErrorListener (_http_client.js:399:9)
at TLSSocket.emit (events.js:203:13)
at emitErrorNT (internal/streams/destroy.js:91:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
at processTicksAndRejections (internal/process/task_queues.js:77:11) { code:
'UNABLE_TO_GET_ISSUER_CERT_LOCALLY' }
Did you try the nodejs-self-signed-certificate-example package from npm?

Resources