mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
Merge branch 'feat/csr-generator' into chore/all-my-stuffs
# Conflicts: # components.d.ts # package.json # pnpm-lock.yaml # src/tools/index.ts
This commit is contained in:
commit
8e37a86c99
6 files changed
+454
-6422
No files matched your search
@@ -324,4 +324,6 @@
|
||||
"zx": "^7.2.1"
|
||||
},
|
||||
"packageManager": "pnpm@8.15.3"
|
||||
}
|
||||
}
|
||||
}
|
||||
Generated
+185
-6421
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,77 @@
|
||||
import { pki } from 'node-forge';
|
||||
import workerScript from 'node-forge/dist/prime.worker.min?url';
|
||||
|
||||
export { generateCSR };
|
||||
|
||||
function generateRSAPairs({ bits = 2048 }) {
|
||||
return new Promise<pki.rsa.KeyPair>((resolve, reject) =>
|
||||
pki.rsa.generateKeyPair({ bits, workerScript }, (err, keyPair) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(keyPair);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
async function generateCSR(config: {
|
||||
bits?: number
|
||||
password?: string
|
||||
commonName?: string
|
||||
countryName?: string
|
||||
city?: string
|
||||
state?: string
|
||||
organizationName?: string
|
||||
organizationalUnit?: string
|
||||
contactEmail?: string
|
||||
} = {}): Promise<{
|
||||
publicKeyPem: string
|
||||
privateKeyPem: string
|
||||
csrPem: string
|
||||
}> {
|
||||
const { privateKey, publicKey } = await generateRSAPairs(config);
|
||||
|
||||
// create a certification request (CSR)
|
||||
const csr = pki.createCertificationRequest();
|
||||
csr.publicKey = publicKey;
|
||||
csr.setSubject([{
|
||||
name: 'commonName',
|
||||
value: config.commonName,
|
||||
}, {
|
||||
name: 'countryName',
|
||||
value: config.countryName,
|
||||
}, {
|
||||
name: 'stateOrProvinceName',
|
||||
value: config.state,
|
||||
}, {
|
||||
name: 'localityName',
|
||||
value: config.city,
|
||||
}, {
|
||||
name: 'organizationName',
|
||||
value: config.organizationName,
|
||||
}, {
|
||||
name: 'organizationalUnitName',
|
||||
value: config.organizationalUnit,
|
||||
}, {
|
||||
name: 'emailAddress',
|
||||
value: config.contactEmail,
|
||||
}].filter(attr => attr.value !== null && attr.value?.trim() !== ''));
|
||||
|
||||
// sign certification request
|
||||
csr.sign(privateKey);
|
||||
|
||||
// convert certification request to PEM-format
|
||||
const csrPem = pki.certificationRequestToPem(csr);
|
||||
|
||||
const privateUnencryptedKeyPem = pki.privateKeyToPem(privateKey);
|
||||
|
||||
return {
|
||||
csrPem,
|
||||
publicKeyPem: pki.publicKeyToPem(publicKey),
|
||||
privateKeyPem: config?.password
|
||||
? pki.encryptRsaPrivateKey(privateKey, config?.password)
|
||||
: privateUnencryptedKeyPem,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
<script setup lang="ts">
|
||||
import { generateCSR } from './csr-generator.service';
|
||||
import TextareaCopyable from '@/components/TextareaCopyable.vue';
|
||||
import { withDefaultOnErrorAsync } from '@/utils/defaults';
|
||||
import { computedRefreshableAsync } from '@/composable/computedRefreshable';
|
||||
import { useValidation } from '@/composable/validation';
|
||||
|
||||
const commonName = ref('test.com');
|
||||
const commonNameValidation = useValidation({
|
||||
source: commonName,
|
||||
rules: [
|
||||
{
|
||||
message: 'Common Name/Domain Name must not be empty',
|
||||
validator: value => value?.trim() !== '',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const organizationName = ref('Test');
|
||||
const organizationalUnit = ref('');
|
||||
const password = ref('');
|
||||
const city = ref('Paris');
|
||||
const state = ref('FR');
|
||||
const country = ref('France');
|
||||
const contactEmail = ref('');
|
||||
const emptyCSR = { csrPem: '', privateKeyPem: '', publicKeyPem: '' };
|
||||
|
||||
const [certs, refreshCerts] = computedRefreshableAsync(
|
||||
() => withDefaultOnErrorAsync(() => {
|
||||
if (!commonNameValidation.isValid) {
|
||||
return emptyCSR;
|
||||
}
|
||||
|
||||
return generateCSR({
|
||||
password: password.value,
|
||||
commonName: commonName.value,
|
||||
countryName: country.value,
|
||||
city: city.value,
|
||||
state: state.value,
|
||||
organizationName: organizationName.value,
|
||||
organizationalUnit: organizationalUnit.value,
|
||||
contactEmail: contactEmail.value,
|
||||
});
|
||||
},
|
||||
emptyCSR,
|
||||
), emptyCSR);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<div mb-2>
|
||||
<n-form-item
|
||||
label="Common Name/Domain Name:"
|
||||
label-placement="top"
|
||||
:feedback="commonNameValidation.message"
|
||||
:validation-status="commonNameValidation.status"
|
||||
>
|
||||
<n-input
|
||||
v-model:value="commonName"
|
||||
placeholder="Common/Domain Name"
|
||||
/>
|
||||
</n-form-item>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<n-form-item
|
||||
label="Organization Name:"
|
||||
label-placement="left" label-width="100"
|
||||
>
|
||||
<n-input
|
||||
v-model:value="organizationName"
|
||||
placeholder="Organization Name"
|
||||
/>
|
||||
</n-form-item>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<n-form-item
|
||||
label="Organization Unit:"
|
||||
label-placement="left" label-width="100"
|
||||
>
|
||||
<n-input
|
||||
v-model:value="organizationalUnit"
|
||||
placeholder="Organization Unit"
|
||||
/>
|
||||
</n-form-item>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<n-form-item
|
||||
label="State:"
|
||||
label-placement="left" label-width="100"
|
||||
>
|
||||
<n-input
|
||||
v-model:value="state"
|
||||
placeholder="State"
|
||||
/>
|
||||
</n-form-item>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<n-form-item
|
||||
label="City:"
|
||||
label-placement="left" label-width="100"
|
||||
>
|
||||
<n-input
|
||||
v-model:value="city"
|
||||
placeholder="City"
|
||||
/>
|
||||
</n-form-item>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<n-form-item
|
||||
label="Country:"
|
||||
label-placement="left" label-width="100"
|
||||
>
|
||||
<n-input
|
||||
v-model:value="country"
|
||||
placeholder="Country"
|
||||
/>
|
||||
</n-form-item>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<n-form-item
|
||||
label="Contact Email:"
|
||||
label-placement="left" label-width="100"
|
||||
>
|
||||
<n-input
|
||||
v-model:value="contactEmail"
|
||||
placeholder="Contact Email"
|
||||
/>
|
||||
</n-form-item>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<n-form-item
|
||||
label="Private Key passphrase:"
|
||||
label-placement="top"
|
||||
>
|
||||
<n-input
|
||||
v-model:value="password"
|
||||
type="password"
|
||||
show-password-on="mousedown"
|
||||
placeholder="Passphrase"
|
||||
/>
|
||||
</n-form-item>
|
||||
</div>
|
||||
|
||||
<div flex justify-center>
|
||||
<c-button @click="refreshCerts">
|
||||
Refresh CSR
|
||||
</c-button>
|
||||
</div>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<div v-if="commonNameValidation.isValid">
|
||||
<div>
|
||||
<h3>Certificate Signing Request</h3>
|
||||
<TextareaCopyable :value="certs.csrPem" />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h3>Public key</h3>
|
||||
<TextareaCopyable :value="certs.publicKeyPem" :word-wrap="true" />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h3>Private key</h3>
|
||||
<TextareaCopyable :value="certs.privateKeyPem" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,12 @@
|
||||
import { ArrowsShuffle } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'CSR Generator',
|
||||
path: '/csr-generator',
|
||||
description: 'Certificate Signing Request generator (PEM format)',
|
||||
keywords: ['csr', 'certificate', 'signing', 'request', 'x509', 'generator'],
|
||||
component: () => import('./csr-generator.vue'),
|
||||
icon: ArrowsShuffle,
|
||||
createdAt: new Date('2024-02-25'),
|
||||
});
|
||||
+2
-1
@@ -105,7 +105,7 @@ import { tool as unicodeFormatter } from './unicode-formatter';
|
||||
import { tool as asciiTextDrawer } from './ascii-text-drawer';
|
||||
|
||||
import { tool as textToUnicode } from './text-to-unicode';
|
||||
|
||||
import { tool as csrGenerator } from './csr-generator';
|
||||
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
|
||||
import { tool as numeronymGenerator } from './numeronym-generator';
|
||||
import { tool as macAddressGenerator } from './mac-address-generator';
|
||||
@@ -233,6 +233,7 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
pdfSignatureChecker,
|
||||
wpaPskGenerator,
|
||||
ansibleVaultCryptDecrypt,
|
||||
csrGenerator,
|
||||
passwordStrengthAnalyser,
|
||||
pdfSignatureChecker,
|
||||
],
|
||||
|
||||
Reference in new issue
Block a user