@peculiar/fortify-webcomponents
Version:
Web-components for creating CSR or Certificate and viewing certificates list using Fortify
302 lines (295 loc) • 12.5 kB
JavaScript
/*!
* © Peculiar Ventures https://peculiarventures.com/ - BSD 3-Clause License
*/
;
const certification_request = require('./certification_request-89396ee6.js');
const utils = require('./utils-10d69476.js');
/*!
* © Peculiar Ventures https://peculiarventures.com/ - MIT License
*/
const attributesParsers = {
[certification_request.id_DomainNameBeneficiary]: certification_request.DomainNameBeneficiary,
[certification_request.id_DomainNameLegalRepresentative]: certification_request.DomainNameLegalRepresentative,
[certification_request.id_DomainNameOwner]: certification_request.DomainNameOwner,
[certification_request.id_DomainNameTechnicalOperator]: certification_request.DomainNameTechnicalOperator,
[certification_request.id_TypeRelationship]: certification_request.TypeRelationship,
[certification_request.id_ActivityDescription]: certification_request.ActivityDescription,
[certification_request.id_WebGDPR]: certification_request.WebGDPR,
[certification_request.id_InsuranceValue]: certification_request.InsuranceValue,
[certification_request.id_ValuationRanking]: certification_request.ValuationRanking,
[certification_request.id_pkcs9_at_challengePassword]: certification_request.ChallengePassword,
[certification_request.id_pkcs9_at_unstructuredName]: certification_request.UnstructuredName,
[certification_request.id_pkcs9_at_extensionRequest]: certification_request.ExtensionRequest,
};
class Attribute extends certification_request.AsnData {
getAsnExtnValue() {
return this.asn.values[0];
}
constructor(raw) {
super(raw, certification_request.Attribute);
const asnExtnValue = this.getAsnExtnValue();
try {
const target = attributesParsers[this.asn.type];
if (target) {
this.value = certification_request.AsnParser.parse(asnExtnValue, target);
}
else {
console.warn(`Didn't detect parser for "${this.asn.type}" attribute.`);
this.value = certification_request.Convert_1.ToHex(asnExtnValue);
}
}
catch (error) {
console.error(`Error parse "${this.asn.type}" attribute:`, error.message);
this.value = certification_request.Convert_1.ToHex(asnExtnValue);
}
}
}
/*!
* © Peculiar Ventures https://peculiarventures.com/ - MIT License
*/
class X509AttributeCertificate extends certification_request.AsnData {
constructor(raw) {
var _a;
super(utils.certificateRawToBuffer(raw), certification_request.AttributeCertificate);
this.thumbprints = {};
this.type = 'X.509 Attribute Certificate';
this.tag = certification_request.PemConverter.AttributeCertificateTag;
const { acinfo } = this.asn;
this.serialNumber = certification_request.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 = certification_request.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(certification_request.AsnConvert.serialize(e)));
}
}
parseAttributes() {
const { acinfo } = this.asn;
if (acinfo.attributes) {
this.attributes = acinfo.attributes
.map((e) => new Attribute(certification_request.AsnConvert.serialize(e)));
}
}
async getThumbprint(algorithm = 'SHA-1') {
try {
const thumbprint = await utils.getCertificateThumbprint(algorithm, this.raw);
if (thumbprint) {
this.thumbprints[algorithm] = certification_request.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 certification_request.PemConverter.encode(this.raw, this.tag);
case 'base64url':
return certification_request.Convert_1.ToBase64Url(this.raw);
default:
return certification_request.Convert_1.ToBase64(this.raw);
}
}
downloadAsPEM(name) {
certification_request.Download.attrCert.asPEM(this.toString('pem'), name || this.commonName);
}
downloadAsDER(name) {
certification_request.Download.attrCert.asDER(this.raw, name || this.commonName);
}
}
/*!
* © Peculiar Ventures https://peculiarventures.com/ - MIT License
*/
class Pkcs10CertificateRequest extends certification_request.AsnData {
constructor(raw) {
super(utils.certificateRawToBuffer(raw), certification_request.CertificationRequest);
this.thumbprints = {};
this.type = 'PKCS#10 Certificate Request';
this.tag = certification_request.PemConverter.CertificateRequestTag;
const { certificationRequestInfo } = this.asn;
this.subject = new certification_request.Name(certificationRequestInfo.subject).toJSON();
this.version = certificationRequestInfo.version;
}
get publicKey() {
const { subjectPublicKey, algorithm } = this.asn.certificationRequestInfo.subjectPKInfo;
let params;
if (algorithm.algorithm === certification_request.id_ecPublicKey && algorithm.parameters) {
params = certification_request.AsnConvert.parse(algorithm.parameters, certification_request.ECParameters);
}
if (algorithm.algorithm === certification_request.id_rsaEncryption) {
params = certification_request.AsnConvert.parse(subjectPublicKey, certification_request.RSAPublicKey);
}
const spki = certification_request.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] = certification_request.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(certification_request.AsnConvert.serialize(e)));
const extensionRequestAttribute = this.attributes.find((attribute) => attribute.asn.type === certification_request.id_pkcs9_at_extensionRequest);
if (extensionRequestAttribute) {
this.extensions = extensionRequestAttribute.value
.map((e) => new utils.Extension(certification_request.AsnConvert.serialize(e)));
}
}
}
toString(format = 'pem') {
switch (format) {
case 'pem':
return certification_request.PemConverter.encode(this.raw, this.tag);
case 'base64url':
return certification_request.Convert_1.ToBase64Url(this.raw);
default:
return certification_request.Convert_1.ToBase64(this.raw);
}
}
downloadAsPEM(name) {
certification_request.Download.csr.asPEM(this.toString('pem'), name || this.commonName);
}
downloadAsDER(name) {
certification_request.Download.csr.asDER(this.raw, name || this.commonName);
}
}
/*!
* © Peculiar Ventures https://peculiarventures.com/ - MIT License
*/
class X509Crl extends certification_request.AsnData {
constructor(raw) {
super(utils.certificateRawToBuffer(raw), certification_request.CertificateList);
this.thumbprints = {};
this.type = 'X.509 Certificate Revocation List';
this.tag = certification_request.PemConverter.CrlTag;
const { tbsCertList } = this.asn;
this.issuer = new certification_request.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(certification_request.AsnConvert.serialize(e))),
});
});
}
async getThumbprint(algorithm = 'SHA-1') {
try {
const thumbprint = await utils.getCertificateThumbprint(algorithm, this.raw);
if (thumbprint) {
this.thumbprints[algorithm] = certification_request.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 utils.Extension(certification_request.AsnConvert.serialize(e)));
}
}
toString(format = 'pem') {
switch (format) {
case 'pem':
return certification_request.PemConverter.encode(this.raw, this.tag);
case 'base64url':
return certification_request.Convert_1.ToBase64Url(this.raw);
default:
return certification_request.Convert_1.ToBase64(this.raw);
}
}
downloadAsPEM(name) {
certification_request.Download.crl.asPEM(this.toString('pem'), name || this.commonName);
}
downloadAsDER(name) {
certification_request.Download.crl.asDER(this.raw, name || this.commonName);
}
}
exports.Pkcs10CertificateRequest = Pkcs10CertificateRequest;
exports.X509AttributeCertificate = X509AttributeCertificate;
exports.X509Crl = X509Crl;
//# sourceMappingURL=x509_crl-d7366252.js.map