Compare commits

...
Author SHA1 Message Date
sharevb 85aed08b44 feat(rsa-key-generator): passphrase and formats
Fix #281 (rsa with passphrase and comment)
Supports many formats: PEM (with or without passphrase), PKCS#1, PKCS#8, OpenSSH Standard (with or without passphrase), OpenSSH (new format) and PuTTY
2024-02-18 11:49:01 +01:00
sharevb caa67fd040 chore: prepare sshpk for cert/key/sshkeys related tools 2024-02-18 11:47:29 +01:00
sharevb 83832f3e2c feat(TextareaCopyable): word-wrap prop
Add word-wrap property (to allow presenting long public keys)
2024-02-18 11:39:13 +01:00
sharevb ee40ba1439 chore: prepare sshpk for cert/key/sshkeys related tools 2024-02-18 11:39:13 +01:00
sharevb 3f32990499 chore: prepare sshpk for cert/key/sshkeys related tools 2024-02-18 11:38:29 +01:00
8 changed files with 776 additions and 47 deletions

No files matched your search

+2
View File
@@ -156,6 +156,7 @@ declare module '@vue/runtime-core' {
NH3: typeof import('naive-ui')['NH3']
NIcon: typeof import('naive-ui')['NIcon']
NImage: typeof import('naive-ui')['NImage']
NInput: typeof import('naive-ui')['NInput']
NInputGroup: typeof import('naive-ui')['NInputGroup']
NInputGroupLabel: typeof import('naive-ui')['NInputGroupLabel']
NInputNumber: typeof import('naive-ui')['NInputNumber']
@@ -165,6 +166,7 @@ declare module '@vue/runtime-core' {
NProgress: typeof import('naive-ui')['NProgress']
NScrollbar: typeof import('naive-ui')['NScrollbar']
NSlider: typeof import('naive-ui')['NSlider']
NSpace: typeof import('naive-ui')['NSpace']
NStatistic: typeof import('naive-ui')['NStatistic']
NSwitch: typeof import('naive-ui')['NSwitch']
NTable: typeof import('naive-ui')['NTable']
+28 -5
View File
@@ -1,6 +1,6 @@
{
"name": "it-tools",
"version": "2023.12.21-5ed3693",
"version": "2023.11.2-7d94e11",
"description": "Collection of handy online tools for developers, with great UX. ",
"keywords": [
"productivity",
@@ -35,12 +35,15 @@
"release": "node ./scripts/release.mjs"
},
"dependencies": {
"@guolao/vue-monaco-editor": "^1.4.1",
"@it-tools/bip39": "^0.0.4",
"@it-tools/oggen": "^1.3.0",
"@jspawn/qpdf-wasm": "^0.0.2",
"@sindresorhus/slugify": "^2.2.1",
"@tiptap/pm": "2.1.6",
"@tiptap/starter-kit": "2.1.6",
"@tiptap/vue-3": "2.0.3",
"@types/sshpk": "^1.17.4",
"@vicons/material": "^0.12.0",
"@vicons/tabler": "^0.12.0",
"@vueuse/core": "^10.3.0",
@@ -48,44 +51,63 @@
"@vueuse/router": "^10.0.0",
"bcryptjs": "^2.4.3",
"change-case": "^4.1.2",
"cidr-tools": "^7.0.4",
"colord": "^2.9.3",
"composerize-ts": "^0.6.2",
"composerize": "^1.6.6",
"composeverter": "^1.6.2",
"country-code-lookup": "^0.1.0",
"cron-validator": "^1.3.1",
"cronstrue": "^2.26.0",
"crypto-js": "^4.1.1",
"custom-ed25519": "^1.0.0",
"date-fns": "^2.29.3",
"decomposerize": "^1.2.4",
"dompurify": "^3.0.6",
"emojilib": "^3.0.10",
"exifreader": "^4.20.0",
"figlet": "^1.7.0",
"figue": "^1.2.0",
"fuse.js": "^6.6.2",
"highlight.js": "^11.7.0",
"iarna-toml-esm": "^3.0.5",
"ibantools": "^4.3.3",
"ip-address": "^9.0.5",
"ip-bigint": "^8.0.2",
"ip-cidr": "^4.0.0",
"is-cidr": "^5.0.3",
"is-ip": "^5.0.1",
"isbn3": "^1.1.44",
"jpeg-quality-estimator": "^1.0.1",
"json5": "^2.2.3",
"jwt-decode": "^3.1.2",
"libphonenumber-js": "^1.10.28",
"lodash": "^4.17.21",
"mammoth": "^1.6.0",
"marked": "^10.0.0",
"mathjs": "^11.9.1",
"mime-types": "^2.1.35",
"monaco-editor": "^0.43.0",
"naive-ui": "^2.35.0",
"netmask": "^2.0.2",
"node-forge": "^1.3.1",
"oui-data": "^1.0.10",
"pdf-signature-reader": "^1.4.2",
"pinia": "^2.0.34",
"plausible-tracker": "^0.3.8",
"process": "^0.11.10",
"qpdf.js": "^1.0.0",
"qrcode": "^1.5.1",
"qrcode-parser": "^2.1.3",
"sql-formatter": "^13.0.0",
"sshpk": "^1.18.0",
"tesseract.js": "^5.0.4",
"turndown": "^7.1.2",
"ua-parser-js": "^1.0.35",
"ulid": "^2.3.0",
"unicode-emoji-json": "^0.4.0",
"unplugin-auto-import": "^0.16.4",
"uuid": "^9.0.0",
"vue": "^3.3.4",
"vue-i18n": "^9.9.1",
"vue-i18n": "^9.2.2",
"vue-router": "^4.1.6",
"vue-tsc": "^1.8.1",
"xml-formatter": "^3.3.2",
@@ -94,7 +116,7 @@
"devDependencies": {
"@antfu/eslint-config": "^0.41.0",
"@iconify-json/mdi": "^1.1.50",
"@intlify/unplugin-vue-i18n": "^2.0.0",
"@intlify/unplugin-vue-i18n": "^0.13.0",
"@playwright/test": "^1.32.3",
"@rushstack/eslint-patch": "^1.2.0",
"@tsconfig/node18": "^18.2.0",
@@ -129,6 +151,7 @@
"unplugin-icons": "^0.17.0",
"unplugin-vue-components": "^0.25.0",
"vite": "^4.4.9",
"vite-plugin-node-polyfills": "^0.21.0",
"vite-plugin-pwa": "^0.16.0",
"vite-plugin-vue-markdown": "^0.23.5",
"vite-svg-loader": "^4.0.0",
+631 -6
View File
File diff suppressed because it is too large. Load diff
+2 -1
View File
@@ -16,6 +16,7 @@ const props = withDefaults(
language?: string
copyPlacement?: 'top-right' | 'bottom-right' | 'outside' | 'none'
copyMessage?: string
wordWrap?: boolean
}>(),
{
followHeightOf: null,
@@ -47,7 +48,7 @@ const tooltipText = computed(() => isJustCopied.value ? 'Copied!' : copyMessage.
:style="height ? `min-height: ${height - 40 /* card padding */ + 10 /* negative margin compensation */}px` : ''"
>
<n-config-provider :hljs="hljs">
<n-code :code="value" :language="language" :trim="false" data-test-id="area-content" />
<n-code :code="value" :language="language" :word-wrap="wordWrap" :trim="false" data-test-id="area-content" />
</n-config-provider>
</n-scrollbar>
<div absolute right-10px top-10px>
+2 -2
View File
@@ -5,8 +5,8 @@ import { translate } from '@/plugins/i18n.plugin';
export const tool = defineTool({
name: translate('tools.rsa-key-pair-generator.title'),
path: '/rsa-key-pair-generator',
description: translate('tools.rsa-key-pair-generator.description'),
keywords: ['rsa', 'key', 'pair', 'generator', 'public', 'private', 'secret', 'ssh', 'pem'],
description: 'Generate new random RSA private and public keys (with or without passphrase).',
keywords: ['rsa', 'key', 'pair', 'generator', 'public', 'private', 'secret', 'ssh', 'pem', 'passphrase', 'password'],
component: () => import('./rsa-key-pair-generator.vue'),
icon: Certificate,
});
@@ -1,5 +1,6 @@
import { pki } from 'node-forge';
import workerScript from 'node-forge/dist/prime.worker.min?url';
import sshpk from 'sshpk';
export { generateKeyPair };
@@ -16,11 +17,39 @@ function generateRawPairs({ bits = 2048 }) {
);
}
async function generateKeyPair(config: { bits?: number } = {}) {
async function generateKeyPair(config: {
bits?: number
password?: string
format?: sshpk.PrivateKeyFormatType
comment?: string
} = {}) {
const { privateKey, publicKey } = await generateRawPairs(config);
const privateUnencryptedKeyPem = pki.privateKeyToPem(privateKey);
if (config?.format === 'pem') {
return {
publicKey: pki.publicKeyToPem(publicKey),
privateKey: config?.password
? pki.encryptRsaPrivateKey(privateKey, config?.password)
: privateUnencryptedKeyPem,
};
}
const privKey = sshpk.parsePrivateKey(privateUnencryptedKeyPem);
privKey.comment = config?.comment;
const pubFormat = config.format ?? 'ssh';
let privFormat = config.format ?? 'ssh';
if (privFormat === 'ssh') {
privFormat = 'ssh-private';
}
const pubKey = privKey.toPublic();
return {
publicKeyPem: pki.publicKeyToPem(publicKey),
privateKeyPem: pki.privateKeyToPem(privateKey),
publicKey: pubKey.toString(pubFormat),
privateKey: config?.password
? privKey.toString(privFormat,
{ passphrase: config?.password, comment: config?.comment },
)
: privKey.toString(privFormat, { comment: config?.comment }),
};
}
@@ -1,4 +1,5 @@
<script setup lang="ts">
import type sshpk from 'sshpk';
import { generateKeyPair } from './rsa-key-pair-generator.service';
import TextareaCopyable from '@/components/TextareaCopyable.vue';
import { withDefaultOnErrorAsync } from '@/utils/defaults';
@@ -6,7 +7,21 @@ import { useValidation } from '@/composable/validation';
import { computedRefreshableAsync } from '@/composable/computedRefreshable';
const bits = ref(2048);
const emptyCerts = { publicKeyPem: '', privateKeyPem: '' };
const comment = ref('');
const password = ref('');
const emptyCerts = { publicKey: '', privateKey: '' };
const format = useStorage('rsa-key-pair-generator:format', 'ssh');
const formatOptions = [
{ value: 'pem', label: 'PEM' },
{ value: 'pkcs1', label: 'PKCS#1' },
{ value: 'pkcs8', label: 'PKCS#8' },
{ value: 'ssh', label: 'OpenSSH Standard' },
{ value: 'openssh', label: 'OpenSSH New' },
{ value: 'putty', label: 'PuTTY' },
];
const supportsPassphrase = computed(() => format.value === 'pem' || format.value === 'ssh');
const { attrs: bitsValidationAttrs } = useValidation({
source: bits,
@@ -19,31 +34,67 @@ const { attrs: bitsValidationAttrs } = useValidation({
});
const [certs, refreshCerts] = computedRefreshableAsync(
() => withDefaultOnErrorAsync(() => generateKeyPair({ bits: bits.value }), emptyCerts),
() => withDefaultOnErrorAsync(() => generateKeyPair({
bits: bits.value,
password: password.value,
format: format.value as sshpk.PrivateKeyFormatType,
comment: comment.value,
}), emptyCerts),
emptyCerts,
);
</script>
<template>
<div style="flex: 0 0 100%">
<div item-style="flex: 1 1 0" style="max-width: 600px" mx-auto flex gap-3>
<n-form-item label="Bits :" v-bind="bitsValidationAttrs as any" label-placement="left" label-width="100">
<div>
<n-space justify="space-between" mb-1>
<c-select
v-model:value="format"
label-position="left"
label="Format:"
:options="formatOptions"
placeholder="Select a key format"
/>
<n-form-item label="Bits :" v-bind="bitsValidationAttrs as any" label-placement="left">
<n-input-number v-model:value="bits" min="256" max="16384" step="8" />
</n-form-item>
</n-space>
<div v-if="supportsPassphrase" mb-1>
<n-form-item label="Passphrase :" label-placement="left">
<n-input
v-model:value="password"
type="password"
show-password-on="mousedown"
placeholder="Passphrase"
/>
</n-form-item>
</div>
<div mb-1>
<n-form-item label="Comment :" label-placement="left">
<n-input
v-model:value="comment"
type="text"
placeholder="Comment"
/>
</n-form-item>
</div>
<n-space justify="center" mb-1>
<c-button @click="refreshCerts">
Refresh key-pair
</c-button>
</n-space>
<div>
<h3>Public key</h3>
<TextareaCopyable :value="certs.publicKey" :word-wrap="true" />
</div>
<div>
<h3>Private key</h3>
<TextareaCopyable :value="certs.privateKey" />
</div>
</div>
<div>
<h3>Public key</h3>
<TextareaCopyable :value="certs.publicKeyPem" />
</div>
<div>
<h3>Private key</h3>
<TextareaCopyable :value="certs.privateKeyPem" />
</div>
</template>
+13 -15
View File
@@ -1,20 +1,21 @@
import { resolve } from 'node:path';
import { URL, fileURLToPath } from 'node:url';
import { resolve } from 'node:path';
import { nodePolyfills } from 'vite-plugin-node-polyfills';
import VueI18n from '@intlify/unplugin-vue-i18n/vite';
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import Unocss from 'unocss/vite';
import AutoImport from 'unplugin-auto-import/vite';
import IconsResolver from 'unplugin-icons/resolver';
import Icons from 'unplugin-icons/vite';
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers';
import Components from 'unplugin-vue-components/vite';
import { defineConfig } from 'vite';
import { VitePWA } from 'vite-plugin-pwa';
import markdown from 'vite-plugin-vue-markdown';
import svgLoader from 'vite-svg-loader';
import { VitePWA } from 'vite-plugin-pwa';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers';
import Unocss from 'unocss/vite';
import { configDefaults } from 'vitest/config';
import Icons from 'unplugin-icons/vite';
import IconsResolver from 'unplugin-icons/resolver';
import VueI18n from '@intlify/unplugin-vue-i18n/vite';
const baseUrl = process.env.BASE_URL ?? '/';
@@ -23,13 +24,9 @@ export default defineConfig({
plugins: [
VueI18n({
runtimeOnly: true,
jitCompilation: true,
compositionOnly: true,
fullInstall: true,
strictMessage: false,
include: [
resolve(__dirname, 'locales/**'),
],
include: [resolve(__dirname, 'locales/**')],
}),
AutoImport({
imports: [
@@ -97,6 +94,7 @@ export default defineConfig({
resolvers: [NaiveUiResolver(), IconsResolver({ prefix: 'icon' })],
}),
Unocss(),
nodePolyfills(),
],
base: baseUrl,
resolve: {