MySQL Forums
Forum List  »  Connector/Node.js

Understanding SSL connection with MySQL protocol
Posted by: austin cheney
Date: February 13, 2023 07:21AM

I am writing a MySQL connection utility from scratch in Node.js in order to better understand the details of the protocol and extend my knowledge of Node TLS. The problem I am having is how to execute the upgrade from a Net socket to a TLS socket.

Following the MySQL documentation I can create a socket and connect to MySQL, get back the greeting packet and parse it. I believe I am formulating the SSL Request packet properly:

<Buffer 20 00 00 01 ff ff ff cf 00 00 ff ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00>

I cannot seem to get the SSL connection correct though.

I am performing the following:

```javascript
let secureSocket = null;
const context = {
ca: "ca cert text",
cert: "cert text",
minVersion: "TLSv1.3"
};

socket.write(sslRequest);

secureSocket = new TLSSocket(socket, {
rejectUnauthorized : true,
requestCert : true,
secureContext : context,
isServer : false
});

connectSecure({
host: env[environment].host,
port: env[environment].port,
secureContext: sslContext,
socket: secureSocket
});
```


I am getting this error:

node:events:491
throw er; // Unhandled 'error' event
^

Error: Client network socket disconnected before secure TLS connection was established
at connResetException (node:internal/errors:717:14)
at TLSSocket.onConnectEnd (node:_tls_wrap:1600:19)
at TLSSocket.emit (node:events:525:35)
at endReadableNT (node:internal/streams/readable:1359:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on TLSSocket instance at:
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
code: 'ECONNRESET',
path: undefined,
host: 'host location address',
port: 3306,
localAddress: undefined
}

Node.js v19.4.0


Any guidance or suggestions?

Options: ReplyQuote


Subject
Written By
Posted
Understanding SSL connection with MySQL protocol
February 13, 2023 07:21AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.