UNPKG

@peculiar/fortify-webcomponents

Version:

Web-components for creating CSR or Certificate and viewing certificates list using Fortify

298 lines (292 loc) 11.7 kB
/*! * © Peculiar Ventures https://peculiarventures.com/ - BSD 3-Clause License */ import { e as AsnData, o as Attribute$1, p as AsnParser, C as Convert_1, q as id_DomainNameBeneficiary, r as DomainNameBeneficiary, s as id_DomainNameLegalRepresentative, t as DomainNameLegalRepresentative, u as id_DomainNameOwner, v as DomainNameOwner, w as id_DomainNameTechnicalOperator, x as DomainNameTechnicalOperator, y as id_TypeRelationship, T as TypeRelationship, z as id_ActivityDescription, B as ActivityDescription, F as id_WebGDPR, W as WebGDPR, G as id_InsuranceValue, I as InsuranceValue, H as id_ValuationRanking, V as ValuationRanking, J as id_pkcs9_at_challengePassword, K as ChallengePassword, L as id_pkcs9_at_unstructuredName, U as UnstructuredName, M as id_pkcs9_at_extensionRequest, Q as ExtensionRequest, X as AttributeCertificate, P as PemConverter, f as dateDiff, A as AsnConvert, D as Download, Y as CertificationRequest, N as Name, i as id_ecPublicKey, g as ECParameters, h as id_rsaEncryption, R as RSAPublicKey, Z as CertificateList } from './certification_request-0b43f1e5.js'; import { c as certificateRawToBuffer, E as Extension, g as getCertificateThumbprint } from './utils-75993c76.js'; /*! * © Peculiar Ventures https://peculiarventures.com/ - MIT License */ const attributesParsers = { [id_DomainNameBeneficiary]: DomainNameBeneficiary, [id_DomainNameLegalRepresentative]: DomainNameLegalRepresentative, [id_DomainNameOwner]: DomainNameOwner, [id_DomainNameTechnicalOperator]: DomainNameTechnicalOperator, [id_TypeRelationship]: TypeRelationship, [id_ActivityDescription]: ActivityDescription, [id_WebGDPR]: WebGDPR, [id_InsuranceValue]: InsuranceValue, [id_ValuationRanking]: ValuationRanking, [id_pkcs9_at_challengePassword]: ChallengePassword, [id_pkcs9_at_unstructuredName]: UnstructuredName, [id_pkcs9_at_extensionRequest]: ExtensionRequest, }; class Attribute extends AsnData { getAsnExtnValue() { return this.asn.values[0]; } constructor(raw) { super(raw, Attribute$1); const asnExtnValue = this.getAsnExtnValue(); try { const target = attributesParsers[this.asn.type]; if (target) { this.value = AsnParser.parse(asnExtnValue, target); } else { console.warn(`Didn't detect parser for "${this.asn.type}" attribute.`); this.value = Convert_1.ToHex(asnExtnValue); } } catch (error) { console.error(`Error parse "${this.asn.type}" attribute:`, error.message); this.value = Convert_1.ToHex(asnExtnValue); } } } /*! * © Peculiar Ventures https://peculiarventures.com/ - MIT License */ class X509AttributeCertificate extends AsnData { constructor(raw) { var _a; super(certificateRawToBuffer(raw), AttributeCertificate); this.thumbprints = {}; this.type = 'X.509 Attribute Certificate'; this.tag = PemConverter.AttributeCertificateTag; const { acinfo } = this.asn; this.serialNumber = Convert_1.ToHex(acinfo.serialNumber); this.version = acinfo.version; const notBefore = acinfo.attrCertValidityPeriod.notBeforeTime; if (!notBefore) { throw new Error("Cannot get 'notBefore' value"); } this.notBefore = notBefore; const notAfter = acinfo.attrCertValidityPeriod.notAfterTime; if (!notAfter) { throw new Error("Cannot get 'notAfter' value"); } this.notAfter = notAfter; this.validity = dateDiff(this.notBefore, this.notAfter); this.issuer = acinfo.issuer.v1Form || ((_a = acinfo.issuer.v2Form) === null || _a === void 0 ? void 0 : _a.issuerName); this.holder = acinfo.holder; } get signature() { const { signatureValue, signatureAlgorithm } = this.asn; return { value: signatureValue, algorithm: signatureAlgorithm.algorithm, }; } parseExtensions() { const { acinfo } = this.asn; if (acinfo.extensions) { this.extensions = acinfo.extensions .map((e) => new Extension(AsnConvert.serialize(e))); } } parseAttributes() { const { acinfo } = this.asn; if (acinfo.attributes) { this.attributes = acinfo.attributes .map((e) => new Attribute(AsnConvert.serialize(e))); } } async getThumbprint(algorithm = 'SHA-1') { try { const thumbprint = await getCertificateThumbprint(algorithm, this.raw); if (thumbprint) { this.thumbprints[algorithm] = Convert_1.ToHex(thumbprint); } } catch (error) { console.error('Error thumbprint get:', error); } } get commonName() { return `attribute-certificate-${this.thumbprints['SHA-1']}`; } toString(format = 'pem') { switch (format) { case 'pem': return PemConverter.encode(this.raw, this.tag); case 'base64url': return Convert_1.ToBase64Url(this.raw); default: return Convert_1.ToBase64(this.raw); } } downloadAsPEM(name) { Download.attrCert.asPEM(this.toString('pem'), name || this.commonName); } downloadAsDER(name) { Download.attrCert.asDER(this.raw, name || this.commonName); } } /*! * © Peculiar Ventures https://peculiarventures.com/ - MIT License */ class Pkcs10CertificateRequest extends AsnData { constructor(raw) { super(certificateRawToBuffer(raw), CertificationRequest); this.thumbprints = {}; this.type = 'PKCS#10 Certificate Request'; this.tag = PemConverter.CertificateRequestTag; const { certificationRequestInfo } = this.asn; this.subject = new Name(certificationRequestInfo.subject).toJSON(); this.version = certificationRequestInfo.version; } get publicKey() { const { subjectPublicKey, algorithm } = this.asn.certificationRequestInfo.subjectPKInfo; let params; if (algorithm.algorithm === id_ecPublicKey && algorithm.parameters) { params = AsnConvert.parse(algorithm.parameters, ECParameters); } if (algorithm.algorithm === id_rsaEncryption) { params = AsnConvert.parse(subjectPublicKey, RSAPublicKey); } const spki = AsnConvert.serialize(this.asn.certificationRequestInfo.subjectPKInfo); return { params, value: spki, algorithm: algorithm.algorithm, }; } get signature() { const { signature, signatureAlgorithm } = this.asn; return { value: signature, algorithm: signatureAlgorithm.algorithm, }; } get commonName() { if (!this.subject) { return ''; } for (let i = 0; i < this.subject.length; i += 1) { const name = this.subject[i]; if (name.shortName === 'CN' || name.shortName === 'E' || name.shortName === 'O') { return name.value; } } return ''; } async getThumbprint(algorithm = 'SHA-1') { try { const thumbprint = await getCertificateThumbprint(algorithm, this.raw); if (thumbprint) { this.thumbprints[algorithm] = Convert_1.ToHex(thumbprint); } } catch (error) { console.error('Error thumbprint get:', error); } } parseAttributes() { const { certificationRequestInfo } = this.asn; if (certificationRequestInfo.attributes) { this.attributes = certificationRequestInfo.attributes .map((e) => new Attribute(AsnConvert.serialize(e))); const extensionRequestAttribute = this.attributes.find((attribute) => attribute.asn.type === id_pkcs9_at_extensionRequest); if (extensionRequestAttribute) { this.extensions = extensionRequestAttribute.value .map((e) => new Extension(AsnConvert.serialize(e))); } } } toString(format = 'pem') { switch (format) { case 'pem': return PemConverter.encode(this.raw, this.tag); case 'base64url': return Convert_1.ToBase64Url(this.raw); default: return Convert_1.ToBase64(this.raw); } } downloadAsPEM(name) { Download.csr.asPEM(this.toString('pem'), name || this.commonName); } downloadAsDER(name) { Download.csr.asDER(this.raw, name || this.commonName); } } /*! * © Peculiar Ventures https://peculiarventures.com/ - MIT License */ class X509Crl extends AsnData { constructor(raw) { super(certificateRawToBuffer(raw), CertificateList); this.thumbprints = {}; this.type = 'X.509 Certificate Revocation List'; this.tag = PemConverter.CrlTag; const { tbsCertList } = this.asn; this.issuer = new Name(tbsCertList.issuer).toJSON(); this.version = tbsCertList.version + 1; this.lastUpdate = tbsCertList.thisUpdate.getTime(); this.nextUpdate = tbsCertList.nextUpdate.getTime(); this.revokedCertificates = (tbsCertList.revokedCertificates || []) .map((revokedCertificate) => { var _a; return ({ revocationDate: revokedCertificate.revocationDate, userCertificate: revokedCertificate.userCertificate, crlEntryExtensions: (_a = revokedCertificate.crlEntryExtensions) === null || _a === void 0 ? void 0 : _a.map((e) => new Extension(AsnConvert.serialize(e))), }); }); } async getThumbprint(algorithm = 'SHA-1') { try { const thumbprint = await getCertificateThumbprint(algorithm, this.raw); if (thumbprint) { this.thumbprints[algorithm] = Convert_1.ToHex(thumbprint); } } catch (error) { console.error('Error thumbprint get:', error); } } get signature() { const { signature, signatureAlgorithm } = this.asn; return { value: signature, algorithm: signatureAlgorithm.algorithm, }; } get commonName() { if (!this.issuer) { return ''; } for (let i = 0; i < this.issuer.length; i += 1) { const name = this.issuer[i]; if (name.shortName === 'CN' || name.shortName === 'E' || name.shortName === 'O') { return name.value; } } return ''; } parseExtensions() { const { tbsCertList } = this.asn; if (tbsCertList.crlExtensions) { this.extensions = tbsCertList.crlExtensions .map((e) => new Extension(AsnConvert.serialize(e))); } } toString(format = 'pem') { switch (format) { case 'pem': return PemConverter.encode(this.raw, this.tag); case 'base64url': return Convert_1.ToBase64Url(this.raw); default: return Convert_1.ToBase64(this.raw); } } downloadAsPEM(name) { Download.crl.asPEM(this.toString('pem'), name || this.commonName); } downloadAsDER(name) { Download.crl.asDER(this.raw, name || this.commonName); } } export { Pkcs10CertificateRequest as P, X509AttributeCertificate as X, X509Crl as a }; //# sourceMappingURL=x509_crl-7fe337c3.js.map