From f229e4a8251852319029ab7363f4a18cb40fb346 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Fri, 27 Dec 2019 21:55:21 -0500 Subject: [PATCH] add parseCertificate typescript bindings --- src/functions/parseCertificate.ts | 61 +++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/functions/parseCertificate.ts diff --git a/src/functions/parseCertificate.ts b/src/functions/parseCertificate.ts new file mode 100644 index 0000000..2f45301 --- /dev/null +++ b/src/functions/parseCertificate.ts @@ -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 { + 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), + }; +}