So I have a solution. This is based on https://github.com/april/certainly-something (Which itself is what Mozilla’s certificate viewer is based on)
You can create a downloadable link which contains the PEM file through the rawDER.
The steps below are to create a pem file for the certificate chain.
let chain = securityInfo.certificates; // securityInfo is the object returned by webRequest.getSecurityInfo
let builtChain = chain.map(cert => { return new Uint8Array(cert.rawDER).buffer });
let modifiedChain = builtChain.map(cert => parse(cert));
function parse(certificate)
{
const certBTOA = window.btoa(String.fromCharCode.apply(null, new Uint8Array(certificate))).match(/.{1,64}/g).join('\r\n');
const pURI = encodeURI(`-----BEGIN CERTIFICATE-----\r\n${certBTOA}\r\n-----END CERTIFICATE-----\r\n`);
return pURI;
}
let dString = "data:,"
for(let p of modifiedChain)
{
dString += p;
}
At this stage dString is the downloadable link. In order to utilize it you need to make an anchor (via html or document.createElement(‘a’)) with dString as the href. In browser you need to right click the link and choose “save link as file”. This is how the mozilla certificate viewer lets you download certificates as well.