UNPKG

@peculiar/fortify-webcomponents

Version:

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

327 lines (320 loc) 12.7 kB
/*! * © Peculiar Ventures https://peculiarventures.com/ - BSD 3-Clause License */ 'use strict'; var ssh_certificate = require('./ssh_certificate-ClDh-FAQ.js'); var utils = require('./utils-DSHncyfG.js'); /*! * © Peculiar Ventures https://peculiarventures.com/ - MIT License */ /** * @license * Copyright (c) Peculiar Ventures, LLC. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ const attributesParsers = { [ssh_certificate.id_DomainNameBeneficiary]: ssh_certificate.DomainNameBeneficiary, [ssh_certificate.id_DomainNameLegalRepresentative]: ssh_certificate.DomainNameLegalRepresentative, [ssh_certificate.id_DomainNameOwner]: ssh_certificate.DomainNameOwner, [ssh_certificate.id_DomainNameTechnicalOperator]: ssh_certificate.DomainNameTechnicalOperator, [ssh_certificate.id_TypeRelationship]: ssh_certificate.TypeRelationship, [ssh_certificate.id_ActivityDescription]: ssh_certificate.ActivityDescription, [ssh_certificate.id_WebGDPR]: ssh_certificate.WebGDPR, [ssh_certificate.id_InsuranceValue]: ssh_certificate.InsuranceValue, [ssh_certificate.id_ValuationRanking]: ssh_certificate.ValuationRanking, [ssh_certificate.id_pkcs9_at_challengePassword]: ssh_certificate.ChallengePassword, [ssh_certificate.id_pkcs9_at_unstructuredName]: ssh_certificate.UnstructuredName, [ssh_certificate.id_pkcs9_at_extensionRequest]: ssh_certificate.ExtensionRequest, [ssh_certificate.id_at_statementOfPossession]: ssh_certificate.PrivateKeyPossessionStatement, }; class Attribute extends ssh_certificate.AsnData { getAsnExtnValue() { return this.asn.values[0]; } constructor(raw) { super(raw, ssh_certificate.Attribute); const asnExtnValue = this.getAsnExtnValue(); try { const target = attributesParsers[this.asn.type]; if (target) { this.value = ssh_certificate.AsnParser.parse(asnExtnValue, target); } else { console.warn(`Didn't detect parser for "${this.asn.type}" attribute.`); this.value = ssh_certificate.buildExports.Convert.ToHex(asnExtnValue); } } catch (error) { console.error(`Error parse "${this.asn.type}" attribute:`, error.message); this.value = ssh_certificate.buildExports.Convert.ToHex(asnExtnValue); } } } /*! * © Peculiar Ventures https://peculiarventures.com/ - MIT License */ /** * @license * Copyright (c) Peculiar Ventures, LLC. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ class X509AttributeCertificate extends ssh_certificate.AsnData { constructor(raw) { var _a; super(utils.certificateRawToBuffer(raw), ssh_certificate.AttributeCertificate); this.thumbprints = {}; this.type = 'X.509 Attribute Certificate'; this.tag = ssh_certificate.PemConverter.AttributeCertificateTag; const { acinfo } = this.asn; this.serialNumber = ssh_certificate.buildExports.Convert.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 = ssh_certificate.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 utils.Extension(ssh_certificate.AsnConvert.serialize(e))); } } parseAttributes() { const { acinfo } = this.asn; if (acinfo.attributes) { this.attributes = acinfo.attributes .map((e) => new Attribute(ssh_certificate.AsnConvert.serialize(e))); } } async getThumbprint(algorithm = 'SHA-1') { try { const thumbprint = await utils.getCertificateThumbprint(algorithm, this.raw); if (thumbprint) { this.thumbprints[algorithm] = ssh_certificate.buildExports.Convert.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 ssh_certificate.PemConverter.encode(this.raw, this.tag); case 'base64url': return ssh_certificate.buildExports.Convert.ToBase64Url(this.raw); default: return ssh_certificate.buildExports.Convert.ToBase64(this.raw); } } downloadAsPEM(name) { ssh_certificate.Download.attrCert.asPEM(this.toString('pem'), name || this.commonName); } downloadAsDER(name) { ssh_certificate.Download.attrCert.asDER(this.raw, name || this.commonName); } } /*! * © Peculiar Ventures https://peculiarventures.com/ - MIT License */ /** * @license * Copyright (c) Peculiar Ventures, LLC. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ class Pkcs10CertificateRequest extends ssh_certificate.AsnData { constructor(raw) { super(utils.certificateRawToBuffer(raw), ssh_certificate.CertificationRequest); this.thumbprints = {}; this.type = 'PKCS#10 Certificate Request'; this.tag = ssh_certificate.PemConverter.CertificateRequestTag; const { certificationRequestInfo } = this.asn; this.subject = new ssh_certificate.Name(certificationRequestInfo.subject).toJSON(); this.version = certificationRequestInfo.version; } get publicKey() { const { subjectPublicKey, algorithm } = this.asn.certificationRequestInfo.subjectPKInfo; let params; if (algorithm.algorithm === ssh_certificate.id_ecPublicKey && algorithm.parameters) { params = ssh_certificate.AsnConvert.parse(algorithm.parameters, ssh_certificate.ECParameters); } if (algorithm.algorithm === ssh_certificate.id_rsaEncryption) { params = ssh_certificate.AsnConvert.parse(subjectPublicKey, ssh_certificate.RSAPublicKey); } const spki = ssh_certificate.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 utils.getCertificateThumbprint(algorithm, this.raw); if (thumbprint) { this.thumbprints[algorithm] = ssh_certificate.buildExports.Convert.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(ssh_certificate.AsnConvert.serialize(e))); } } toString(format = 'pem') { switch (format) { case 'pem': return ssh_certificate.PemConverter.encode(this.raw, this.tag); case 'base64url': return ssh_certificate.buildExports.Convert.ToBase64Url(this.raw); default: return ssh_certificate.buildExports.Convert.ToBase64(this.raw); } } downloadAsPEM(name) { ssh_certificate.Download.csr.asPEM(this.toString('pem'), name || this.commonName); } downloadAsDER(name) { ssh_certificate.Download.csr.asDER(this.raw, name || this.commonName); } } /*! * © Peculiar Ventures https://peculiarventures.com/ - MIT License */ /** * @license * Copyright (c) Peculiar Ventures, LLC. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ class X509Crl extends ssh_certificate.AsnData { constructor(raw) { super(utils.certificateRawToBuffer(raw), ssh_certificate.CertificateList); this.thumbprints = {}; this.type = 'X.509 Certificate Revocation List'; this.tag = ssh_certificate.PemConverter.CrlTag; const { tbsCertList } = this.asn; this.issuer = new ssh_certificate.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 utils.Extension(ssh_certificate.AsnConvert.serialize(e))), }); }); } async getThumbprint(algorithm = 'SHA-1') { try { const thumbprint = await utils.getCertificateThumbprint(algorithm, this.raw); if (thumbprint) { this.thumbprints[algorithm] = ssh_certificate.buildExports.Convert.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 utils.Extension(ssh_certificate.AsnConvert.serialize(e))); } } toString(format = 'pem') { switch (format) { case 'pem': return ssh_certificate.PemConverter.encode(this.raw, this.tag); case 'base64url': return ssh_certificate.buildExports.Convert.ToBase64Url(this.raw); default: return ssh_certificate.buildExports.Convert.ToBase64(this.raw); } } downloadAsPEM(name) { ssh_certificate.Download.crl.asPEM(this.toString('pem'), name || this.commonName); } downloadAsDER(name) { ssh_certificate.Download.crl.asDER(this.raw, name || this.commonName); } } exports.Pkcs10CertificateRequest = Pkcs10CertificateRequest; exports.X509AttributeCertificate = X509AttributeCertificate; exports.X509Crl = X509Crl; //# sourceMappingURL=x509_crl-ePTz18Qg.js.map //# sourceMappingURL=x509_crl-ePTz18Qg.js.map