I am making an POST request in Java that requires an ssl certificate and private key combination. I have looked at Java KeyStore and create a .jks file from both the .key and .cert files using the two commands:
winpty openssl pkcs12 -export -in certificate.crt -inkey privatekey.key -out abc.p12
keytool -importkeystore -srckeystore abc.p12 -srcstoretype PKCS12 -destkeystore abc.jks -deststoretype JKS
But this failed the request with a 403 exception. Effectively, I want to perform the following Javascript's functions in java:
function cardBalance(intent, session, response) {
var options = {
key: fs.readFileSync('privatekey.key'),
cert: fs.readFileSync('certificate.crt'),
host: "blah.blah.blah.com',
path: '/abc/def/ghi/jkl/mno/pqr/creditcardsummary',
method: 'POST',
headers: {
'Authorization': 'Bearer ' + session.user.accessToken,
'Content-Type': 'application/json',
'Version': '1.1.0',
'zId': '1234',
'aId': '123456789',
'bId': 'bId',
'AppName': 'AppName'
}
};
var postData = JSON.stringify({
'acctnum': '00002600452999820832'
});
console.log(options);
var req = https.request(options, function (res) {
console.log('Request Credit Card Balance');
var data = '';
res.on('data', function (chunk) {
data += chunk;
});
res.on('end', function () {
data = JSON.parse(data);
console.log(data);
if (data.CreditCardSummary.status === 'SUCCESS') {
var balance = data.balance;
console.log('Balance: ' + balance);
var speechOutput = 'The current balance is $' + balance;
response.tell(speechOutput);
} else {
response.tell('There was a problem getting your card balance.');
}
});
});
req.on('error', function (e) {
console.log('An Error Occurred when calling the Gateway. ' + e);
response.tell(e);
});
req.write(postData);
req.end();
}