1

I am trying to use SSL secured api which Two Way SSL Authentication. Have already created self signed certificate using keytool -genkey command and created 3 key files (selfsigned.crt , selfsigned.p12, selfsigned.jks) which is shared with API provider. and one UATSKY.crt certificate given by API provider is added to my trust store on mac. now when i try to access this api from post man it gives me pop up to select certificate after which it makes successful call api and get positive response.how do i achieve same in Node JS application.

I tried using https.createserver and passing ptivate key and certificate to the craeteserver

var app = express();

app.use(bodyParser.urlencoded({

extended: false

}));

app.use(bodyParser.json());

app.use(bodyParser.json({ limit: '50mb' }));

app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));

app.use(cors());


var privateKey =             
fs.readFileSync('./private/selfsignedpayeazzy.p12');
var certificate = fs.readFileSync('./private/selfsignedpayeazzy.crt');
var credentials = { 
    key: privateKey,
    cert: certificate
 };

https.createServer(credentials, app).listen(port);

This is gives me following error

_tls_common.js:112
  c.context.setCert(cert);
            ^

Error: error:0906D06C:PEM routines:PEM_read_bio:no start line
at Object.createSecureContext (_tls_common.js:112:17)
at Server.setSecureContext (_tls_wrap.js:960:27)
at Server (_tls_wrap.js:850:8)
at new Server (https.js:61:14)
at Object.createServer (https.js:83:10)

not able to add this certificates to the application.
  • I'm guessing you know to check this already, but... is that certificate in PEM format? Can you show the command line you used to generate it? – Brad Dec 31 '18 at 04:42
  • You need to convert those files to PEM format. This might help: https://stackoverflow.com/a/15144560/1531054 – S.D. Dec 31 '18 at 10:54
  • @Brad it was not in PEM format keytool -genkey -alias www.secureapi.com -keyalg RSA -keystore selfsigned.jks -validity 365 -keysize 2048 keytool -list -alias www.secureapi.com -v -keystore selfsigned.jks keytool -export -alias www.yesbank.com -file selfsigned.crt -keystore selfsigned.jks –  Jan 01 '19 at 09:46
  • @S.D. I tried converting those file to PEM, var privateKey = fs.readFileSync('./private/selfsigned.crt.pem'); var certificate = fs.readFileSync('./private/selfsigned.key.pem'); var credentials = { key: privateKey, cert: certificate }; and added still gives the same error. –  Jan 01 '19 at 09:48

0 Answers0