Merge branch 'up/feat/seip-auth-tester' into chore/all-my-stuffs

This commit is contained in:
ShareVB committed 2024-12-01 12:42:51 +01:00
commit 1331b34c62
7 files changed
+139 -1

No files matched your search

+10 -1
View File
@@ -457,4 +457,13 @@ tools:
unicode-to-java-entities:
title: Unicode Characters to Java Entities Converter
description: Unicode Characters to Java Entities Converter and vice-versa
description: Unicode Characters to Java Entities Converter and vice-versa
sip-auth:
password: SIP password
password-tips: Enter a password...
message: SIP message
message-tips: Paste your SIP message here...
result: Result
sucess: Sucess
failure: Failure
+10
View File
@@ -404,3 +404,13 @@ tools:
text-to-binary:
title: 文本到 ASCII 二进制
description: 将文本转换为其 ASCII 二进制表示形式,反之亦然。
sip-auth:
title: SIP 认证校验
description: 这个工具能够帮你验证 SIP 授权头。该工具所有运算过程都在浏览器中进行,并不会通过网络传输敏感信息,所以请放心使用。
password: SIP 密码
password-tips: 输入密码...
message: SIP 消息文本
message-tips: 在此处粘贴您的 SIP 消息...
result: 检测结果
sucess: 成功
failure: 失败
+2
View File
@@ -118,6 +118,7 @@ import { tool as ttlCalculator } from './ttl-calculator';
import { tool as unicodeFormatter } from './unicode-formatter';
import { tool as raidCalculator } from './raid-calculator';
import { tool as nanoidGenerator } from './nanoid-generator';
import { tool as sipAuth } from './sip-auth';
import { tool as asciiTextDrawer } from './ascii-text-drawer';
@@ -484,6 +485,7 @@ export const toolsByCategory: ToolCategory[] = [
option43Generator,
portNumbers,
raidCalculator,
sipAuth,
],
},
{
+12
View File
@@ -0,0 +1,12 @@
import { ShieldCheck } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'SIP Authorization',
path: '/sip-auth',
description: 'This tool helps you to verify the SIP authorization header. The tool performs all calculations in the browser and does not transmit sensitive information over the network, so feel free to use it.',
keywords: ['sip', 'authorization'],
component: () => import('./sip-auth.vue'),
icon: ShieldCheck,
createdAt: new Date('2024-04-11'),
});
@@ -0,0 +1,30 @@
import { describe, expect, it } from 'vitest';
import { getAuthHeaderCheckResult } from './sip-auth.service';
const message = `REGISTER sip:172.21.169.226 SIP/2.0
Via: SIP/2.0/UDP 172.21.160.1:64712;rport;branch=z9hG4bKPja70ba2f5f4464081a3925196ebd4e7f9
Max-Forwards: 70
From: <sip:1000@172.21.169.226>;tag=8db088f1039e49b691e53e5f172ace98
To: <sip:1000@172.21.169.226>
Call-ID: be95702faee84a8ebc8ccf94c5ca5492
CSeq: 37808 REGISTER
User-Agent: MicroSIP/3.21.3
Contact: <sip:1000@172.21.160.1:64712;ob>
Expires: 300
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Authorization: Digest username="1000", realm="172.21.169.226", nonce="d99a372c-340a-4ec9-91ed-53ad8f318ae0", uri="sip:172.21.169.226", response="7bdeb758d949a3c5e8d125fafbac1d5e", algorit=MD5, cnonce="3a8c445fb7ff48aeb8c422b00afaaddc", qop=auth, nc=00000001
Content-Length: 0`;
describe('getAuthHeaderCheckResult', () => {
it('should return "check success" for valid authentication', () => {
const password = '1234';
const result = getAuthHeaderCheckResult({ message, password });
expect(result).toBe(true);
});
it('should return "check failed" for invalid authentication', () => {
const password = '12345';
const result = getAuthHeaderCheckResult({ message, password });
expect(result).toBe(false);
});
});
+36
View File
@@ -0,0 +1,36 @@
import { MD5 } from 'crypto-js';
export { getAuthHeaderCheckResult };
function getAuthHeaderCheckResult({ message, password }: { message: string; password: string }) {
let calculatedHash;
const method = extractComponent('^([A-Z]+) sip', message);
const username = extractComponent('username="([^"]+)"', message);
const realm = extractComponent('realm="([^"]+)"', message);
const uri = extractComponent('uri="([^"]+)"', message);
const nonce = extractComponent('[^c]nonce="([^"]+)"', message);
const cnonce = extractComponent('cnonce="([^"]+)"', message);
const nc = extractComponent('nc=([0-9a-f]+)', message);
const qop = extractComponent('qop="?(auth|auth-int)"?', message);
const response = extractComponent('response="([^"]+)"', message);
const ha1 = MD5(`${username}:${realm}:${password}`).toString();
const ha2 = MD5(`${method}:${uri}`).toString();
if (qop.toLowerCase() === 'auth') {
calculatedHash = MD5(`${ha1}:${nonce}:${nc}:${cnonce}:${qop}:${ha2}`).toString();
}
else {
calculatedHash = MD5(`${ha1}:${nonce}:${cnonce}`).toString();
}
return (response === calculatedHash);
}
function extractComponent(regex: string, source: string): string {
const processor = new RegExp(regex, 'i');
const matchResult = processor.exec(source);
if (matchResult !== null && matchResult.length > 1) {
return matchResult[1];
}
else {
return 'Not Found';
}
}
+39
View File
@@ -0,0 +1,39 @@
<script setup lang="ts">
import { getAuthHeaderCheckResult } from './sip-auth.service';
const password = ref('');
const { t } = useI18n();
function transformer(value: string) {
if (value !== '' && password.value !== '') {
const Result = getAuthHeaderCheckResult({ message: value, password: password.value });
if (Result) {
return t('tools.sip-auth.sucess');
}
else {
return t('tools.sip-auth.failure');
// return `11 calculatedHash: ${calculatedHash}, response: ${response}`;
}
}
}
</script>
<template>
<div flex flex-col gap-4>
<c-input-text
v-model:value="password"
type="password"
:placeholder="$t('tools.sip-auth.password-tips')"
autofocus
raw-text
:label="$t('tools.sip-auth.password')"
/>
<format-transformer
:input-label="$t('tools.sip-auth.message')"
:input-placeholder="$t('tools.sip-auth.message-tips')"
:output-label="$t('tools.sip-auth.result')"
:transformer="transformer"
autosize
/>
</div>
</template>