Skip to content

Commit

Permalink
feat(new tool): WPA PSK Raw Key Generator
Browse files Browse the repository at this point in the history
Fix #1236
  • Loading branch information
sharevb committed Aug 25, 2024
1 parent 318fb6e commit 8b93379
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 1 deletion.
2 changes: 2 additions & 0 deletions components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ declare module '@vue/runtime-core' {
MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default']
MimeTypes: typeof import('./src/tools/mime-types/mime-types.vue')['default']
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
NButton: typeof import('naive-ui')['NButton']
NCode: typeof import('naive-ui')['NCode']
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
Expand Down Expand Up @@ -185,6 +186,7 @@ declare module '@vue/runtime-core' {
UserAgentResultCards: typeof import('./src/tools/user-agent-parser/user-agent-result-cards.vue')['default']
UuidGenerator: typeof import('./src/tools/uuid-generator/uuid-generator.vue')['default']
WifiQrCodeGenerator: typeof import('./src/tools/wifi-qr-code-generator/wifi-qr-code-generator.vue')['default']
WpaPskGenerator: typeof import('./src/tools/wpa-psk-generator/wpa-psk-generator.vue')['default']
XmlFormatter: typeof import('./src/tools/xml-formatter/xml-formatter.vue')['default']
XmlToJson: typeof import('./src/tools/xml-to-json/xml-to-json.vue')['default']
YamlToJson: typeof import('./src/tools/yaml-to-json-converter/yaml-to-json.vue')['default']
Expand Down
16 changes: 15 additions & 1 deletion src/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { tool as base64FileConverter } from './base64-file-converter';
import { tool as base64StringConverter } from './base64-string-converter';
import { tool as basicAuthGenerator } from './basic-auth-generator';
import { tool as emailNormalizer } from './email-normalizer';
import { tool as wpaPskGenerator } from './wpa-psk-generator';

import { tool as asciiTextDrawer } from './ascii-text-drawer';

Expand Down Expand Up @@ -88,7 +89,20 @@ import { tool as yamlViewer } from './yaml-viewer';
export const toolsByCategory: ToolCategory[] = [
{
name: 'Crypto',
components: [tokenGenerator, hashText, bcrypt, uuidGenerator, ulidGenerator, cypher, bip39, hmacGenerator, rsaKeyPairGenerator, passwordStrengthAnalyser, pdfSignatureChecker],
components: [
tokenGenerator,
hashText,
bcrypt,
uuidGenerator,
ulidGenerator,
cypher,
bip39,
hmacGenerator,
rsaKeyPairGenerator,
passwordStrengthAnalyser,
pdfSignatureChecker,
wpaPskGenerator,
],
},
{
name: 'Converter',
Expand Down
12 changes: 12 additions & 0 deletions src/tools/wpa-psk-generator/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Wifi } from '@vicons/tabler';
import { defineTool } from '../tool';

export const tool = defineTool({
name: 'WPA PSK generator',
path: '/wpa-psk-generator',
description: 'WPA Pre-shared Key Generator to convert a WPA passphrase and SSID to the 256-bit pre-shared ("raw") key',
keywords: ['wpa', 'psk', 'pre', 'shared', 'key', 'ssid', 'passphrase', 'generator'],
component: () => import('./wpa-psk-generator.vue'),
icon: Wifi,
createdAt: new Date('2024-08-15'),
});
12 changes: 12 additions & 0 deletions src/tools/wpa-psk-generator/wpa-psk-generator.service.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { describe, expect, it } from 'vitest';
import { generateWpaPskRawKey } from './wpa-psk-generator.service';

describe('wpa-psk-generator', () => {
it('generateWpaPskRawKey should generate raw key', () => {
expect(generateWpaPskRawKey('test', 'test')).to.deep.eq({
passphrase: 'test',
psk: 'd630c5513becfd3952432bd7fcf098b7a40907f3214cf43551f1b8cfda873eccd55e2e0c6b8fed55feecdd7f21db4fb6b31c602fe3f5e58e7edd462b12e4acc4632aa41c4755646b8a52826cb76f3a984571c4cfc73a1a2684f55790fac9e1f6c6002faedcb6c2d47a3678139027b95641efbcecd934b712bf48db71a76d8915',
ssid: 'test',
});
});
});
15 changes: 15 additions & 0 deletions src/tools/wpa-psk-generator/wpa-psk-generator.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import CryptoJS from 'crypto-js';
import pbkdf2 from 'crypto-js/pbkdf2';

export function generateWpaPskRawKey(ssid: string, passphrase: string) {
const psk = pbkdf2(passphrase, ssid, {
keySize: 32,
iterations: 4096,
hasher: CryptoJS.algo.SHA1,
}).toString(CryptoJS.enc.Hex);
return {
ssid,
passphrase,
psk,
};
}
58 changes: 58 additions & 0 deletions src/tools/wpa-psk-generator/wpa-psk-generator.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<script setup lang="ts">
import { generateWpaPskRawKey } from './wpa-psk-generator.service';
import { useValidation } from '@/composable/validation';
const ssid = ref('');
const passphrase = ref('');
const wpaPSKRawKey = ref('');
function computeRawKey() {
try {
wpaPSKRawKey.value = generateWpaPskRawKey(ssid.value, passphrase.value)?.psk;
}
catch (e: any) {
wpaPSKRawKey.value = e.toString();
}
}
const ssidValidation = useValidation({
source: ssid,
rules: [
{
validator: v => v !== '',
message: 'SSID must not be empty.',
},
],
});
</script>

<template>
<div style="max-width: 600px;">
<c-card title="Wifi Infos" mb-2>
<c-input-text
v-model:value="ssid"
label="SSID"
label-position="left"
placeholder="Put your SSID here..."
:validation="ssidValidation"
mb-2
/>

<c-input-text
v-model:value="passphrase"
label="Passphrase"
label-position="left"
placeholder="Put your Passphrase here..."
mb-2
/>

<div flex justify-center>
<n-button @click="computeRawKey()">Compute</n-button>

Check warning on line 50 in src/tools/wpa-psk-generator/wpa-psk-generator.vue

View workflow job for this annotation

GitHub Actions / ci

Expected 1 line break after opening tag (`<n-button>`), but no line breaks found

Check warning on line 50 in src/tools/wpa-psk-generator/wpa-psk-generator.vue

View workflow job for this annotation

GitHub Actions / ci

Expected 1 line break before closing tag (`</n-button>`), but no line breaks found
</div>
</c-card>

<c-card title="WPA PSK Raw Key (256 bits)">
<TextareaCopyable :value="wpaPSKRawKey" />
</c-card>
</div>
</template>

0 comments on commit 8b93379

Please sign in to comment.