@peculiar/fortify-webcomponents
Version:
Web-components for creating CSR or Certificate and viewing certificates list using Fortify
8 lines • 2.96 kB
JavaScript
/*!
* © Peculiar Ventures https://peculiarventures.com/ - BSD 3-Clause License
*/
import{e as t,c as s,P as i,C as e,N as r,f as n,A as a,i as h,g as o,h as u,R as c,j as f,k as l,l as g,m,n as p,D as b}from"./p-4227eec7.js";import{c as w,E as C,g as E}from"./p-db3ee43d.js";
/*!
* © Peculiar Ventures https://peculiarventures.com/ - MIT License
*/class d extends t{constructor(t){super(w(t),s);this.thumbprints={};this.type="X.509 Certificate";this.tag=i.CertificateTag;const{tbsCertificate:a}=this.asn;this.serialNumber=e.ToHex(a.serialNumber);this.subject=new r(a.subject).toJSON();this.issuer=new r(a.issuer).toJSON();this.version=a.version+1;const h=a.validity.notBefore.utcTime||a.validity.notBefore.generalTime;if(!h){throw new Error("Cannot get 'notBefore' value")}this.notBefore=h;const o=a.validity.notAfter.utcTime||a.validity.notAfter.generalTime;if(!o){throw new Error("Cannot get 'notAfter' value")}this.notAfter=o;this.validity=n(this.notBefore,this.notAfter)}parseExtensions(){const{tbsCertificate:t}=this.asn;if(t.extensions){this.extensions=t.extensions.map((t=>new C(a.serialize(t))))}}getPublicKeyInfo(t){const{subjectPublicKey:s,algorithm:i}=t;let e;if(i.algorithm===h&&i.parameters){e=a.parse(i.parameters,o)}if(i.algorithm===u){e=a.parse(s,c)}if(i.algorithm===f){e=a.parse(s,l);e=e.map((t=>this.getPublicKeyInfo(t)))}const r=a.serialize(t);return{params:e,value:r,algorithm:i.algorithm}}get publicKey(){return this.getPublicKeyInfo(this.asn.tbsCertificate.subjectPublicKeyInfo)}get signature(){const{signatureValue:t,signatureAlgorithm:s}=this.asn;let i;if(s.algorithm===g){const e=a.parse(t,m);const r=a.parse(s.parameters,p);i=r.map(((t,s)=>Object.assign(Object.assign({},t),{value:e[s]})))}return{params:i,value:t,algorithm:s.algorithm}}async getThumbprint(t="SHA-1"){try{const s=await E(t,this.raw);if(s){this.thumbprints[t]=e.ToHex(s)}}catch(t){console.error("Error thumbprint get:",t)}}get commonName(){if(!this.subject){return""}for(let t=0;t<this.subject.length;t+=1){const s=this.subject[t];if(s.shortName==="CN"||s.shortName==="E"||s.shortName==="O"){return s.value}}return""}get issuerCommonName(){if(!this.issuer){return""}for(let t=0;t<this.issuer.length;t+=1){const s=this.issuer[t];if(s.shortName==="CN"){return s.value}if(s.shortName==="E"){return s.value}}return""}get isRoot(){return JSON.stringify(this.issuer)===JSON.stringify(this.subject)}subjectToString(){if(!this.subject){return""}return this.subject.map((t=>`${t.shortName}=${t.value}`)).join(", ")}issuerToString(){if(!this.issuer){return""}return this.issuer.map((t=>`${t.shortName}=${t.value}`)).join(", ")}toString(t="pem"){switch(t){case"pem":return i.encode(this.raw,this.tag);case"base64url":return e.ToBase64Url(this.raw);default:return e.ToBase64(this.raw)}}downloadAsPEM(t){b.cert.asPEM(this.toString("pem"),t||this.commonName)}downloadAsDER(t){b.cert.asDER(this.raw,t||this.commonName)}}export{d as X};
//# sourceMappingURL=p-c66d5b86.js.map