@peculiar/fortify-webcomponents
Version:
Web-components for creating CSR or Certificate and viewing certificates list using Fortify
351 lines (334 loc) • 14.8 kB
JavaScript
/*!
* © Peculiar Ventures https://peculiarventures.com/ - BSD 3-Clause License
*/
import { A as AsnData, z as Attribute$1, B as AsnParser, F as PrivateKeyPossessionStatement, G as ExtensionRequest, U as UnstructuredName, H as ChallengePassword, V as ValuationRanking, J as InsuranceValue, W as WebGDPR, K as ActivityDescription, T as TypeRelationship, L as DomainNameTechnicalOperator, M as DomainNameOwner, Q as DomainNameLegalRepresentative, X as DomainNameBeneficiary, b as buildExports, Y as id_at_statementOfPossession, Z as id_pkcs9_at_extensionRequest, _ as id_pkcs9_at_unstructuredName, $ as id_pkcs9_at_challengePassword, a0 as id_ValuationRanking, a1 as id_InsuranceValue, a2 as id_WebGDPR, a3 as id_ActivityDescription, a4 as id_TypeRelationship, a5 as id_DomainNameTechnicalOperator, a6 as id_DomainNameOwner, a7 as id_DomainNameLegalRepresentative, a8 as id_DomainNameBeneficiary, x as OIDs, l as l10n, a as AsnConvert, a9 as Name$1 } from './ssh_certificate.js';
import { h } from '@stencil/core/internal/client';
import { a as RowValue, g as getStringByOID, T as TableRowTable, R as RowTitle } from './download.js';
import { f as camelCaseToWords, G as GeneralNamePart, E as Extension, e as Extensions } from './miscellaneous.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 = {
[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,
[id_at_statementOfPossession]: PrivateKeyPossessionStatement,
};
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 = buildExports.Convert.ToHex(asnExtnValue);
}
}
catch (error) {
console.error(`Error parse "${this.asn.type}" attribute:`, error.message);
this.value = 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.
*/
const BasicAttribute = (props, children) => {
const { attribute } = props;
return ([
h(RowValue, { name: "Name", value: getStringByOID(attribute.asn.type) }),
children,
h("tr", null, h("td", { colSpan: 2, class: "divider" }, h("span", null))),
]);
};
/*!
* © 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.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const NamePart = (props) => {
const { name } = props;
if (!name) {
return null;
}
return name.map((relativeDistinguishedName) => (relativeDistinguishedName.map((attributeTypeAndValue) => (h(RowValue, { name: OIDs[attributeTypeAndValue.type] || attributeTypeAndValue.type, value: attributeTypeAndValue.value.toString() })))));
};
/*!
* © 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 NameAttribute = (props) => {
const { attribute } = props;
return (h(BasicAttribute, { attribute: attribute }, h(NamePart, { name: attribute.value })));
};
/*!
* © 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 ActivityDescriptionAttribute = (props) => {
const { attribute } = props;
return (h(BasicAttribute, { attribute: attribute }, h(RowValue, { name: camelCaseToWords('codeAuthority'), value: "" }), h(TableRowTable, null, h(GeneralNamePart, { generalName: attribute.value.codeAuthority, getDNSNameLink: () => '', getIPAddressLink: () => '' })), h(RowValue, { name: camelCaseToWords('codeId'), value: "" }), h(TableRowTable, null, h(GeneralNamePart, { generalName: attribute.value.codeId, getDNSNameLink: () => '', getIPAddressLink: () => '' })), h(RowValue, { name: camelCaseToWords('shortName'), value: attribute.value.shortName }), h(RowValue, { name: camelCaseToWords('shortDescription'), value: attribute.value.shortDescription })));
};
/*!
* © 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 WebGdprAttribute = (props) => {
const { attribute } = props;
return (h(BasicAttribute, { attribute: attribute }, h(RowValue, { name: camelCaseToWords('assessmentAuthority'), value: "" }), h(TableRowTable, null, h(GeneralNamePart, { generalName: attribute.value.assessmentAuthority, getDNSNameLink: () => '', getIPAddressLink: () => '' })), h(RowValue, { name: camelCaseToWords('assessmentLocation'), value: "" }), h(TableRowTable, null, h(GeneralNamePart, { generalName: attribute.value.assessmentLocation, getDNSNameLink: () => '', getIPAddressLink: () => '' })), h(RowValue, { name: camelCaseToWords('assessmentRef'), value: "" }), h(TableRowTable, null, h(GeneralNamePart, { generalName: attribute.value.assessmentRef, getDNSNameLink: () => '', getIPAddressLink: () => '' })), h(RowValue, { name: camelCaseToWords('dataStorageTerritory'), value: attribute.value.dataStorageTerritory }), h(RowValue, { name: camelCaseToWords('description'), value: attribute.value.description })));
};
/*!
* © 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 InsuranceValueAttribute = (props) => {
const { attribute } = props;
const value = `${attribute.value.base} * 10^${attribute.value.degree} ${attribute.value.location}`;
return (h(BasicAttribute, { attribute: attribute }, h(RowValue, { name: "Value", value: value })));
};
/*!
* © 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 TypeRelationshipAttribute = (props) => {
const { attribute } = props;
return (h(BasicAttribute, { attribute: attribute }, Object.keys(attribute.value).map((keyName) => (h(RowValue, { name: keyName, value: attribute.value[keyName].toNumber() ? l10n.getString('yes') : l10n.getString('no') })))));
};
/*!
* © 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 getValueRank = (value) => {
let ratio = 1;
if (value / 100 > 1) {
ratio = 100;
}
else if (value / 10 > 1) {
ratio = 10;
}
return `${value}/${5 * ratio}`;
};
const ValuationRankingAttribute = (props) => {
const { attribute } = props;
const values = Object.keys(attribute.value).map((keyName) => ([
getValueRank(attribute.value[keyName]),
h("br", null),
]));
return (h(BasicAttribute, { attribute: attribute }, h(RowValue, { name: "Value", value: values })));
};
/*!
* © 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 AsStringAttribute = (props) => {
const { attribute } = props;
return (h(BasicAttribute, { attribute: attribute }, h(RowValue, { name: "Value", value: attribute.value, monospace: true })));
};
/*!
* © 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 UnstructuredNameAttribute = (props) => {
const { attribute } = props;
return (h(BasicAttribute, { attribute: attribute }, h(RowValue, { name: "Value", value: attribute.value.utf8String })));
};
/*!
* © 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 ChallengePasswordAttribute = (props) => {
const { attribute } = props;
return (h(BasicAttribute, { attribute: attribute }, h(RowValue, { name: "Value", value: attribute.value.toString() })));
};
/*!
* © 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 ExtensionRequestAttribute = (props) => {
const { attribute } = props;
let extensions;
if (attribute.value) {
extensions = attribute.value.map((e) => new Extension(AsnConvert.serialize(e)));
}
return (h(BasicAttribute, { attribute: attribute }, h(TableRowTable, null, h(Extensions, { extensions: extensions, getDNSNameLink: () => '', getIPAddressLink: () => '', getLEILink: () => '' }))));
};
/*!
* © 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 PrivateKeyPossessionStatementAttribute = (props) => {
const { attribute } = props;
const certificateRaw = attribute.value.cert
? AsnConvert.serialize(attribute.value.cert)
: null;
return (h(BasicAttribute, { attribute: attribute }, h(RowValue, { name: "Serial Number", value: buildExports.Convert.ToHex(attribute.value.signer.serialNumber), monospace: true }), h(RowValue, { name: "Issuer", value: "" }), h(TableRowTable, null, h(NamePart, { name: attribute.value.signer.issuer })), certificateRaw && [
h(RowValue, { name: "Certificate", value: "" }),
h(TableRowTable, null, h("peculiar-certificate-viewer", { certificate: buildExports.Convert.ToBase64(certificateRaw) })),
]));
};
/*!
* © 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 Attributes = (props) => {
const { attributes } = props;
if (!attributes || !attributes.length) {
return null;
}
return ([
h(RowTitle, { value: "Attributes" }),
attributes.map((attribute) => {
try {
if (attribute.value instanceof Name$1) {
return (h(NameAttribute, { attribute: attribute }));
}
if (attribute.value instanceof ExtensionRequest) {
return (h(ExtensionRequestAttribute, { attribute: attribute }));
}
if (attribute.value instanceof ActivityDescription) {
return (h(ActivityDescriptionAttribute, { attribute: attribute }));
}
if (attribute.value instanceof WebGDPR) {
return (h(WebGdprAttribute, { attribute: attribute }));
}
if (attribute.value instanceof InsuranceValue) {
return (h(InsuranceValueAttribute, { attribute: attribute }));
}
if (attribute.value instanceof TypeRelationship) {
return (h(TypeRelationshipAttribute, { attribute: attribute }));
}
if (attribute.value instanceof ValuationRanking) {
return (h(ValuationRankingAttribute, { attribute: attribute }));
}
if (attribute.value instanceof UnstructuredName) {
return (h(UnstructuredNameAttribute, { attribute: attribute }));
}
if (attribute.value instanceof ChallengePassword) {
return (h(ChallengePasswordAttribute, { attribute: attribute }));
}
if (attribute.value instanceof PrivateKeyPossessionStatement) {
return (h(PrivateKeyPossessionStatementAttribute, { attribute: attribute }));
}
if (typeof attribute.value === 'string') {
return (h(AsStringAttribute, { attribute: attribute }));
}
return (h(BasicAttribute, { attribute: attribute }));
}
catch (_a) {
console.error('Error render attribute:', attribute.asn.type);
return null;
}
}),
]);
};
export { Attribute as A, Attributes as a };
//# sourceMappingURL=index2.js.map
//# sourceMappingURL=index2.js.map