Compare commits

..
Author SHA1 Message Date
sharevb ecf0eacc32 Merge branch 'main' into feat/gzip 2024-03-11 22:18:19 +01:00
ShareVB ffc635ef26 fix: better ui, word wrap 2024-03-11 22:14:24 +01:00
sharevb 3ad648d569 feat(new tool): GZIP String converter
Fix #892
2024-03-11 22:05:47 +01:00
sharevbandCorentin THOMASSET d3b32cc14e feat(new tool): Outlook Safelink Decoder (#911)
* feat(new tool): Outlook Safelink Decoder

Fix #897

* Use native URL parsing

Co-authored-by: Corentin THOMASSET <corentin.thomasset74@gmail.com>

* Update src/tools/safelink-decoder/index.ts

---------

Co-authored-by: Corentin THOMASSET <corentin.thomasset74@gmail.com>
2024-03-11 10:19:32 +00:00
14 changed files with 204 additions and 991 deletions

No files matched your search

+1 -7
View File
@@ -81,6 +81,7 @@ declare module '@vue/runtime-core' {
FormatTransformer: typeof import('./src/components/FormatTransformer.vue')['default']
GitMemo: typeof import('./src/tools/git-memo/git-memo.vue')['default']
'GitMemo.content': typeof import('./src/tools/git-memo/git-memo.content.md')['default']
GzipConverter: typeof import('./src/tools/gzip-converter/gzip-converter.vue')['default']
HashText: typeof import('./src/tools/hash-text/hash-text.vue')['default']
HmacGenerator: typeof import('./src/tools/hmac-generator/hmac-generator.vue')['default']
'Home.page': typeof import('./src/pages/Home.page.vue')['default']
@@ -130,21 +131,14 @@ 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']
NGi: typeof import('naive-ui')['NGi']
NGrid: typeof import('naive-ui')['NGrid']
NH1: typeof import('naive-ui')['NH1']
NH3: typeof import('naive-ui')['NH3']
NIcon: typeof import('naive-ui')['NIcon']
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']
+2 -3
View File
@@ -58,12 +58,14 @@
"date-fns": "^2.29.3",
"dompurify": "^3.0.6",
"emojilib": "^3.0.10",
"fflate": "^0.8.2",
"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",
"js-base64": "^3.7.7",
"json5": "^2.2.3",
"jwt-decode": "^3.1.2",
"libphonenumber-js": "^1.10.28",
@@ -81,7 +83,6 @@
"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 +112,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 +133,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",
+24 -637
View File
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,88 @@
<script setup lang="ts">
import * as fflate from 'fflate';
import { Base64 } from 'js-base64';
import TextareaCopyable from '@/components/TextareaCopyable.vue';
import { withDefaultOnError } from '@/utils/defaults';
const compressedInput = ref('');
const decompressedOutput = computed(() => withDefaultOnError(() => {
const compressedBuf = Base64.toUint8Array(compressedInput.value);
return fflate.strFromU8(fflate.decompressSync(compressedBuf));
}, '# invalid compressed base64 string'));
const rawInput = ref('');
const compressedGzipOutput = computed(() => withDefaultOnError(() => Base64.fromUint8Array(fflate.gzipSync(fflate.strToU8(rawInput.value))), ''));
const compressedDeflateOutput = computed(() => withDefaultOnError(() => Base64.fromUint8Array(fflate.deflateSync(fflate.strToU8(rawInput.value))), ''));
const compressedZlibOutput = computed(() => withDefaultOnError(() => Base64.fromUint8Array(fflate.zlibSync(fflate.strToU8(rawInput.value))), ''));
</script>
<template>
<div style="max-width: 600px;">
<c-card title="Compress string" mb-5>
<c-input-text
v-model:value="rawInput"
multiline
placeholder="Put your string here..."
rows="5"
label="String to compress"
raw-text
mb-5
/>
<div>
<h3>GZIP compressed string</h3>
<TextareaCopyable
:value="compressedGzipOutput"
:word-wrap="true"
multiline
placeholder="The GZip compressed version of your string will be here"
mb-5
/>
</div>
<div>
<h3>Zlib compressed string</h3>
<TextareaCopyable
:value="compressedZlibOutput"
:word-wrap="true"
multiline
placeholder="The Zlib compressed version of your string will be here"
mb-5
/>
</div>
<div>
<h3>Deflate compressed string</h3>
<TextareaCopyable
:value="compressedDeflateOutput"
:word-wrap="true"
multiline
placeholder="The Deflate compressed version of your string will be here"
mb-5
/>
</div>
</c-card>
<c-card title="Decompress string">
<c-input-text
v-model:value="compressedInput"
multiline
placeholder="Your compressed string..."
rows="5"
label="Compressed string to decompress"
mb-5
/>
<div>
<h3>Decompressed string</h3>
<TextareaCopyable
v-model:value="decompressedOutput"
:word-wrap="true"
multiline
placeholder="The decompressed string will be here"
mb-5
/>
</div>
</c-card>
</div>
</template>
+12
View File
@@ -0,0 +1,12 @@
import { FileZip } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'GZip/Deflate converter',
path: '/gzip-converter',
description: 'Convert text from/to gzip/deflate',
keywords: ['gzip', 'deflate', 'converter'],
component: () => import('./gzip-converter.vue'),
icon: FileZip,
createdAt: new Date('2024-03-09'),
});
+5 -15
View File
@@ -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 x509CertificateGenerator } from './x509-certificate-generator';
import { tool as gzipConverter } from './gzip-converter';
import { tool as safelinkDecoder } from './safelink-decoder';
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
import { tool as numeronymGenerator } from './numeronym-generator';
import { tool as macAddressGenerator } from './mac-address-generator';
@@ -85,20 +86,7 @@ import { tool as yamlViewer } from './yaml-viewer';
export const toolsByCategory: ToolCategory[] = [
{
name: 'Crypto',
components: [
tokenGenerator,
hashText,
bcrypt,
uuidGenerator,
ulidGenerator,
cypher,
bip39,
hmacGenerator,
rsaKeyPairGenerator,
x509CertificateGenerator,
passwordStrengthAnalyser,
pdfSignatureChecker,
],
components: [tokenGenerator, hashText, bcrypt, uuidGenerator, ulidGenerator, cypher, bip39, hmacGenerator, rsaKeyPairGenerator, passwordStrengthAnalyser, pdfSignatureChecker],
},
{
name: 'Converter',
@@ -120,6 +108,7 @@ export const toolsByCategory: ToolCategory[] = [
listConverter,
tomlToJson,
tomlToYaml,
gzipConverter,
],
},
{
@@ -140,6 +129,7 @@ export const toolsByCategory: ToolCategory[] = [
userAgentParser,
httpStatusCodes,
jsonDiff,
safelinkDecoder,
],
},
{
+12
View File
@@ -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&amp;data=05%7C02%7C%7C1ed07253975b46da1d1508dc3443752a%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638442711583216725%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&amp;sdata=%2BQY0HBnnxfI7pzZoxzlhZdDvYu80LwQB0zUUjrffVnk%3D&amp;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,12 +0,0 @@
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'),
});
@@ -1,119 +0,0 @@
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,
};
}
@@ -1,196 +0,0 @@
<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>
-2
View File
@@ -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: {