diff --git a/locales/en.yml b/locales/en.yml index d8014f3d..a5b1037c 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -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:' diff --git a/src/tools/certificate-key-parser/certificate-key-parser.service.ts b/src/tools/certificate-key-parser/certificate-key-parser.service.ts index eb330e1a..0ba8b5ac 100644 --- a/src/tools/certificate-key-parser/certificate-key-parser.service.ts +++ b/src/tools/certificate-key-parser/certificate-key-parser.service.ts @@ -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)]; diff --git a/src/tools/certificate-key-parser/certificate-key-parser.vue b/src/tools/certificate-key-parser/certificate-key-parser.vue index 9bd7a594..31257623 100644 --- a/src/tools/certificate-key-parser/certificate-key-parser.vue +++ b/src/tools/certificate-key-parser/certificate-key-parser.vue @@ -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; 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(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(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' }, +];