mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +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[];
|
||||
}
|
||||
|
||||
export function getCertificateLabelValues(cert: Certificate) {
|
||||
export function getCertificateLabelValues(cert: Certificate, forgeCertificate: forge.pki.Certificate | null) {
|
||||
return [
|
||||
{
|
||||
label: 'Type:',
|
||||
@@ -162,7 +162,7 @@ export function getCertificateLabelValues(cert: Certificate) {
|
||||
value: cert.purposes?.join(', '),
|
||||
},
|
||||
{
|
||||
label: 'Extensions:',
|
||||
label: 'Extensions (parsed):',
|
||||
value: JSON.stringify(cert.getExtensions().map(ext => ({
|
||||
oid: (<any>ext).oid,
|
||||
name: (<any>ext).name || (<any>oids)[(<any>ext).oid],
|
||||
@@ -171,6 +171,15 @@ export function getCertificateLabelValues(cert: Certificate) {
|
||||
})), null, 2),
|
||||
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 =>
|
||||
[
|
||||
|
||||
@@ -260,7 +269,7 @@ export async function getPGPPrivateKeyLabelValuesAsync(pgpPrivateKey: openpgp.Ke
|
||||
] as LabelValue[];
|
||||
}
|
||||
|
||||
export function getCSRLabelValues(csr: forge.pki.Certificate) {
|
||||
export function getCSRLabelValues(csr: forge.pki.CertificateSigningRequest) {
|
||||
return [
|
||||
{
|
||||
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'),
|
||||
multiline: true,
|
||||
},
|
||||
{
|
||||
label: 'Issuer:',
|
||||
value: csr.issuer?.toString(),
|
||||
multiline: true,
|
||||
},
|
||||
{
|
||||
label: 'Validity:',
|
||||
value: JSON.stringify(csr.validity, null, 2),
|
||||
},
|
||||
// {
|
||||
// label: 'Request Info:',
|
||||
// value: JSON.stringify(csr.certificationRequestInfo, null, 2),
|
||||
// multiline: true,
|
||||
// },
|
||||
{
|
||||
label: 'Signature:',
|
||||
value: csr.signature,
|
||||
value: csr.signature?.toString('hex'),
|
||||
},
|
||||
{
|
||||
label: 'Signature Oid:',
|
||||
@@ -296,23 +301,19 @@ export function getCSRLabelValues(csr: forge.pki.Certificate) {
|
||||
label: 'Signing info:',
|
||||
value: JSON.stringify(csr.siginfo, null, 2),
|
||||
},
|
||||
{
|
||||
label: 'Serial:',
|
||||
value: csr.serialNumber?.toString(),
|
||||
},
|
||||
{
|
||||
label: 'Extensions:',
|
||||
value: JSON.stringify(csr.extensions, null, 2),
|
||||
value: JSON.stringify(csr.attributes, null, 2),
|
||||
multiline: true,
|
||||
},
|
||||
{
|
||||
label: 'Public Key:',
|
||||
value: onErrorReturnErrorMessage(() => forge.pki.publicKeyToPem(csr.publicKey)),
|
||||
value: onErrorReturnErrorMessage(() => forge.pki.publicKeyToPem(csr.publicKey as never)),
|
||||
multiline: true,
|
||||
},
|
||||
{
|
||||
label: 'Public Key Fingerprint:',
|
||||
value: onErrorReturnErrorMessage(() => forge.pki.getPublicKeyFingerprint(csr.publicKey)?.toHex()),
|
||||
value: onErrorReturnErrorMessage(() => forge.pki.getPublicKeyFingerprint(csr.publicKey as never)?.toHex()),
|
||||
multiline: true,
|
||||
},
|
||||
] as LabelValue[];
|
||||
|
||||
@@ -77,13 +77,24 @@ export async function getKeyOrCertificateInfosAsync(keyOrCertificateValue: strin
|
||||
certificateX509DER = Base64.fromUint8Array(cert.toBuffer('x509'));
|
||||
}
|
||||
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) => {
|
||||
return forge.pki.certificationRequestFromPem(value.toString(), false, false);
|
||||
}) as forge.pki.Certificate;
|
||||
}) as forge.pki.CertificateSigningRequest;
|
||||
if (csr) {
|
||||
return { values: getCSRLabelValues(csr) };
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user