Augment parseX509Output to also work with libressl

LibreSSL uses a different output separated and semantics, which broke
the X509 parser. With some slight modifications both can be supported.
This commit is contained in:
Will Rouesnel
2023-05-31 23:57:49 +10:00
parent 4d491b2d76
commit 0969cd76be

View File

@@ -741,10 +741,11 @@ const internalCertificate = {
*/
parseX509Output: (line, prefix) => {
// Remove the subject= part
const subject_value = line.slice(prefix.length);
const subject_value = line.slice(prefix.length).trim();
const subject = subject_value.split(/,(?=(?:(?:[^"]*"){2})*[^"]*$)/)
.map( (e) => { return e.trim().split(' = ', 2); })
const subject = subject_value.split(/[,/](?=(?:(?:[^"]*"){2})*[^"]*$)/)
.filter( (e) => { return e.length > 0; } )
.map( (e) => { return e.trim().split('=', 2).map( (p) => { return p.trim(); }); })
.reduce((obj, [key, value]) => {
obj[key] = value.replace(/^"/, '').replace(/"$/, '');
return obj;