Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Format TLS certficiate with new line

We extract raw tls certificate and we need to pass the certificate to a program with proper format of the cert - new line characters to extract information about certificate.

Used below snippet in js and trying to get complete string but facing issues.

Any javascript expert plz advice.


var rawcert = context.getVariable("request.header.X-Tls.ssl_client_raw_cert");
var newrawcert= function(splitArr){  
var parseArr=[]; 
 splitArr = splitArr.split(' ');
  print (splitArr);  
for (var i=0; i <splitArr.length;i++){
  if (i === 0 || i ===1 || i=== splitArr.length -2 || i === splitArr.length -1)  
continue; 
 else   
parseArr.push(splitArr[i]); 
 }  
var beginStr='-----BEGIN CERTIFICATE-----';  
var endStr='-----END CERTIFICATE-----';  
parseArr.unshift(beginStr);  
parseArr.push(endStr);  
parseArr.join("\n");  
return parseArr;   
}
var result = newrawcert(rawcert);
0 4 499
4 REPLIES 4