Friday, April 20, 2018

Sending pfx or p12 certificate using javascript


Recently I was stuck with a task where I needed to send .p12 file along with the request and since this certificate is different from the regular one, it will have to be sent in a different way.

The testing framework was in Javascript and we used chakram as the module to send the request which is using requests module underneath. It took some time to find out a working solution which I am sharing here. Hope this will help you.

Code
 var fs = require('fs');  
 var options = {  
   headers: { 'authrization':'' },  
   agentOptions: {  
     pfx: fs.readFileSync('certfile.p12'),  
     passphrase: 'passphrase',  
     securityOptions: 'SSL_OP_NO_SSLv3'  
   }  
 };