mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
Merge branch 'feat/x509-cert-generator' into chore/all-my-stuffs
# Conflicts: # src/tools/index.ts
This commit is contained in:
commit
b2db2bdb1e
5 files changed
+337
-5
No files matched your search
Generated
+6
-5
@@ -1058,9 +1058,9 @@ packages:
|
|||||||
resolution: {integrity: sha512-+lcUbnTRhd0jOewtFSedLyiPsD5tswKkbgcezOqqWFUVNEwoUTlpPOBmvhG7OXWLR4jMdv0czPGH5XbflnD1EA==}
|
resolution: {integrity: sha512-+lcUbnTRhd0jOewtFSedLyiPsD5tswKkbgcezOqqWFUVNEwoUTlpPOBmvhG7OXWLR4jMdv0czPGH5XbflnD1EA==}
|
||||||
engines: {node: '>=6.9.0'}
|
engines: {node: '>=6.9.0'}
|
||||||
dependencies:
|
dependencies:
|
||||||
'@babel/types': 7.23.0
|
'@babel/types': 7.22.5
|
||||||
'@jridgewell/gen-mapping': 0.3.3
|
'@jridgewell/gen-mapping': 0.3.3
|
||||||
'@jridgewell/trace-mapping': 0.3.20
|
'@jridgewell/trace-mapping': 0.3.18
|
||||||
jsesc: 2.5.2
|
jsesc: 2.5.2
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
@@ -1330,7 +1330,7 @@ packages:
|
|||||||
resolution: {integrity: sha512-thqK5QFghPKWLhAV321lxF95yCg2K3Ob5yw+M3VHWfdia0IkPXUtoLH8x/6Fh486QUvzhb8YOWHChTVen2/PoQ==}
|
resolution: {integrity: sha512-thqK5QFghPKWLhAV321lxF95yCg2K3Ob5yw+M3VHWfdia0IkPXUtoLH8x/6Fh486QUvzhb8YOWHChTVen2/PoQ==}
|
||||||
engines: {node: '>=6.9.0'}
|
engines: {node: '>=6.9.0'}
|
||||||
dependencies:
|
dependencies:
|
||||||
'@babel/types': 7.23.0
|
'@babel/types': 7.22.5
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/@babel/helper-split-export-declaration@7.22.6:
|
/@babel/helper-split-export-declaration@7.22.6:
|
||||||
@@ -5697,7 +5697,7 @@ packages:
|
|||||||
/@types/lodash-es@4.17.10:
|
/@types/lodash-es@4.17.10:
|
||||||
resolution: {integrity: sha512-YJP+w/2khSBwbUSFdGsSqmDvmnN3cCKoPOL7Zjle6s30ZtemkkqhjVfFqGwPN7ASil5VyjE2GtyU/yqYY6mC0A==}
|
resolution: {integrity: sha512-YJP+w/2khSBwbUSFdGsSqmDvmnN3cCKoPOL7Zjle6s30ZtemkkqhjVfFqGwPN7ASil5VyjE2GtyU/yqYY6mC0A==}
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/lodash': 4.14.192
|
'@types/lodash': 4.14.200
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/@types/lodash.defaultsdeep@4.6.9:
|
/@types/lodash.defaultsdeep@4.6.9:
|
||||||
@@ -5720,6 +5720,7 @@ packages:
|
|||||||
|
|
||||||
/@types/lodash@4.14.192:
|
/@types/lodash@4.14.192:
|
||||||
resolution: {integrity: sha512-km+Vyn3BYm5ytMO13k9KTp27O75rbQ0NFw+U//g+PX7VZyjCioXaRFisqSIJRECljcTv73G3i6BpglNGHgUQ5A==}
|
resolution: {integrity: sha512-km+Vyn3BYm5ytMO13k9KTp27O75rbQ0NFw+U//g+PX7VZyjCioXaRFisqSIJRECljcTv73G3i6BpglNGHgUQ5A==}
|
||||||
|
dev: true
|
||||||
|
|
||||||
/@types/lodash@4.14.200:
|
/@types/lodash@4.14.200:
|
||||||
resolution: {integrity: sha512-YI/M/4HRImtNf3pJgbF+W6FrXovqj+T+/HpENLTooK9PnkacBsDpeP3IpHab40CClUfhNmdM2WTNP2sa2dni5Q==}
|
resolution: {integrity: sha512-YI/M/4HRImtNf3pJgbF+W6FrXovqj+T+/HpENLTooK9PnkacBsDpeP3IpHab40CClUfhNmdM2WTNP2sa2dni5Q==}
|
||||||
@@ -6838,7 +6839,7 @@ packages:
|
|||||||
/@vueuse/shared@10.0.0(vue@3.3.4):
|
/@vueuse/shared@10.0.0(vue@3.3.4):
|
||||||
resolution: {integrity: sha512-Zh3LgJqvUBWVY3SiMvXanTcfAneGbt63QPczBRDNgQ6jd/ehodO9a1lCFzaA6SWJJoI+ugVTjHFYJdoR656DVQ==}
|
resolution: {integrity: sha512-Zh3LgJqvUBWVY3SiMvXanTcfAneGbt63QPczBRDNgQ6jd/ehodO9a1lCFzaA6SWJJoI+ugVTjHFYJdoR656DVQ==}
|
||||||
dependencies:
|
dependencies:
|
||||||
vue-demi: 0.14.5(vue@3.3.4)
|
vue-demi: 0.14.10(vue@3.3.4)
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- '@vue/composition-api'
|
- '@vue/composition-api'
|
||||||
- vue
|
- vue
|
||||||
|
|||||||
@@ -139,6 +139,7 @@ import { tool as utmUrlGenerator } from './utm-url-generator';
|
|||||||
import { tool as javascriptPrettifier } from './javascript-prettifier';
|
import { tool as javascriptPrettifier } from './javascript-prettifier';
|
||||||
import { tool as cssPrettifier } from './css-prettifier';
|
import { tool as cssPrettifier } from './css-prettifier';
|
||||||
import { tool as htmlPrettifier } from './html-prettifier';
|
import { tool as htmlPrettifier } from './html-prettifier';
|
||||||
|
import { tool as x509CertificateGenerator } from './x509-certificate-generator';
|
||||||
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
|
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
|
||||||
import { tool as numeronymGenerator } from './numeronym-generator';
|
import { tool as numeronymGenerator } from './numeronym-generator';
|
||||||
import { tool as macAddressGenerator } from './mac-address-generator';
|
import { tool as macAddressGenerator } from './mac-address-generator';
|
||||||
@@ -291,6 +292,9 @@ export const toolsByCategory: ToolCategory[] = [
|
|||||||
passwordStrengthAnalyser,
|
passwordStrengthAnalyser,
|
||||||
pdfSignatureChecker,
|
pdfSignatureChecker,
|
||||||
rsaEncryption,
|
rsaEncryption,
|
||||||
|
x509CertificateGenerator,
|
||||||
|
passwordStrengthAnalyser,
|
||||||
|
pdfSignatureChecker,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { FileCertificate } from '@vicons/tabler';
|
||||||
|
import { defineTool } from '../tool';
|
||||||
|
|
||||||
|
export const tool = defineTool({
|
||||||
|
name: 'X509 certificate generator',
|
||||||
|
path: '/x509-certificate-generator',
|
||||||
|
description: 'Generate a self signed SSL/x509 certificate',
|
||||||
|
keywords: ['x509', 'ssl', 'tls', 'self-signed', 'certificate', 'generator'],
|
||||||
|
component: () => import('./x509-certificate-generator.vue'),
|
||||||
|
icon: FileCertificate,
|
||||||
|
createdAt: new Date('2024-02-25'),
|
||||||
|
});
|
||||||
@@ -0,0 +1,119 @@
|
|||||||
|
import { asn1, md, pki, random, util } from 'node-forge';
|
||||||
|
import workerScript from 'node-forge/dist/prime.worker.min?url';
|
||||||
|
|
||||||
|
export { generateSSLCertificate };
|
||||||
|
|
||||||
|
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);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// a hexString is considered negative if it's most significant bit is 1
|
||||||
|
// because serial numbers use ones' complement notation
|
||||||
|
// this RFC in section 4.1.2.2 requires serial numbers to be positive
|
||||||
|
// http://www.ietf.org/rfc/rfc5280.txt
|
||||||
|
function toPositiveHex(hexString: string) {
|
||||||
|
let mostSiginficativeHexAsInt = Number.parseInt(hexString[0], 16);
|
||||||
|
if (mostSiginficativeHexAsInt < 8) {
|
||||||
|
return hexString;
|
||||||
|
}
|
||||||
|
|
||||||
|
mostSiginficativeHexAsInt -= 8;
|
||||||
|
return mostSiginficativeHexAsInt.toString() + hexString.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function generateSSLCertificate(config: {
|
||||||
|
bits?: number
|
||||||
|
password?: string
|
||||||
|
commonName?: string
|
||||||
|
countryName?: string
|
||||||
|
city?: string
|
||||||
|
state?: string
|
||||||
|
organizationName?: string
|
||||||
|
organizationalUnit?: string
|
||||||
|
contactEmail?: string
|
||||||
|
days?: number
|
||||||
|
} = {}): Promise<{
|
||||||
|
fingerprint: string
|
||||||
|
publicKeyPem: string
|
||||||
|
privateKeyPem: string
|
||||||
|
certificatePem: string
|
||||||
|
}> {
|
||||||
|
const { privateKey, publicKey } = await generateRSAPairs(config);
|
||||||
|
|
||||||
|
const cert = pki.createCertificate();
|
||||||
|
|
||||||
|
cert.serialNumber = toPositiveHex(util.bytesToHex(random.getBytesSync(9))); // the serial number can be decimal or hex (if preceded by 0x)
|
||||||
|
|
||||||
|
cert.validity.notBefore = new Date();
|
||||||
|
cert.validity.notAfter = new Date();
|
||||||
|
cert.validity.notAfter.setDate(cert.validity.notBefore.getDate() + (config.days || 365));
|
||||||
|
|
||||||
|
const attrs = [{
|
||||||
|
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() !== '');
|
||||||
|
|
||||||
|
cert.setSubject(attrs);
|
||||||
|
cert.setIssuer(attrs);
|
||||||
|
|
||||||
|
cert.publicKey = publicKey;
|
||||||
|
|
||||||
|
cert.setExtensions([{
|
||||||
|
name: 'basicConstraints',
|
||||||
|
cA: true,
|
||||||
|
}, {
|
||||||
|
name: 'keyUsage',
|
||||||
|
keyCertSign: true,
|
||||||
|
digitalSignature: true,
|
||||||
|
nonRepudiation: true,
|
||||||
|
keyEncipherment: true,
|
||||||
|
dataEncipherment: true,
|
||||||
|
}]);
|
||||||
|
|
||||||
|
cert.sign(privateKey);
|
||||||
|
|
||||||
|
const fingerprint = md.sha1
|
||||||
|
.create()
|
||||||
|
.update(asn1.toDer(pki.certificateToAsn1(cert)).getBytes())
|
||||||
|
.digest()
|
||||||
|
.toHex()
|
||||||
|
.match(/.{2}/g)?.join(':') ?? '';
|
||||||
|
|
||||||
|
const privateUnencryptedKeyPem = pki.privateKeyToPem(privateKey);
|
||||||
|
|
||||||
|
return {
|
||||||
|
fingerprint,
|
||||||
|
certificatePem: pki.certificateToPem(cert),
|
||||||
|
publicKeyPem: pki.publicKeyToPem(publicKey),
|
||||||
|
privateKeyPem: config?.password
|
||||||
|
? pki.encryptRsaPrivateKey(privateKey, config?.password)
|
||||||
|
: privateUnencryptedKeyPem,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,196 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { generateSSLCertificate } from './x509-certificate-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 days = ref(365);
|
||||||
|
const password = ref('');
|
||||||
|
const city = ref('Paris');
|
||||||
|
const state = ref('FR');
|
||||||
|
const country = ref('France');
|
||||||
|
const contactEmail = ref('');
|
||||||
|
const emptyCSR = { certificatePem: '', privateKeyPem: '', publicKeyPem: '', fingerprint: '' };
|
||||||
|
|
||||||
|
const [certs, refreshCerts] = computedRefreshableAsync(
|
||||||
|
() => withDefaultOnErrorAsync(() => {
|
||||||
|
if (!commonNameValidation.isValid) {
|
||||||
|
return emptyCSR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return generateSSLCertificate({
|
||||||
|
password: password.value,
|
||||||
|
commonName: commonName.value,
|
||||||
|
countryName: country.value,
|
||||||
|
city: city.value,
|
||||||
|
state: state.value,
|
||||||
|
organizationName: organizationName.value,
|
||||||
|
organizationalUnit: organizationalUnit.value,
|
||||||
|
contactEmail: contactEmail.value,
|
||||||
|
days: days.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="Duration (days):"
|
||||||
|
label-placement="left" label-width="100"
|
||||||
|
>
|
||||||
|
<n-input-number
|
||||||
|
v-model:value="days"
|
||||||
|
placeholder="Duration (days)"
|
||||||
|
:min="1"
|
||||||
|
/>
|
||||||
|
</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="Organizational 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 Certificate
|
||||||
|
</c-button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<n-divider />
|
||||||
|
|
||||||
|
<div v-if="commonNameValidation.isValid">
|
||||||
|
<div>
|
||||||
|
<h3>Certificate (PEM)</h3>
|
||||||
|
<TextareaCopyable :value="certs.certificatePem" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h3>Fingerprint:</h3>
|
||||||
|
<TextareaCopyable :value="certs.fingerprint" :word-wrap="true" />
|
||||||
|
</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>
|
||||||
Reference in new issue
Block a user