From caa67fd040e2922ed1ed6ee1886004192ba38d20 Mon Sep 17 00:00:00 2001 From: sharevb Date: Sat, 17 Feb 2024 14:44:27 +0100 Subject: [PATCH 1/2] chore: prepare sshpk for cert/key/sshkeys related tools --- package.json | 6 +++--- vite.config.ts | 26 +++++++++++--------------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 174a859a..6b3d7233 100644 --- a/package.json +++ b/package.json @@ -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", @@ -107,7 +107,7 @@ "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", @@ -116,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", diff --git a/vite.config.ts b/vite.config.ts index 2e5c0254..0c7f8f16 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,21 +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 ?? '/'; @@ -24,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: [ From 85aed08b44f80be3215b81ef15501c03149377ff Mon Sep 17 00:00:00 2001 From: sharevb Date: Sat, 17 Feb 2024 17:28:58 +0100 Subject: [PATCH 2/2] 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 --- components.d.ts | 2 + src/tools/rsa-key-pair-generator/index.ts | 4 +- .../rsa-key-pair-generator.service.ts | 35 +++++++- .../rsa-key-pair-generator.vue | 81 +++++++++++++++---- 4 files changed, 102 insertions(+), 20 deletions(-) diff --git a/components.d.ts b/components.d.ts index fabbe793..18828739 100644 --- a/components.d.ts +++ b/components.d.ts @@ -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'] diff --git a/src/tools/rsa-key-pair-generator/index.ts b/src/tools/rsa-key-pair-generator/index.ts index 3d034e5b..4c844707 100644 --- a/src/tools/rsa-key-pair-generator/index.ts +++ b/src/tools/rsa-key-pair-generator/index.ts @@ -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, }); diff --git a/src/tools/rsa-key-pair-generator/rsa-key-pair-generator.service.ts b/src/tools/rsa-key-pair-generator/rsa-key-pair-generator.service.ts index 1cb1f1ae..34b06f26 100644 --- a/src/tools/rsa-key-pair-generator/rsa-key-pair-generator.service.ts +++ b/src/tools/rsa-key-pair-generator/rsa-key-pair-generator.service.ts @@ -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 }), }; } diff --git a/src/tools/rsa-key-pair-generator/rsa-key-pair-generator.vue b/src/tools/rsa-key-pair-generator/rsa-key-pair-generator.vue index 7f972464..3ca9f7bd 100644 --- a/src/tools/rsa-key-pair-generator/rsa-key-pair-generator.vue +++ b/src/tools/rsa-key-pair-generator/rsa-key-pair-generator.vue @@ -1,4 +1,5 @@