mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-25 07:04:39 +03:00
fix(Certificate/Key Parser): CSR infos and Certificate extensions
Better extract and display x509 Certificate extensions (sshpk and node-forge) Better handle display of CSR information (and extensions)
This commit is contained in:
1 parent
904352a4eb
commit
371517ff98
2 files changed
+34
-22
No files matched your search
@@ -102,7 +102,7 @@ export function getPrivateKeyLabelValues(privateKey: PrivateKey) {
|
|||||||
] as LabelValue[];
|
] as LabelValue[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCertificateLabelValues(cert: Certificate) {
|
export function getCertificateLabelValues(cert: Certificate, forgeCertificate: forge.pki.Certificate | null) {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
label: 'Type:',
|
label: 'Type:',
|
||||||
@@ -162,7 +162,7 @@ export function getCertificateLabelValues(cert: Certificate) {
|
|||||||
value: cert.purposes?.join(', '),
|
value: cert.purposes?.join(', '),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Extensions:',
|
label: 'Extensions (parsed):',
|
||||||
value: JSON.stringify(cert.getExtensions().map(ext => ({
|
value: JSON.stringify(cert.getExtensions().map(ext => ({
|
||||||
oid: (<any>ext).oid,
|
oid: (<any>ext).oid,
|
||||||
name: (<any>ext).name || (<any>oids)[(<any>ext).oid],
|
name: (<any>ext).name || (<any>oids)[(<any>ext).oid],
|
||||||
@@ -171,6 +171,15 @@ export function getCertificateLabelValues(cert: Certificate) {
|
|||||||
})), null, 2),
|
})), null, 2),
|
||||||
multiline: true,
|
multiline: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'Extensions (raw):',
|
||||||
|
value: JSON.stringify(forgeCertificate?.extensions.map(ext => ({
|
||||||
|
id: (<any>ext).id,
|
||||||
|
name: (<any>ext).id || (<any>oids)[(<any>ext).id],
|
||||||
|
...ext,
|
||||||
|
})), null, 2),
|
||||||
|
multiline: true,
|
||||||
|
},
|
||||||
...['sha1', 'sha256', 'sha512'].flatMap(algorithm =>
|
...['sha1', 'sha256', 'sha512'].flatMap(algorithm =>
|
||||||
[
|
[
|
||||||
|
|
||||||
@@ -260,7 +269,7 @@ export async function getPGPPrivateKeyLabelValuesAsync(pgpPrivateKey: openpgp.Ke
|
|||||||
] as LabelValue[];
|
] as LabelValue[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCSRLabelValues(csr: forge.pki.Certificate) {
|
export function getCSRLabelValues(csr: forge.pki.CertificateSigningRequest) {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
label: 'Type:',
|
label: 'Type:',
|
||||||
@@ -271,18 +280,14 @@ export function getCSRLabelValues(csr: forge.pki.Certificate) {
|
|||||||
value: csr.subject?.attributes?.map(a => JSON.stringify(a, null, 2)).join('\n'),
|
value: csr.subject?.attributes?.map(a => JSON.stringify(a, null, 2)).join('\n'),
|
||||||
multiline: true,
|
multiline: true,
|
||||||
},
|
},
|
||||||
{
|
// {
|
||||||
label: 'Issuer:',
|
// label: 'Request Info:',
|
||||||
value: csr.issuer?.toString(),
|
// value: JSON.stringify(csr.certificationRequestInfo, null, 2),
|
||||||
multiline: true,
|
// multiline: true,
|
||||||
},
|
// },
|
||||||
{
|
|
||||||
label: 'Validity:',
|
|
||||||
value: JSON.stringify(csr.validity, null, 2),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
label: 'Signature:',
|
label: 'Signature:',
|
||||||
value: csr.signature,
|
value: csr.signature?.toString('hex'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Signature Oid:',
|
label: 'Signature Oid:',
|
||||||
@@ -296,23 +301,19 @@ export function getCSRLabelValues(csr: forge.pki.Certificate) {
|
|||||||
label: 'Signing info:',
|
label: 'Signing info:',
|
||||||
value: JSON.stringify(csr.siginfo, null, 2),
|
value: JSON.stringify(csr.siginfo, null, 2),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
label: 'Serial:',
|
|
||||||
value: csr.serialNumber?.toString(),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
label: 'Extensions:',
|
label: 'Extensions:',
|
||||||
value: JSON.stringify(csr.extensions, null, 2),
|
value: JSON.stringify(csr.attributes, null, 2),
|
||||||
multiline: true,
|
multiline: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Public Key:',
|
label: 'Public Key:',
|
||||||
value: onErrorReturnErrorMessage(() => forge.pki.publicKeyToPem(csr.publicKey)),
|
value: onErrorReturnErrorMessage(() => forge.pki.publicKeyToPem(csr.publicKey as never)),
|
||||||
multiline: true,
|
multiline: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Public Key Fingerprint:',
|
label: 'Public Key Fingerprint:',
|
||||||
value: onErrorReturnErrorMessage(() => forge.pki.getPublicKeyFingerprint(csr.publicKey)?.toHex()),
|
value: onErrorReturnErrorMessage(() => forge.pki.getPublicKeyFingerprint(csr.publicKey as never)?.toHex()),
|
||||||
multiline: true,
|
multiline: true,
|
||||||
},
|
},
|
||||||
] as LabelValue[];
|
] as LabelValue[];
|
||||||
|
|||||||
@@ -77,13 +77,24 @@ export async function getKeyOrCertificateInfosAsync(keyOrCertificateValue: strin
|
|||||||
certificateX509DER = Base64.fromUint8Array(cert.toBuffer('x509'));
|
certificateX509DER = Base64.fromUint8Array(cert.toBuffer('x509'));
|
||||||
}
|
}
|
||||||
catch {}
|
catch {}
|
||||||
|
let forgeCertificate: forge.pki.Certificate | null = null;
|
||||||
|
try {
|
||||||
|
forgeCertificate = forge.pki.certificateFromPem(inputKeyOrCertificateValue?.toString(), false, false);
|
||||||
|
}
|
||||||
|
catch {}
|
||||||
|
if (!forgeCertificate) {
|
||||||
|
try {
|
||||||
|
forgeCertificate = forge.pki.certificateFromAsn1(inputKeyOrCertificateValue as never, false);
|
||||||
|
}
|
||||||
|
catch {}
|
||||||
|
}
|
||||||
|
|
||||||
return { values: getCertificateLabelValues(cert), certificateX509DER };
|
return { values: getCertificateLabelValues(cert, forgeCertificate), certificateX509DER };
|
||||||
}
|
}
|
||||||
|
|
||||||
const csr = canParse(inputKeyOrCertificateValue, (value) => {
|
const csr = canParse(inputKeyOrCertificateValue, (value) => {
|
||||||
return forge.pki.certificationRequestFromPem(value.toString(), false, false);
|
return forge.pki.certificationRequestFromPem(value.toString(), false, false);
|
||||||
}) as forge.pki.Certificate;
|
}) as forge.pki.CertificateSigningRequest;
|
||||||
if (csr) {
|
if (csr) {
|
||||||
return { values: getCSRLabelValues(csr) };
|
return { values: getCSRLabelValues(csr) };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user