mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
feat(SSL Certificate Converter): allow converting crt... with multiple certificate
This commit is contained in:
1 parent
083b5e1834
commit
cf3defed07
2 files changed
+25
-2
No files matched your search
@@ -47,6 +47,29 @@ function getCertificateFromP12(p12: any) {
|
||||
return { pemCertificate, commonName };
|
||||
}
|
||||
|
||||
export function convertCertificates(
|
||||
inputKeyOrCertificateValue: string | Buffer,
|
||||
password: string) {
|
||||
if (typeof inputKeyOrCertificateValue !== 'string') {
|
||||
return convertCertificate(inputKeyOrCertificateValue, password);
|
||||
}
|
||||
const parts = inputKeyOrCertificateValue.toString().trim().split(/(-----BEGIN [^-]+-----\n)/).filter(s => s !== '');
|
||||
if (!parts.length) {
|
||||
return convertCertificate(inputKeyOrCertificateValue, password);
|
||||
}
|
||||
let parsedPEMs: Array<{
|
||||
alias: string
|
||||
key: string
|
||||
der: Certificate
|
||||
pem: string
|
||||
}> = [];
|
||||
for (let i = 0; i < parts.length; i += 2) {
|
||||
const pemPart = parts[i] + parts[i + 1];
|
||||
parsedPEMs = [...parsedPEMs, ...(convertCertificate(pemPart, password) || [])];
|
||||
}
|
||||
return parsedPEMs;
|
||||
}
|
||||
|
||||
export function convertCertificate(
|
||||
inputKeyOrCertificateValue: string | Buffer,
|
||||
password: string) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { Buffer } from 'node:buffer';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { convertCertificate } from './ssl-cert-converter.service';
|
||||
import { convertCertificates } from './ssl-cert-converter.service';
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
@@ -41,7 +41,7 @@ const convertedCertificates = computed(() => {
|
||||
inputKeyOrCertificateValue = inputContent;
|
||||
}
|
||||
|
||||
return convertCertificate(inputKeyOrCertificateValue, passphrase.value);
|
||||
return convertCertificates(inputKeyOrCertificateValue, passphrase.value);
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
Reference in new issue
Block a user