Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var myArgs = process.argv.slice(2); // Remove redundant parms
if (myArgs[0]) {
qMgr = myArgs[0];
}
if (myArgs[1]) {
connName = myArgs[1];
}
// The program starts here.
// Connect to the queue manager.
console.log("Sample AMQSCONNTLS.JS start");
// Create default MQCNO and MQSCO structures
var cno = new mq.MQCNO();
var sco = new mq.MQSCO();
// Add authentication via the MQCSP structure
var csp = new mq.MQCSP();
csp.UserId = "mqguest";
csp.Password = "passw0rd";
// Make the MQCNO refer to the MQCSP so it knows to use the structure
cno.SecurityParms = csp;
// And use the MQCD to programatically connect as a client
// First force the client mode
cno.Options |= MQC.MQCNO_CLIENT_BINDING;
// And then fill in relevant fields for the MQCD
var cd = new mq.MQCD();
cd.ConnectionName = connName;
cd.ChannelName = "SYSTEM.SSL.SVRCONN";
cd.SSLCipherSpec = MQDetails.CIPHER;
cd.SSLClientAuth = MQC.MQSCA_OPTIONAL;
}
// Make the MQCNO refer to the MQCD
cno.ClientConn = cd;
}
// The location of the KeyRepository is not specified in the CCDT, so regardless
// of whether a CCDT is being used, need to specify the KeyRepository location
// if it has been provided in the environment json settings.
if (MQDetails.KEY_REPOSITORY) {
debug_info('Key Repository has been specified');
// *** For TLS ***
var sco = new mq.MQSCO();
sco.KeyRepository = MQDetails.KEY_REPOSITORY;
// And make the CNO refer to the SSL Connection Options
cno.SSLConfig = sco;
}
// Do the connect, including a callback function
mq.Connx(MQDetails.QMGR, cno, function(err, hConn) {
if (err) {
console.log("MQCONN ended with reason code " + err.mqrc);
} else {
console.log("MQCONN to %s successful ", MQDetails.QMGR);
// Define what we want to open, and how we want to open it.
var sd = new mq.MQSD();
cd.SSLCipherSpec = MQDetails.CIPHER;
cd.SSLClientAuth = MQC.MQSCA_OPTIONAL;
}
// Make the MQCNO refer to the MQCD
cno.ClientConn = cd;
}
// The location of the KeyRepository is not specified in the CCDT, so regardless
// of whether a CCDT is being used, need to specify the KeyRepository location
// if it has been provided in the environment json settings.
if (MQDetails.KEY_REPOSITORY) {
debug_info('Key Repository has been specified');
// *** For TLS ***
var sco = new mq.MQSCO();
sco.KeyRepository = MQDetails.KEY_REPOSITORY;
// And make the CNO refer to the SSL Connection Options
cno.SSLConfig = sco;
}
debug_info('Attempting Connection to MQ Server');
mq.Connx(MQDetails.QMGR, cno, function(err, hConn) {
debug_info('Inside Connection Callback function');
if (err) {
debug_warn('Error Detected making Connection', err);
} else {
debug_info("MQCONN to %s successful ", MQDetails.QMGR);
// Open up the Dynamic Response queue
// SVRCONN is defined on the queue manager.
cd.SSLCipherSpec = this.MQDetails.CIPHER;
cd.SSLClientAuth = MQC.MQSCA_OPTIONAL;
// And make the CNO refer to the SSL Connection Options
mqcno.SSLConfig = sco;
}
// Make the MQCNO refer to the MQCD
mqcno.ClientConn = cd;
}
if (this.MQDetails.KEY_REPOSITORY) {
debug_info('Key Repository has been specified');
// *** For TLS ***
var sco = new mq.MQSCO();
// *** For TLS ***
// Set the SSL/TLS Configuration Options structure field that
// specifies the keystore (expect to see a .kdb, .sth and .rdb
// with the same root name). For this program, all we need is for
// the keystore to contain the signing information for the queue manager's
// cert.
sco.KeyRepository = this.MQDetails.KEY_REPOSITORY;
// And make the CNO refer to the SSL Connection Options
mqcno.SSLConfig = sco;
}
return Promise.resolve(mqcno);
}
cd.SSLCipherSpec = MQDetails.CIPHER;
cd.SSLClientAuth = MQC.MQSCA_OPTIONAL;
}
// Make the MQCNO refer to the MQCD
cno.ClientConn = cd;
}
// The location of the KeyRepository is not specified in the CCDT, so regardless
// of whether a CCDT is being used, need to specify the KeyRepository location
// if it has been provided in the environment json settings.
if (MQDetails.KEY_REPOSITORY) {
debug_info('Key Repository has been specified');
// *** For TLS ***
var sco = new mq.MQSCO();
sco.KeyRepository = MQDetails.KEY_REPOSITORY;
// And make the CNO refer to the SSL Connection Options
cno.SSLConfig = sco;
}
debug_info('Attempting Connection to MQ Server');
mq.Connx(MQDetails.QMGR, cno, function(err, hConn) {
debug_info('Inside Connection Callback function');
if (err) {
debug_warn('Error Detected making Connection', err);
} else {
debug_info("MQCONN to %s successful ", MQDetails.QMGR);
// Define what we want to open, and how we want to open it.
if (MQDetails.KEY_REPOSITORY) {
debug_info('Will be running in TLS Mode');
cd.SSLCipherSpec = MQDetails.CIPHER;
cd.SSLClientAuth = MQC.MQSCA_OPTIONAL;
}
// Make the MQCNO refer to the MQCD
cno.ClientConn = cd;
}
if (MQDetails.KEY_REPOSITORY) {
debug_info('SCO object to locate key repository for TLS');
// *** For TLS ***
let sco = new mq.MQSCO();
sco.KeyRepository = MQDetails.KEY_REPOSITORY;
// And make the CNO refer to the SSL Connection Options
cno.SSLConfig = sco;
}
return Promise.resolve();
}
cd.SSLCipherSpec = MQDetails.CIPHER;
cd.SSLClientAuth = MQC.MQSCA_OPTIONAL;
}
// Make the MQCNO refer to the MQCD
cno.ClientConn = cd;
}
// The location of the KeyRepository is not specified in the CCDT, so regardless
// of whether a CCDT is being used, need to specify the KeyRepository location
// if it has been provided in the environment json settings.
if (MQDetails.KEY_REPOSITORY) {
debug_info('Key Repository has been specified');
// *** For TLS ***
var sco = new mq.MQSCO();
sco.KeyRepository = MQDetails.KEY_REPOSITORY;
// And make the CNO refer to the SSL Connection Options
cno.SSLConfig = sco;
}
// Do the connect, including a callback function
mq.Connx(MQDetails.QMGR, cno, function(err, hConn) {
if (err) {
debug_warn('Error Detected making Connection', err);
} else {
debug_info("MQCONN to %s successful ", MQDetails.QMGR);
// Define what we want to open, and how we want to open it.
var od = new mq.MQOD();
od.ObjectName = MQDetails.QUEUE_NAME;
od.ObjectType = MQC.MQOT_Q;
if (MQDetails.KEY_REPOSITORY) {
debug_info('Will be running in TLS Mode');
cd.SSLCipherSpec = MQDetails.CIPHER;
cd.SSLClientAuth = MQC.MQSCA_OPTIONAL;
}
// Make the MQCNO refer to the MQCD
cno.ClientConn = cd;
}
if (MQDetails.KEY_REPOSITORY) {
debug_info('Key Repository has been specified');
// *** For TLS ***
var sco = new mq.MQSCO();
sco.KeyRepository = MQDetails.KEY_REPOSITORY;
// And make the CNO refer to the SSL Connection Options
cno.SSLConfig = sco;
}
debug_info('Attempting Connection to MQ Server');
mq.Connx(MQDetails.QMGR, cno, function(err, hConn) {
if (err) {
debug_warn('Error Detected making Connection', err);
} else {
debug_info("MQCONN to %s successful ", MQDetails.QMGR);
// Define what we want to open, and how we want to open it.
//