1
0
Fork 0

add parseCertificate typescript bindings

refactor/models
Matthew 2019-12-27 21:55:21 -05:00
parent 609079fc12
commit f229e4a825
No known key found for this signature in database
GPG Key ID: 766BE43AE75F7559
1 changed files with 61 additions and 0 deletions

View File

@ -0,0 +1,61 @@
import { Client } from '..';
export interface Certificate {
subject: {
commonName: string,
emailAddress: string
organizationName: string,
organizationalUnitName: string,
countryName: string,
},
issuer: {
commonName: string
emailAddress: null,
organizationName: string,
organizationalUnitName: string,
countryName: string,
},
extensions: {
keyUsage: '[ Not implemented by executable ]',
extendedKeyUsage: string[],
certificatePolicies: string[],
},
serial: string,
fingerPrint: string,
signatureAlgorithm: string,
publicKeyAlgorithm: string,
notBefore: Date,
notAfter: Date,
}
export default async function parseCertificate(client: Client, pathToCertificate: string): Promise<Certificate> {
const result = await client.util.exec(`${__dirname}/../bin/checkCertificate ${pathToCertificate}`);
const parsedObject = JSON.parse(result);
return {
subject: {
commonName: parsedObject.RawParse.Subject.CommonName,
emailAddress: parsedObject.AbstractParse.EmailAddress,
organizationName: parsedObject.RawParse.Subject.Organization[0],
organizationalUnitName: parsedObject.RawParse.Subject.OrganizationalUnit[0],
countryName: parsedObject.RawParse.Subject.Country[0],
},
issuer: {
commonName: parsedObject.RawParse.Issuer.CommonName,
emailAddress: null,
organizationName: parsedObject.RawParse.Issuer.Organization[0],
organizationalUnitName: parsedObject.RawParse.Issuer.OrganizationalUnit[0],
countryName: parsedObject.RawParse.Issuer.Country[0],
},
extensions: {
keyUsage: '[ Not implemented by executable ]',
extendedKeyUsage: parsedObject.AbstractParse.ExtendedKeyUsage,
certificatePolicies: parsedObject.AbstractParse.PolicyIdentifiers,
},
serial: parsedObject.AbstractParse.SerialNumber,
fingerPrint: parsedObject.AbstractParse.FingerPrint,
signatureAlgorithm: parsedObject.AbstractParse.SignatureAlgorithm,
publicKeyAlgorithm: parsedObject.AbstractParse.PublicKeyAlgorithm,
notBefore: new Date(parsedObject.RawParse.NotBefore),
notAfter: new Date(parsedObject.RawParse.NotAfter),
};
}