mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-24 06:40:20 +03:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
01a0e06c88 | ||
|
|
9eac9cb2a9 | ||
|
|
23f82d956a | ||
|
|
d3b32cc14e |
No files matched your search
@@ -15,7 +15,7 @@ jobs:
|
||||
- run: corepack enable
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 16
|
||||
node-version: 20
|
||||
cache: 'pnpm'
|
||||
|
||||
- name: Install dependencies
|
||||
|
||||
@@ -18,7 +18,7 @@ jobs:
|
||||
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 16
|
||||
node-version: 20
|
||||
cache: 'pnpm'
|
||||
|
||||
- name: Get Playwright version
|
||||
|
||||
Vendored
+2
-6
@@ -58,7 +58,6 @@ declare module '@vue/runtime-core' {
|
||||
CrontabGenerator: typeof import('./src/tools/crontab-generator/crontab-generator.vue')['default']
|
||||
CSelect: typeof import('./src/ui/c-select/c-select.vue')['default']
|
||||
'CSelect.demo': typeof import('./src/ui/c-select/c-select.demo.vue')['default']
|
||||
CsrGenerator: typeof import('./src/tools/csr-generator/csr-generator.vue')['default']
|
||||
CTable: typeof import('./src/ui/c-table/c-table.vue')['default']
|
||||
'CTable.demo': typeof import('./src/ui/c-table/c-table.demo.vue')['default']
|
||||
CTextCopyable: typeof import('./src/ui/c-text-copyable/c-text-copyable.vue')['default']
|
||||
@@ -131,26 +130,22 @@ declare module '@vue/runtime-core' {
|
||||
NCode: typeof import('naive-ui')['NCode']
|
||||
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
|
||||
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
|
||||
NDivider: typeof import('naive-ui')['NDivider']
|
||||
NEllipsis: typeof import('naive-ui')['NEllipsis']
|
||||
NFormItem: typeof import('naive-ui')['NFormItem']
|
||||
NH1: typeof import('naive-ui')['NH1']
|
||||
NH3: typeof import('naive-ui')['NH3']
|
||||
NIcon: typeof import('naive-ui')['NIcon']
|
||||
NInput: typeof import('naive-ui')['NInput']
|
||||
NInputNumber: typeof import('naive-ui')['NInputNumber']
|
||||
NLabel: typeof import('naive-ui')['NLabel']
|
||||
NLayout: typeof import('naive-ui')['NLayout']
|
||||
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
|
||||
NMenu: typeof import('naive-ui')['NMenu']
|
||||
NScrollbar: typeof import('naive-ui')['NScrollbar']
|
||||
NSpin: typeof import('naive-ui')['NSpin']
|
||||
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
|
||||
OtpCodeGeneratorAndValidator: typeof import('./src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue')['default']
|
||||
PasswordStrengthAnalyser: typeof import('./src/tools/password-strength-analyser/password-strength-analyser.vue')['default']
|
||||
PdfSignatureChecker: typeof import('./src/tools/pdf-signature-checker/pdf-signature-checker.vue')['default']
|
||||
PdfSignatureDetails: typeof import('./src/tools/pdf-signature-checker/components/pdf-signature-details.vue')['default']
|
||||
PercentageCalculator: typeof import('./src/tools/percentage-calculator/percentage-calculator.vue')['default']
|
||||
PgpEncryption: typeof import('./src/tools/pgp-encryption/pgp-encryption.vue')['default']
|
||||
PhoneParserAndFormatter: typeof import('./src/tools/phone-parser-and-formatter/phone-parser-and-formatter.vue')['default']
|
||||
QrCodeGenerator: typeof import('./src/tools/qr-code-generator/qr-code-generator.vue')['default']
|
||||
RandomPortGenerator: typeof import('./src/tools/random-port-generator/random-port-generator.vue')['default']
|
||||
@@ -159,6 +154,7 @@ declare module '@vue/runtime-core' {
|
||||
RouterLink: typeof import('vue-router')['RouterLink']
|
||||
RouterView: typeof import('vue-router')['RouterView']
|
||||
RsaKeyPairGenerator: typeof import('./src/tools/rsa-key-pair-generator/rsa-key-pair-generator.vue')['default']
|
||||
SafelinkDecoder: typeof import('./src/tools/safelink-decoder/safelink-decoder.vue')['default']
|
||||
SlugifyString: typeof import('./src/tools/slugify-string/slugify-string.vue')['default']
|
||||
SpanCopyable: typeof import('./src/components/SpanCopyable.vue')['default']
|
||||
SqlPrettify: typeof import('./src/tools/sql-prettify/sql-prettify.vue')['default']
|
||||
|
||||
+2
-4
@@ -75,13 +75,13 @@
|
||||
"naive-ui": "^2.35.0",
|
||||
"netmask": "^2.0.2",
|
||||
"node-forge": "^1.3.1",
|
||||
"openpgp": "^5.11.1",
|
||||
"oui-data": "^1.0.10",
|
||||
"pdf-signature-reader": "^1.4.2",
|
||||
"pinia": "^2.0.34",
|
||||
"plausible-tracker": "^0.3.8",
|
||||
"qrcode": "^1.5.1",
|
||||
"sql-formatter": "^13.0.0",
|
||||
"sshpk": "^1.18.0",
|
||||
"ua-parser-js": "^1.0.35",
|
||||
"ulid": "^2.3.0",
|
||||
"unicode-emoji-json": "^0.4.0",
|
||||
@@ -111,7 +111,6 @@
|
||||
"@types/node": "^18.15.11",
|
||||
"@types/node-forge": "^1.3.2",
|
||||
"@types/qrcode": "^1.5.0",
|
||||
"@types/sshpk": "^1.17.4",
|
||||
"@types/ua-parser-js": "^0.7.36",
|
||||
"@types/uuid": "^9.0.0",
|
||||
"@unocss/eslint-config": "^0.57.0",
|
||||
@@ -133,7 +132,6 @@
|
||||
"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",
|
||||
@@ -141,4 +139,4 @@
|
||||
"workbox-window": "^7.0.0",
|
||||
"zx": "^7.2.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ const useWebServer = process.env.NO_WEB_SERVER !== 'true';
|
||||
*/
|
||||
export default defineConfig({
|
||||
testDir: './src',
|
||||
testMatch: /.*\.e2e\.(spec\.)?ts/,
|
||||
testMatch: /\.e2e\.(spec\.)?ts$/,
|
||||
/* Run tests in files in parallel */
|
||||
fullyParallel: true,
|
||||
/* Fail the build on CI if you accidentally left test.only in the source code. */
|
||||
@@ -57,7 +57,7 @@ export default defineConfig({
|
||||
&& {
|
||||
webServer: {
|
||||
command: 'npm run preview',
|
||||
url: 'http://127.0.0.1:5050',
|
||||
url: 'http://localhost:5050',
|
||||
reuseExistingServer: !isCI,
|
||||
},
|
||||
}
|
||||
|
||||
Generated
+17
-619
File diff suppressed because it is too large.
Load diff
@@ -16,7 +16,6 @@ const props = withDefaults(
|
||||
language?: string
|
||||
copyPlacement?: 'top-right' | 'bottom-right' | 'outside' | 'none'
|
||||
copyMessage?: string
|
||||
wordWrap?: boolean
|
||||
}>(),
|
||||
{
|
||||
followHeightOf: null,
|
||||
@@ -48,7 +47,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" :word-wrap="wordWrap" :trim="false" data-test-id="area-content" />
|
||||
<n-code :code="value" :language="language" :trim="false" data-test-id="area-content" />
|
||||
</n-config-provider>
|
||||
</n-scrollbar>
|
||||
<div absolute right-10px top-10px>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { type Ref, ref, watchEffect } from 'vue';
|
||||
|
||||
export { computedCatch };
|
||||
export { computedCatch, computedCatchAsync };
|
||||
|
||||
function computedCatch<T, D>(getter: () => T, { defaultValue }: { defaultValue: D; defaultErrorMessage?: string }): [Ref<T | D>, Ref<string | undefined>];
|
||||
function computedCatch<T, D>(getter: () => T, { defaultValue, defaultErrorMessage = 'Unknown error' }: { defaultValue?: D; defaultErrorMessage?: string } = {}) {
|
||||
@@ -20,3 +20,22 @@ function computedCatch<T, D>(getter: () => T, { defaultValue, defaultErrorMessag
|
||||
|
||||
return [value, error] as const;
|
||||
}
|
||||
|
||||
function computedCatchAsync<T, D>(getterAsync: () => Promise<T>, { defaultValue }: { defaultValue: D; defaultErrorMessage?: string }): [Ref<T | D>, Ref<string | undefined>];
|
||||
function computedCatchAsync<T, D>(getterAsync: () => Promise<T>, { defaultValue, defaultErrorMessage = 'Unknown error' }: { defaultValue?: D; defaultErrorMessage?: string } = {}) {
|
||||
const error = ref<string | undefined>();
|
||||
const value = ref<T | D | undefined>();
|
||||
|
||||
watchEffect(async () => {
|
||||
try {
|
||||
error.value = undefined;
|
||||
value.value = await getterAsync();
|
||||
}
|
||||
catch (err) {
|
||||
error.value = err instanceof Error ? err.message : err?.toString() ?? defaultErrorMessage;
|
||||
value.value = defaultValue;
|
||||
}
|
||||
});
|
||||
|
||||
return [value, error] as const;
|
||||
}
|
||||
@@ -28,7 +28,7 @@ const compareMatch = computed(() => compareSync(compareString.value, compareHash
|
||||
mb-2
|
||||
/>
|
||||
<n-form-item label="Salt count: " label-placement="left" label-width="120">
|
||||
<n-input-number v-model:value="saltCount" placeholder="Salt rounds..." :max="10" :min="0" w-full />
|
||||
<n-input-number v-model:value="saltCount" placeholder="Salt rounds..." :max="100" :min="0" w-full />
|
||||
</n-form-item>
|
||||
|
||||
<c-input-text :value="hashed" readonly text-center />
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
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,
|
||||
};
|
||||
}
|
||||
@@ -1,176 +0,0 @@
|
||||
<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>
|
||||
@@ -1,12 +0,0 @@
|
||||
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'),
|
||||
});
|
||||
+4
-2
@@ -5,7 +5,8 @@ import { tool as basicAuthGenerator } from './basic-auth-generator';
|
||||
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 safelinkDecoder } from './safelink-decoder';
|
||||
import { tool as pgpEncryption } from './pgp-encryption';
|
||||
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
|
||||
import { tool as numeronymGenerator } from './numeronym-generator';
|
||||
import { tool as macAddressGenerator } from './mac-address-generator';
|
||||
@@ -95,9 +96,9 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
bip39,
|
||||
hmacGenerator,
|
||||
rsaKeyPairGenerator,
|
||||
csrGenerator,
|
||||
passwordStrengthAnalyser,
|
||||
pdfSignatureChecker,
|
||||
pgpEncryption,
|
||||
],
|
||||
},
|
||||
{
|
||||
@@ -140,6 +141,7 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
userAgentParser,
|
||||
httpStatusCodes,
|
||||
jsonDiff,
|
||||
safelinkDecoder,
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -11,6 +11,9 @@ describe('integer-base-converter', () => {
|
||||
expect(convertBase({ value: '10100101', fromBase: 2, toBase: 16 })).toEqual('a5');
|
||||
expect(convertBase({ value: '192654', fromBase: 10, toBase: 8 })).toEqual('570216');
|
||||
expect(convertBase({ value: 'zz', fromBase: 64, toBase: 10 })).toEqual('2275');
|
||||
expect(convertBase({ value: '42540766411283223938465490632011909384', fromBase: 10, toBase: 10 })).toEqual('42540766411283223938465490632011909384');
|
||||
expect(convertBase({ value: '42540766411283223938465490632011909384', fromBase: 10, toBase: 16 })).toEqual('20010db8000085a300000000ac1f8908');
|
||||
expect(convertBase({ value: '20010db8000085a300000000ac1f8908', fromBase: 16, toBase: 10 })).toEqual('42540766411283223938465490632011909384');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,16 +5,16 @@ export function convertBase({ value, fromBase, toBase }: { value: string; fromBa
|
||||
let decValue = value
|
||||
.split('')
|
||||
.reverse()
|
||||
.reduce((carry: number, digit: string, index: number) => {
|
||||
.reduce((carry: bigint, digit: string, index: number) => {
|
||||
if (!fromRange.includes(digit)) {
|
||||
throw new Error(`Invalid digit "${digit}" for base ${fromBase}.`);
|
||||
}
|
||||
return (carry += fromRange.indexOf(digit) * fromBase ** index);
|
||||
}, 0);
|
||||
return (carry += BigInt(fromRange.indexOf(digit)) * BigInt(fromBase) ** BigInt(index));
|
||||
}, 0n);
|
||||
let newValue = '';
|
||||
while (decValue > 0) {
|
||||
newValue = toRange[decValue % toBase] + newValue;
|
||||
decValue = (decValue - (decValue % toBase)) / toBase;
|
||||
newValue = toRange[Number(decValue % BigInt(toBase))] + newValue;
|
||||
decValue = (decValue - (decValue % BigInt(toBase))) / BigInt(toBase);
|
||||
}
|
||||
return newValue || '0';
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Lock } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'PGP encryption',
|
||||
path: '/pgp-encryption',
|
||||
description: 'Encrypt and decrypt text clear text using PGP Keys.',
|
||||
keywords: ['pgp', 'openpgp', 'encryption', 'cypher', 'encipher', 'crypt', 'decrypt'],
|
||||
component: () => import('./pgp-encryption.vue'),
|
||||
icon: Lock,
|
||||
createdAt: new Date('2024-04-20'),
|
||||
});
|
||||
@@ -0,0 +1,194 @@
|
||||
<script setup lang="ts">
|
||||
import * as openpgp from 'openpgp';
|
||||
import { computedCatchAsync } from '@/composable/computed/catchedComputed';
|
||||
|
||||
const cryptInput = ref('');
|
||||
const cryptPublicKey = ref('');
|
||||
const cryptPrivateKey = ref('');
|
||||
const cryptPrivateKeyPassphrase = ref('');
|
||||
const [cryptOutput, cryptError] = computedCatchAsync(async () => {
|
||||
const publicKeyArmored = cryptPublicKey.value;
|
||||
const privateKeyArmored = cryptPrivateKey.value;
|
||||
const passphrase = cryptPrivateKeyPassphrase.value;
|
||||
const text = cryptInput.value;
|
||||
|
||||
const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });
|
||||
|
||||
const privateKey = privateKeyArmored !== ''
|
||||
? (passphrase !== ''
|
||||
? await openpgp.decryptKey({
|
||||
privateKey: await openpgp.readPrivateKey({ armoredKey: privateKeyArmored }),
|
||||
passphrase,
|
||||
})
|
||||
: await openpgp.readPrivateKey({ armoredKey: privateKeyArmored }))
|
||||
: undefined;
|
||||
|
||||
return await openpgp.encrypt({
|
||||
message: await openpgp.createMessage({ text }),
|
||||
encryptionKeys: publicKey,
|
||||
signingKeys: privateKey,
|
||||
});
|
||||
}, {
|
||||
defaultValue: '',
|
||||
defaultErrorMessage: 'Unable to encrypt your text',
|
||||
});
|
||||
|
||||
const decryptInput = ref('');
|
||||
const decryptPublicKey = ref('');
|
||||
const decryptPrivateKey = ref('');
|
||||
const decryptPrivateKeyPassphrase = ref('');
|
||||
const [decryptOutput, decryptError] = computedCatchAsync(async () => {
|
||||
const publicKeyArmored = decryptPublicKey.value;
|
||||
const privateKeyArmored = decryptPrivateKey.value;
|
||||
const passphrase = decryptPrivateKeyPassphrase.value;
|
||||
const encrypted = decryptInput.value;
|
||||
|
||||
const publicKey = publicKeyArmored !== '' ? await openpgp.readKey({ armoredKey: publicKeyArmored }) : undefined;
|
||||
|
||||
const privateKey = passphrase !== ''
|
||||
? await openpgp.decryptKey({
|
||||
privateKey: await openpgp.readPrivateKey({ armoredKey: privateKeyArmored }),
|
||||
passphrase,
|
||||
})
|
||||
: await openpgp.readPrivateKey({ armoredKey: privateKeyArmored });
|
||||
|
||||
const message = await openpgp.readMessage({
|
||||
armoredMessage: encrypted, // parse armored message
|
||||
});
|
||||
const { data: decrypted, signatures } = await openpgp.decrypt({
|
||||
message,
|
||||
verificationKeys: publicKey, // optional
|
||||
decryptionKeys: privateKey,
|
||||
});
|
||||
if (signatures.length > 0) {
|
||||
try {
|
||||
await signatures[0].verified; // throws on invalid signature
|
||||
}
|
||||
catch (e: any) {
|
||||
return {
|
||||
decryptedText: decrypted,
|
||||
signatureError: `Signature could not be verified: ${e.toString()}`,
|
||||
};
|
||||
}
|
||||
}
|
||||
return {
|
||||
decryptedText: decrypted,
|
||||
signatureError: '',
|
||||
};
|
||||
}, {
|
||||
defaultValue: { decryptedText: '', signatureError: '' },
|
||||
defaultErrorMessage: 'Unable to encrypt your text',
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<c-card title="Encrypt">
|
||||
<div>
|
||||
<c-input-text
|
||||
v-model:value="cryptInput"
|
||||
label="Your text:"
|
||||
placeholder="The string to encrypt"
|
||||
rows="4"
|
||||
multiline raw-text monospace autosize flex-1
|
||||
/>
|
||||
<div flex flex-1 flex-col gap-2>
|
||||
<c-input-text
|
||||
v-model:value="cryptPublicKey"
|
||||
label="Target public key:"
|
||||
placeholder="Target public key"
|
||||
rows="5"
|
||||
multiline raw-text monospace autosize flex-1
|
||||
/>
|
||||
|
||||
<details>
|
||||
<summary>Signing private key (optional)</summary>
|
||||
<c-input-text
|
||||
v-model:value="cryptPrivateKey"
|
||||
label="Your private key:"
|
||||
placeholder="The private key to use to sign message"
|
||||
rows="5"
|
||||
multiline raw-text monospace autosize flex-1
|
||||
/>
|
||||
|
||||
<c-input-text
|
||||
v-model:value="cryptPrivateKeyPassphrase"
|
||||
label="Your private key password:" clearable raw-text
|
||||
/>
|
||||
</details>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<c-alert
|
||||
v-if="cryptError && cryptPublicKey !== ''"
|
||||
type="error" mt-12 title="Error while encrypting"
|
||||
>
|
||||
{{ cryptError }}
|
||||
</c-alert>
|
||||
|
||||
<n-form-item label="Your text encrypted:" mt-3>
|
||||
<TextareaCopyable
|
||||
:value="cryptOutput || ''"
|
||||
rows="3"
|
||||
placeholder="Your string encrypted"
|
||||
multiline monospace readonly autosize mt-5
|
||||
/>
|
||||
</n-form-item>
|
||||
</c-card>
|
||||
|
||||
<c-card title="Decrypt">
|
||||
<div>
|
||||
<c-input-text
|
||||
v-model:value="decryptInput"
|
||||
label="Your PGP Message to decrypt:"
|
||||
placeholder="The string to decrypt"
|
||||
rows="4"
|
||||
multiline raw-text monospace autosize flex-1
|
||||
/>
|
||||
<div flex flex-1 flex-col gap-2>
|
||||
<c-input-text
|
||||
v-model:value="decryptPrivateKey"
|
||||
label="Your private key:"
|
||||
placeholder="The private key to use to decrypt message"
|
||||
rows="5"
|
||||
multiline raw-text monospace autosize flex-1
|
||||
/>
|
||||
|
||||
<c-input-text
|
||||
v-model:value="decryptPrivateKeyPassphrase"
|
||||
label="Your private key password:" clearable raw-text
|
||||
/>
|
||||
|
||||
<details>
|
||||
<summary>Signing public key (optional)</summary>
|
||||
|
||||
<c-input-text
|
||||
v-model:value="decryptPublicKey"
|
||||
label="Sender public key:"
|
||||
placeholder="Sender public key"
|
||||
rows="5"
|
||||
multiline raw-text monospace autosize flex-1
|
||||
/>
|
||||
</details>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<c-alert v-if="decryptError && decryptPrivateKey !== ''" type="error" mt-3 title="Error while decrypting">
|
||||
{{ decryptError }}
|
||||
</c-alert>
|
||||
|
||||
<c-alert v-if="decryptOutput?.signatureError !== ''" type="error" mt-3 title="Signature verification">
|
||||
{{ decryptOutput?.signatureError }}
|
||||
</c-alert>
|
||||
|
||||
<n-form-item label="Your text decrypted:" mt-3>
|
||||
<TextareaCopyable
|
||||
:value="decryptOutput?.decryptedText || ''"
|
||||
rows="3"
|
||||
placeholder="Your string decrypted"
|
||||
multiline monospace readonly autosize mt-5
|
||||
/>
|
||||
</n-form-item>
|
||||
</c-card>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Mailbox } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Outlook Safelink decoder',
|
||||
path: '/safelink-decoder',
|
||||
description: 'Decode Outlook SafeLink links',
|
||||
keywords: ['outlook', 'safelink', 'decoder'],
|
||||
component: () => import('./safelink-decoder.vue'),
|
||||
icon: Mailbox,
|
||||
createdAt: new Date('2024-03-11'),
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { decodeSafeLinksURL } from './safelink-decoder.service';
|
||||
|
||||
describe('safelink-decoder', () => {
|
||||
describe('decodeSafeLinksURL', () => {
|
||||
describe('decode outlook safelink urls', () => {
|
||||
it('should decode basic safelink urls', () => {
|
||||
expect(decodeSafeLinksURL('https://aus01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.google.com%2Fsearch%3Fq%3Dsafelink%26rlz%3D1&data=05%7C02%7C%7C1ed07253975b46da1d1508dc3443752a%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638442711583216725%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=%2BQY0HBnnxfI7pzZoxzlhZdDvYu80LwQB0zUUjrffVnk%3D&reserved=0'))
|
||||
.toBe('https://www.google.com/search?q=safelink&rlz=1');
|
||||
});
|
||||
it('should decode encoded safelink urls', () => {
|
||||
expect(decodeSafeLinksURL('https://aus01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.google.com%2Fsearch%3Fq%3Dsafelink%26rlz%3D1&data=05%7C02%7C%7C1ed07253975b46da1d1508dc3443752a%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638442711583216725%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=%2BQY0HBnnxfI7pzZoxzlhZdDvYu80LwQB0zUUjrffVnk%3D&reserved=0'))
|
||||
.toBe('https://www.google.com/search?q=safelink&rlz=1');
|
||||
});
|
||||
it('throw on not outlook safelink urls', () => {
|
||||
expect(() => decodeSafeLinksURL('https://google.com'))
|
||||
.toThrow('Invalid SafeLinks URL provided');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,7 @@
|
||||
export function decodeSafeLinksURL(safeLinksUrl: string) {
|
||||
if (!safeLinksUrl.match(/\.safelinks\.protection\.outlook\.com/)) {
|
||||
throw new Error('Invalid SafeLinks URL provided');
|
||||
}
|
||||
|
||||
return new URL(safeLinksUrl).searchParams.get('url');
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<script setup lang="ts">
|
||||
import { decodeSafeLinksURL } from './safelink-decoder.service';
|
||||
import TextareaCopyable from '@/components/TextareaCopyable.vue';
|
||||
|
||||
const inputSafeLinkUrl = ref('');
|
||||
const outputDecodedUrl = computed(() => {
|
||||
try {
|
||||
return decodeSafeLinksURL(inputSafeLinkUrl.value);
|
||||
}
|
||||
catch (e: any) {
|
||||
return e.toString();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<c-input-text
|
||||
v-model:value="inputSafeLinkUrl"
|
||||
raw-text
|
||||
placeholder="Your input Outlook SafeLink Url..."
|
||||
autofocus
|
||||
label="Your input Outlook SafeLink Url:"
|
||||
/>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<n-form-item label="Output decoded URL:">
|
||||
<TextareaCopyable :value="outputDecodedUrl" :word-wrap="true" />
|
||||
</n-form-item>
|
||||
</div>
|
||||
</template>
|
||||
@@ -1,6 +1,5 @@
|
||||
import { resolve } from 'node:path';
|
||||
import { URL, fileURLToPath } from 'node:url';
|
||||
import { nodePolyfills } from 'vite-plugin-node-polyfills';
|
||||
|
||||
import VueI18n from '@intlify/unplugin-vue-i18n/vite';
|
||||
import vue from '@vitejs/plugin-vue';
|
||||
@@ -98,7 +97,6 @@ export default defineConfig({
|
||||
resolvers: [NaiveUiResolver(), IconsResolver({ prefix: 'icon' })],
|
||||
}),
|
||||
Unocss(),
|
||||
nodePolyfills(),
|
||||
],
|
||||
base: baseUrl,
|
||||
resolve: {
|
||||
|
||||
Reference in new issue
Block a user