import * as crypto from 'crypto' ; import * as forge from 'node-forge' ; export const parseCert = forge . pki . certificateFromPem ; export function getTimeToCertExpiry ( cert ) { const expiry = cert . validity . notAfter . valueOf ( ) ; return expiry - Date . now ( ) ; } export function getCertificateSubjectHash ( cert ) { const derBytes = forge . asn1 . toDer ( ( forge . pki as any ) . distinguishedNameToAsn1 ( cert . subject ) ) . getBytes ( ) ; return crypto . createHash ( 'md5' ) . update ( derBytes ) . digest ( ) . readUInt32LE ( 0 ) . toString ( 16 ) ; } export function getCertificateFingerprint ( cert ) { return forge . md . sha1 . create ( ) . update ( forge . asn1 . toDer ( forge . pki . certificateToAsn1 ( cert ) ) . getBytes ( ) ) . digest ( ) . toHex ( ) ; }