fix(Certificate Key Parser): option to add missing BEGIN/END

Fix #1799
This commit is contained in:
ShareVB committed 2026-06-23 23:13:30 +02:00
1 parent 521a957640
commit 464e005afd
3 files changed
+70 -3

No files matched your search

+20 -1
View File
@@ -5385,7 +5385,9 @@ tools:
summary-with-large-image: Summary with large image
summary: Summary
twitter: Twitter
the-name-of-the-twitter-account-of-the-creator-ex-cthmsst: The name of the Twitter account of the creator (ex{':'} {'@'}cthmsst)...
the-name-of-the-twitter-account-of-the-creator-ex-cthmsst: >-
The name of the Twitter account of the creator (ex{':'}
{'@'}cthmsst)...
videoEpisode:
text:
which-series-this-episode-belongs-to: Which series this episode belongs to...
@@ -6071,6 +6073,23 @@ tools:
label-fingerprint-base64: 'Fingerprint (base64):'
label-fingerprint-asn1: 'Fingerprint (asn1):'
label-fingerprint-ssh: 'Fingerprint (ssh):'
label-pem-header: 'PEM Header Type:'
autodetect: Autodetect
certificate-x-509: Certificate (X.509)
certificate-request-csr-pkcs-10: Certificate Request (CSR / PKCS#10)
private-key-pkcs-8: Private Key (PKCS#8)
public-key-pkcs-8: Public Key (PKCS#8)
encrypted-private-key-pkcs-8-encrypted: Encrypted Private Key (PKCS#8 Encrypted)
rsa-private-key-pkcs-1: RSA Private Key (PKCS#1)
rsa-public-key-pkcs-1: RSA Public Key (PKCS#1)
ec-private-key: EC Private Key
ec-parameters: EC Parameters
dsa-private-key: DSA Private Key
dsa-public-key: DSA Public Key
openssh-private-key: OpenSSH Private Key
ssh-public-key-rfc4716: SSH Public Key (RFC4716)
pgp-public-key-block: PGP Public Key Block
pgp-private-key-block: PGP Private Key Block
service:
text:
type: 'Type:'
@@ -21,7 +21,13 @@ import { type LabelValue, getCSRLabelValues, getCertificateLabelValues, getFinge
import { translate as t } from '@/plugins/i18n.plugin';
export async function getKeysOrCertificatesInfosAsync(keyOrCertificateValue: string | Buffer, passphrase: string) {
export async function getKeysOrCertificatesInfosAsync(
keyOrCertificateValue: string | Buffer,
passphrase: string,
add_missing_type: string | null = null) {
if (add_missing_type && !keyOrCertificateValue.toString().trim().startsWith('-----BEGIN')) {
keyOrCertificateValue = `-----BEGIN ${add_missing_type}-----\n${keyOrCertificateValue.toString().trim()}\n-----END ${add_missing_type}-----`;
}
const parts = keyOrCertificateValue.toString().trim().split(/(-----BEGIN [^-]+-----\n)/).filter(s => s !== '');
if (!parts.length) {
return [await getKeyOrCertificateInfosAsync(keyOrCertificateValue, passphrase)];
@@ -5,6 +5,7 @@ import { useI18n } from 'vue-i18n';
import { getKeysOrCertificatesInfosAsync } from './certificate-key-parser.service';
import { type LabelValue } from './certificate-key-parser.infos';
import { useDownloadFileFromBase64 } from '@/composable/downloadBase64';
import { useQueryParamOrStorage } from '@/composable/queryParams';
const { t } = useI18n();
@@ -12,6 +13,11 @@ const inputKeyOrCertificate = ref('');
const passphrase = ref('');
const fileInput = ref() as Ref<Buffer>;
const inputType = ref<'file' | 'content'>('file');
const pemHeader = useQueryParamOrStorage({
name: 'pemtype',
storageName: 'cert-key-parser:t',
defaultValue: '',
});
async function onUpload(file: File) {
if (file) {
@@ -51,7 +57,7 @@ const parsedSections = computedAsync<LabelValue[][]>(async () => {
inputKeyOrCertificateValue = inputContent;
}
try {
const parsed = await getKeysOrCertificatesInfosAsync(inputKeyOrCertificateValue, passphrase.value);
const parsed = await getKeysOrCertificatesInfosAsync(inputKeyOrCertificateValue, passphrase.value, pemHeader.value);
if (parsed.length === 1) {
const { values, certificateX509DER: certPEM } = parsed[0];
certificateX509DER.value = certPEM || '';
@@ -67,6 +73,32 @@ const parsedSections = computedAsync<LabelValue[][]>(async () => {
];
}
});
const pemHeaders = [
{ label: t('tools.certificate-key-parser.texts.autodetect'), value: '' },
{ label: t('tools.certificate-key-parser.texts.certificate-x-509'), value: 'CERTIFICATE' },
{ label: t('tools.certificate-key-parser.texts.certificate-request-csr-pkcs-10'), value: 'CERTIFICATE REQUEST' },
{ label: t('tools.certificate-key-parser.texts.private-key-pkcs-8'), value: 'PRIVATE KEY' },
{ label: t('tools.certificate-key-parser.texts.public-key-pkcs-8'), value: 'PUBLIC KEY' },
{ label: t('tools.certificate-key-parser.texts.encrypted-private-key-pkcs-8-encrypted'), value: 'ENCRYPTED PRIVATE KEY' },
{ label: t('tools.certificate-key-parser.texts.rsa-private-key-pkcs-1'), value: 'RSA PRIVATE KEY' },
{ label: t('tools.certificate-key-parser.texts.rsa-public-key-pkcs-1'), value: 'RSA PUBLIC KEY' },
{ label: t('tools.certificate-key-parser.texts.ec-private-key'), value: 'EC PRIVATE KEY' },
{ label: t('tools.certificate-key-parser.texts.ec-parameters'), value: 'EC PARAMETERS' },
{ label: t('tools.certificate-key-parser.texts.dsa-private-key'), value: 'DSA PRIVATE KEY' },
{ label: t('tools.certificate-key-parser.texts.dsa-public-key'), value: 'DSA PUBLIC KEY' },
{ label: t('tools.certificate-key-parser.texts.openssh-private-key'), value: 'OPENSSH PRIVATE KEY' },
{ label: t('tools.certificate-key-parser.texts.ssh-public-key-rfc4716'), value: 'SSH PUBLIC KEY' },
{ label: t('tools.certificate-key-parser.texts.pgp-public-key-block'), value: 'PGP PUBLIC KEY BLOCK' },
{ label: t('tools.certificate-key-parser.texts.pgp-private-key-block'), value: 'PGP PRIVATE KEY BLOCK' },
];
</script>
<template>
@@ -108,6 +140,16 @@ const parsedSections = computedAsync<LabelValue[][]>(async () => {
:placeholder="t('tools.certificate-key-parser.texts.placeholder-passphrase-for-encrypted-keys')"
type="password"
data-test-id="pass"
label-position="left"
mt-1
/>
<c-select
v-model:value="pemHeader"
:options="pemHeaders"
:label="t('tools.certificate-key-parser.texts.label-pem-header')"
label-position="left"
mt-1
/>
<n-divider />