we are using node v6.11.2 and pooling connection using mysql2 utility/module Below is the snippet .
const mysql = require('mysql2');
const cpmPoolConfig = {
connectionLimit: config.get('mysql_cpm.connectionLimit'),
host: config.get('mysql_cpm.host'),
port: config.get('mysql_cpm.port'),
user: config.get('mysql_cpm.user'),
password: config.get('mysql_cpm.password'),
database: config.get('mysql_cpm.database'),
debug: config.get('mysql_cpm.debug'),
}
const poolCpm = mysql.createPool(cpmPoolConfig);
var getConnectionCpm = function () {
return getConnectionWithRetry(poolCpm).disposer(function (connection) {
serverLOG.debug('Releasing db connection.');
connection.release();
});
}
We want to connect using ssl encryption,I tried below but did not work.
const fs = require('fs');
const cpmPoolConfig = {
connectionLimit: config.get('mysql_cpm.connectionLimit'),
host: config.get('mysql_cpm.host'),
port: config.get('mysql_cpm.port'),
user: config.get('mysql_cpm.user'),
password: encryptionUtil.decrypt(config.get('mysql_cpm.password')),
database: config.get('mysql_cpm.database'),
debug: config.get('mysql_cpm.debug'),
ssl: {
ca: fs.readFileSync('/data/celo/dbcerts/ca.pem'),
cert: fs.readFileSync('/data/celo/dbcerts/client-cert.pem'),
key: fs.readFileSync('/data/celo/dbcerts/client-key.pem')
}
}
Error:
{"name":"searchmember-api","hostname":"lba-ovn-1664.loyalty.com","pid":13728,"level":40,"msg":"Error occurred when getting connection: Error: 140086462822176:error:1409441B:SSL routines:ssl3_read_bytes:tlsv1 alert decrypt error:../deps/openssl/openssl/ssl/s3_pkt.c:1494:SSL alert number 51\n140086462822176:error:140940E5:SSL routines:ssl3_read_bytes:ssl handshake failure:../deps/openssl/openssl/ssl/s3_pkt.c:1217:\n\n at Error (native)","time":"2020-12-23T23:06:31.501Z","src":{"file":"/data/celo/servers/searchmember-api/node_modules/searchmember-api/app/helpers/DbUtils.js","line":111},"v":0} {"name":"searchmember-api","hostname":"lba-ovn-1664.loyalty.com","pid":13728,"level":50,"msg":"Error occurred while getting a db connection for : cpm Error: Error: 140086462822176:error:1409441B:SSL routines:ssl3_read_bytes:tlsv1 alert decrypt error:../deps/openssl/openssl/ssl/s3_pkt.c:1494:SSL alert number 51\n140086462822176:error:140940E5:SSL routines:ssl3_read_bytes:ssl handshake failure:../deps/openssl/openssl/ssl/s3_pkt.c:1217:\n\n at Error (native)","time":"2020-12-23T23:06:31.502Z","src":{"file":"/data/celo/servers/searchmember-api/node_modules/searchmember-api/app/helpers/DbUtils.js","line":76},"v":0} {"name":"searchmember-api","hostname":"lba-ovn-1664.loyalty.com","pid":13728,"level":50,"msg":"Error: 140086462822176:error:1409441B:SSL routines:ssl3_read_bytes:tlsv1 alert decrypt error:../deps/openssl/openssl/ssl/s3_pkt.c:1494:SSL alert number 51\n140086462822176:error:140940E5:SSL routines:ssl3_read_bytes:ssl handshake failure:../deps/openssl/openssl/ssl/s3_pkt.c:1217:\n\n at Error (native)","time":"2020-12-23T23:06:31.503Z","src":{"file":"/data/celo/servers/searchmember-api/node_modules/searchmember-api/app/controllers/SearchMemberController.js","line":26},"v":0}
Moving to help repo as I believe it is more likely there will be a response there.
Your SSL/TLS connection is failing to conduct the handshake, the prelude for all secure communications.
Specifically, Error 51 concerns "Failed handshake cryptographic operation, including being unable to correctly verify a signature, decrypt a key exchange, or validate a finished message." and as a 'decrypt_error' is always fatal (for the attempt to establish the secure connection).
So, the good news is that your client and server initiate the secure communication (that part of the configuration is likely OK), but cannot agree to establish trust during the "Client Hello-Server Hello" messages, and therefore do not even progress to attempt to find a common cipher specification between them. That is, your Node.js client cannot validate the identity of your MySql server based on its certificate that it returns to the client.
Hope that helps interpret the error messages you are returned. I think the problem is server based, rather than client based. I'd pursue your diagnosis at the MySql server end, confirm/debug with a trusted secure client first. Other tools may be more constructive with their error/warning messages for you. Correct the server, or with the information gained in that diagnosis correct the client side configuration accordingly.
@shellberg Thanks for response, really appreciated. we have other applications like spring boot rest apis and another one that using jboss as app server and these applications acting as clients are connecting to same database(acting as server) using same keys/certs and they are able to connect to database over SSL. we are using same cert/key for this application connecting to same database ,only difference is ,this application is node.js
we are using node6.X ,any idea if this could be issue ?
It seems there has been no activity on this issue for a while, and it is being closed in 30 days. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.
Node.js 6 has long reached end of life, but if you are able to reproduce, please open a new issue