e8c9affee1
* add catch for node-forge error handling * update comment * adds changelog * alphabetize attrs and add canParse attr * show alert banner if unable to parse metadata * add test to check info banner renders
31 lines
844 B
JavaScript
31 lines
844 B
JavaScript
import { helper } from '@ember/component/helper';
|
|
import { pki } from 'node-forge';
|
|
|
|
export function parsePkiCert([model]) {
|
|
// model has to be the responseJSON from PKI serializer
|
|
if (!model.certificate) {
|
|
return;
|
|
}
|
|
let cert;
|
|
// node-forge cannot parse EC (elliptical curve) certs
|
|
// set canParse to false if unable to convert a Forge cert from PEM
|
|
try {
|
|
cert = pki.certificateFromPem(model.certificate);
|
|
} catch (error) {
|
|
return {
|
|
can_parse: false,
|
|
};
|
|
}
|
|
const commonName = cert?.subject.getField('CN') ? cert.subject.getField('CN').value : null;
|
|
const expiryDate = cert?.validity.notAfter;
|
|
const issueDate = cert?.validity.notBefore;
|
|
return {
|
|
can_parse: true,
|
|
common_name: commonName,
|
|
expiry_date: expiryDate,
|
|
issue_date: issueDate,
|
|
};
|
|
}
|
|
|
|
export default helper(parsePkiCert);
|