mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
fix(Certificate/Key Parser): handle multiple PEM certificate in one file
Fix #74
This commit is contained in:
1 parent
e2a6580851
commit
48854592b0
4 files changed
+10477
-13176
No files matched your search
Vendored
+12
@@ -80,6 +80,7 @@ declare module '@vue/runtime-core' {
|
||||
CommandPaletteOption: typeof import('./src/modules/command-palette/components/command-palette-option.vue')['default']
|
||||
CommonRegex: typeof import('./src/tools/common-regex-memo/common-regex.md')['default']
|
||||
CommonRegexMemo: typeof import('./src/tools/common-regex-memo/common-regex-memo.vue')['default']
|
||||
CookiesParser: typeof import('./src/tools/cookies-parser/cookies-parser.vue')['default']
|
||||
Countdown: typeof import('./src/tools/countdown/countdown.vue')['default']
|
||||
Counter: typeof import('./src/tools/pomodoro-timer/app/components/Counter.vue')['default']
|
||||
CrcCalculator: typeof import('./src/tools/crc-calculator/crc-calculator.vue')['default']
|
||||
@@ -91,6 +92,7 @@ declare module '@vue/runtime-core' {
|
||||
CssSelectors: typeof import('./src/tools/css-selectors-memo/css-selectors.md')['default']
|
||||
CssSelectorsMemo: typeof import('./src/tools/css-selectors-memo/css-selectors-memo.vue')['default']
|
||||
CssXpathConverter: typeof import('./src/tools/css-xpath-converter/css-xpath-converter.vue')['default']
|
||||
CsvToData: typeof import('./src/tools/csv-to-data/csv-to-data.vue')['default']
|
||||
CsvToJson: typeof import('./src/tools/csv-to-json/csv-to-json.vue')['default']
|
||||
CTable: typeof import('./src/ui/c-table/c-table.vue')['default']
|
||||
'CTable.demo': typeof import('./src/ui/c-table/c-table.demo.vue')['default']
|
||||
@@ -101,6 +103,7 @@ declare module '@vue/runtime-core' {
|
||||
CurlConverter: typeof import('./src/tools/curl-converter/curl-converter.vue')['default']
|
||||
CurlGenerator: typeof import('./src/tools/curl-generator/curl-generator.vue')['default']
|
||||
CurrencyConverter: typeof import('./src/tools/currency-converter/currency-converter.vue')['default']
|
||||
DataFaker: typeof import('./src/tools/data-faker/data-faker.vue')['default']
|
||||
DataStorageUnitConverter: typeof import('./src/tools/data-storage-unit-converter/data-storage-unit-converter.vue')['default']
|
||||
DataTransferRateConverter: typeof import('./src/tools/data-transfer-rate-converter/data-transfer-rate-converter.vue')['default']
|
||||
DateDurationCalculator: typeof import('./src/tools/date-duration-calculator/date-duration-calculator.vue')['default']
|
||||
@@ -111,6 +114,7 @@ declare module '@vue/runtime-core' {
|
||||
DeviceInformation: typeof import('./src/tools/device-information/device-information.vue')['default']
|
||||
DiceRoller: typeof import('./src/tools/dice-roller/dice-roller.vue')['default']
|
||||
DiffViewer: typeof import('./src/tools/json-diff/diff-viewer/diff-viewer.vue')['default']
|
||||
DistinctWords: typeof import('./src/tools/distinct-words/distinct-words.vue')['default']
|
||||
DkimDnsGenerator: typeof import('./src/tools/dkim-dns-generator/dkim-dns-generator.vue')['default']
|
||||
'Dmarc-Generator': typeof import('./src/tools/dmarc-dns-generator/dmarc--generator.vue')['default']
|
||||
DmarcDnsGenerator: typeof import('./src/tools/dmarc-dns-generator/dmarc-dns-generator.vue')['default']
|
||||
@@ -157,6 +161,8 @@ declare module '@vue/runtime-core' {
|
||||
GeoDistanceCalculator: typeof import('./src/tools/geo-distance-calculator/geo-distance-calculator.vue')['default']
|
||||
GitMemo: typeof import('./src/tools/git-memo/git-memo.vue')['default']
|
||||
'GitMemo.content': typeof import('./src/tools/git-memo/git-memo.content.md')['default']
|
||||
'GitSem.memo': typeof import('./src/tools/git-semantic-commit-memo/git-sem.memo.md')['default']
|
||||
GitSemanticCommitMemo: typeof import('./src/tools/git-semantic-commit-memo/git-semantic-commit-memo.vue')['default']
|
||||
GptTokenEstimator: typeof import('./src/tools/gpt-token-estimator/gpt-token-estimator.vue')['default']
|
||||
GzipConverter: typeof import('./src/tools/gzip-converter/gzip-converter.vue')['default']
|
||||
HarSanitizer: typeof import('./src/tools/har-sanitizer/har-sanitizer.vue')['default']
|
||||
@@ -240,11 +246,14 @@ declare module '@vue/runtime-core' {
|
||||
JsonToObject: typeof import('./src/tools/json-to-object/json-to-object.vue')['default']
|
||||
JsonToPhp: typeof import('./src/tools/json-to-php/json-to-php.vue')['default']
|
||||
JsonToPhpArray: typeof import('./src/tools/json-to-php-array/json-to-php-array.vue')['default']
|
||||
JsonToProtobuf: typeof import('./src/tools/json-to-protobuf/json-to-protobuf.vue')['default']
|
||||
JsonToPython: typeof import('./src/tools/json-to-python/json-to-python.vue')['default']
|
||||
JsonToSchema: typeof import('./src/tools/json-to-schema/json-to-schema.vue')['default']
|
||||
JsonToSqlDdl: typeof import('./src/tools/json-to-sql-ddl/json-to-sql-ddl.vue')['default']
|
||||
JsonToSqlInsert: typeof import('./src/tools/json-to-sql-insert/json-to-sql-insert.vue')['default']
|
||||
JsonToToml: typeof import('./src/tools/json-to-toml/json-to-toml.vue')['default']
|
||||
JsonToTs: typeof import('./src/tools/json-to-ts/json-to-ts.vue')['default']
|
||||
JsonToTypescript: typeof import('./src/tools/json-to-typescript/json-to-typescript.vue')['default']
|
||||
JsonToXml: typeof import('./src/tools/json-to-xml/json-to-xml.vue')['default']
|
||||
JsonToYaml: typeof import('./src/tools/json-to-yaml-converter/json-to-yaml.vue')['default']
|
||||
JsonViewer: typeof import('./src/tools/json-viewer/json-viewer.vue')['default']
|
||||
@@ -359,6 +368,7 @@ declare module '@vue/runtime-core' {
|
||||
QrCodeDecoder: typeof import('./src/tools/qr-code-decoder/qr-code-decoder.vue')['default']
|
||||
QrCodeGenerator: typeof import('./src/tools/qr-code-generator/qr-code-generator.vue')['default']
|
||||
QrContactInfoGenerator: typeof import('./src/tools/qr-contact-info-generator/qr-contact-info-generator.vue')['default']
|
||||
QuoteConverter: typeof import('./src/tools/quote-converter/quote-converter.vue')['default']
|
||||
RaidCalculator: typeof import('./src/tools/raid-calculator/raid-calculator.vue')['default']
|
||||
RandomPortGenerator: typeof import('./src/tools/random-port-generator/random-port-generator.vue')['default']
|
||||
RegexMemo: typeof import('./src/tools/regex-memo/regex-memo.vue')['default']
|
||||
@@ -392,9 +402,11 @@ declare module '@vue/runtime-core' {
|
||||
SpfDnsGenerator: typeof import('./src/tools/spf-dns-generator/spf-dns-generator.vue')['default']
|
||||
SpfGenerator: typeof import('./src/tools/spf-dns-generator/spf-generator.vue')['default']
|
||||
SplashScreen: typeof import('./src/tools/pomodoro-timer/app/views/SplashScreen.vue')['default']
|
||||
SqlMinifier: typeof import('./src/tools/sql-minifier/sql-minifier.vue')['default']
|
||||
SqlPrettify: typeof import('./src/tools/sql-prettify/sql-prettify.vue')['default']
|
||||
SslCertConverter: typeof import('./src/tools/ssl-cert-converter/ssl-cert-converter.vue')['default']
|
||||
StacktracePrettier: typeof import('./src/tools/stacktrace-prettier/stacktrace-prettier.vue')['default']
|
||||
StringEscaper: typeof import('./src/tools/string-escaper/string-escaper.vue')['default']
|
||||
StringObfuscator: typeof import('./src/tools/string-obfuscator/string-obfuscator.vue')['default']
|
||||
SvgPlaceholderGenerator: typeof import('./src/tools/svg-placeholder-generator/svg-placeholder-generator.vue')['default']
|
||||
TcpdumpGenerator: typeof import('./src/tools/tcpdump-generator/tcpdump-generator.vue')['default']
|
||||
|
||||
Generated
+10419
-13158
File diff suppressed because it is too large.
Load diff
@@ -18,6 +18,22 @@ import * as openpgp from 'openpgp';
|
||||
import * as forge from 'node-forge';
|
||||
import { type LabelValue, getCSRLabelValues, getCertificateLabelValues, getFingerprintLabelValues, getPGPPrivateKeyLabelValuesAsync, getPGPPublicKeyLabelValuesAsync, getPrivateKeyLabelValues, getPublicKeyLabelValues, getSignatureLabelValues } from './certificate-key-parser.infos';
|
||||
|
||||
export async function getKeysOrCertificatesInfosAsync(keyOrCertificateValue: string | Buffer, passphrase: string) {
|
||||
const parts = keyOrCertificateValue.toString().trim().split(/(-----BEGIN [^-]+-----\n)/).filter(s => s !== '');
|
||||
if (!parts.length) {
|
||||
return [await getKeyOrCertificateInfosAsync(keyOrCertificateValue, passphrase)];
|
||||
}
|
||||
const parsedPEMs: Array<{
|
||||
values: LabelValue[]
|
||||
certificateX509DER?: undefined | string
|
||||
}> = [];
|
||||
for (let i = 0; i < parts.length; i += 2) {
|
||||
const pemPart = parts[i] + parts[i + 1];
|
||||
parsedPEMs.push(await getKeyOrCertificateInfosAsync(pemPart, passphrase));
|
||||
}
|
||||
return parsedPEMs;
|
||||
}
|
||||
|
||||
export async function getKeyOrCertificateInfosAsync(keyOrCertificateValue: string | Buffer, passphrase: string) {
|
||||
try {
|
||||
const canParse = (value: string | Buffer, parseFunction: (value: string | Buffer) => any) => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { Buffer } from 'node:buffer';
|
||||
|
||||
import { getKeyOrCertificateInfosAsync } from './certificate-key-parser.service';
|
||||
import { getKeysOrCertificatesInfosAsync } from './certificate-key-parser.service';
|
||||
import { type LabelValue } from './certificate-key-parser.infos';
|
||||
import { useDownloadFileFromBase64 } from '@/composable/downloadBase64';
|
||||
|
||||
@@ -37,7 +37,7 @@ function downloadX509DERFile() {
|
||||
}
|
||||
}
|
||||
|
||||
const parsedSections = computedAsync<LabelValue[]>(async () => {
|
||||
const parsedSections = computedAsync<LabelValue[][]>(async () => {
|
||||
const inputContent = inputKeyOrCertificate.value;
|
||||
const file = fileInput.value;
|
||||
let inputKeyOrCertificateValue: string | Buffer = '';
|
||||
@@ -47,9 +47,15 @@ const parsedSections = computedAsync<LabelValue[]>(async () => {
|
||||
else if (inputType.value === 'content' && inputContent) {
|
||||
inputKeyOrCertificateValue = inputContent;
|
||||
}
|
||||
const { values, certificateX509DER: certPEM } = await getKeyOrCertificateInfosAsync(inputKeyOrCertificateValue, passphrase.value);
|
||||
certificateX509DER.value = certPEM || '';
|
||||
return values;
|
||||
const parsed = await getKeysOrCertificatesInfosAsync(inputKeyOrCertificateValue, passphrase.value);
|
||||
if (parsed.length === 1) {
|
||||
const { values, certificateX509DER: certPEM } = parsed[0];
|
||||
certificateX509DER.value = certPEM || '';
|
||||
return [values];
|
||||
}
|
||||
else {
|
||||
return parsed.map(p => p.values);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -96,20 +102,26 @@ const parsedSections = computedAsync<LabelValue[]>(async () => {
|
||||
|
||||
<n-divider />
|
||||
|
||||
<input-copyable
|
||||
v-for="{ label, value, multiline } of parsedSections"
|
||||
:key="label"
|
||||
:label="label"
|
||||
:data-test-id="label"
|
||||
label-position="left"
|
||||
label-width="100px"
|
||||
label-align="right"
|
||||
<c-card
|
||||
v-for="(part, partIndex) of parsedSections"
|
||||
:key="partIndex"
|
||||
mb-2
|
||||
>
|
||||
<input-copyable
|
||||
v-for="{ label, value, multiline } of part"
|
||||
:key="label"
|
||||
:label="label"
|
||||
:data-test-id="label"
|
||||
label-position="left"
|
||||
label-width="100px"
|
||||
label-align="right"
|
||||
|
||||
autosize mb-2
|
||||
:multiline="multiline"
|
||||
:value="value"
|
||||
placeholder="Not Set"
|
||||
/>
|
||||
autosize mb-2
|
||||
:multiline="multiline"
|
||||
:value="value"
|
||||
placeholder="Not Set"
|
||||
/>
|
||||
</c-card>
|
||||
|
||||
<div v-if="certificateX509DER !== ''" flex justify-center>
|
||||
<c-button @click="downloadX509DERFile()">
|
||||
|
||||
Reference in new issue
Block a user