first commit

This commit is contained in:
Schluffe committed 2026-09-07 18:55:05 +02:00
commit d198332c92
15 files changed
+1125

No files matched your search

+32
View File
@@ -0,0 +1,32 @@
<script setup>
import { ref } from 'vue';
import SendPanel from './components/SendPanel.vue';
import ReceivePanel from './components/ReceivePanel.vue';
const mode = ref('send');
</script>
<template>
<h1>HellCon</h1>
<p class="subtitle">
Peer-to-peer file sharing. No server, no account — files go straight from
browser to browser over WebRTC.
</p>
<div class="tabs" style="width: 100%; max-width: 680px">
<button :class="{ active: mode === 'send' }" @click="mode = 'send'">Send</button>
<button :class="{ active: mode === 'receive' }" @click="mode = 'receive'">Receive</button>
</div>
<SendPanel v-if="mode === 'send'" />
<ReceivePanel v-else />
<footer>
<p>
All transfers are end-to-end encrypted (WebRTC/DTLS) and never pass
through this server — it only delivers this page. Verify the security
check codes with your peer to exclude interception. You are responsible
for what you send, and for whom you send it to.
</p>
</footer>
</template>
+190
View File
@@ -0,0 +1,190 @@
<script setup>
import { ref, computed, onBeforeUnmount } from 'vue';
import {
createPeerConnection,
createAnswerCode,
getFingerprints,
STUN_PROVIDERS,
} from '../lib/webrtc';
const STATUS = {
idle: 'Paste the sender\'s connection code to start.',
'creating-answer': 'Gathering connection info…',
'answer-ready': 'Send the code below back to the sender.',
connecting: 'Waiting for the P2P connection…',
receiving: 'Receiving…',
done: 'File received!',
closed: 'Connection closed.',
};
const step = ref('idle');
const offerInput = ref('');
const answerCode = ref('');
const progress = ref(0);
const error = ref('');
const copied = ref(false);
const fps = ref(null);
const stunChoice = ref('google');
const customStun = ref('');
const fileName = ref('');
const fileSize = ref(0);
const downloadUrl = ref('');
let pc = null;
const statusText = computed(() => STATUS[step.value] ?? '');
const resolvedStun = computed(() => {
if (stunChoice.value === 'custom') {
const raw = customStun.value.trim();
return raw ? raw : null;
}
return STUN_PROVIDERS.find((p) => p.id === stunChoice.value)?.url ?? null;
});
onBeforeUnmount(() => {
pc?.close();
if (downloadUrl.value) URL.revokeObjectURL(downloadUrl.value);
});
async function acceptOffer() {
error.value = '';
if (downloadUrl.value) {
URL.revokeObjectURL(downloadUrl.value);
downloadUrl.value = '';
}
progress.value = 0;
fps.value = null;
pc?.close();
pc = createPeerConnection(resolvedStun.value);
pc.ondatachannel = (e) => setupReceiver(e.channel);
pc.onconnectionstatechange = () => {
if (['disconnected', 'failed', 'closed'].includes(pc.connectionState)) {
if (step.value !== 'done') step.value = 'closed';
}
};
step.value = 'creating-answer';
try {
answerCode.value = await createAnswerCode(pc, offerInput.value);
fps.value = getFingerprints(pc);
step.value = 'answer-ready';
} catch {
step.value = 'idle';
error.value = 'Invalid offer code — paste the full code from the sender.';
}
}
function setupReceiver(dc) {
dc.binaryType = 'arraybuffer';
let meta = null;
let chunks = [];
let received = 0;
dc.onopen = () => {
if (step.value === 'answer-ready') step.value = 'connecting';
};
dc.onmessage = (e) => {
if (typeof e.data === 'string') {
// Metadata frame
meta = JSON.parse(e.data);
fileName.value = meta.name;
fileSize.value = meta.size;
received = 0;
if (meta.size === 0) finish(meta, []);
else step.value = 'receiving';
return;
}
chunks.push(e.data);
received += e.data.byteLength;
if (meta) {
progress.value = Math.min(100, Math.floor((received / meta.size) * 100));
if (received >= meta.size) finish(meta, chunks);
}
};
}
function finish(meta, chunks) {
if (downloadUrl.value) URL.revokeObjectURL(downloadUrl.value);
const blob = new Blob(chunks, { type: meta.type || 'application/octet-stream' });
downloadUrl.value = URL.createObjectURL(blob);
progress.value = 100;
step.value = 'done';
}
async function copy(text) {
await navigator.clipboard.writeText(text);
copied.value = true;
setTimeout(() => (copied.value = false), 1500);
}
</script>
<template>
<div class="panel">
<label class="step">1 — Choose a STUN provider</label>
<select v-model="stunChoice" class="stun-select">
<option v-for="p in STUN_PROVIDERS" :key="p.id" :value="p.id">
{{ p.label }}
</option>
<option value="custom">Custom…</option>
</select>
<input
v-if="stunChoice === 'custom'"
v-model="customStun"
class="stun-input"
type="text"
placeholder="stun:your.domain:3478"
/>
<p class="status stun-hint">
STUN is only needed for peers on different networks — a stateless UDP
lookup of your public IP; it never sees the connection or the file.
Same-network or VPN peers work with "None".
</p>
<label class="step">2 — Paste the sender's connection code</label>
<textarea
v-model="offerInput"
placeholder="Paste the code from the sender…"
/>
<button class="primary" :disabled="!offerInput.trim()" @click="acceptOffer">
Accept & create answer
</button>
<template v-if="answerCode">
<label class="step">3 — Send this answer code back to the sender</label>
<textarea :value="answerCode" readonly @focus="$event.target.select()" />
<button @click="copy(answerCode)">{{ copied ? 'Copied!' : 'Copy code' }}</button>
</template>
<div class="progress" v-if="step === 'receiving' || step === 'done'">
<div :style="{ width: progress + '%' }"></div>
</div>
<div v-if="fps" class="fingerprint">
<label class="step">Security check</label>
<div class="fp-row">
<span>Your code</span>
<code>{{ fps.local }}</code>
</div>
<div class="fp-row">
<span>Their code</span>
<code>{{ fps.remote }}</code>
</div>
<p class="status">
To rule out an intercepted exchange, compare with your peer over a
channel you trust: your "Your code" must equal their "Their code",
and vice versa.
</p>
</div>
<p class="status">{{ statusText }}</p>
<p class="error" v-if="error">{{ error }}</p>
<div v-if="downloadUrl" class="file-chip">
<span>{{ fileName }}</span>
<a class="download" :href="downloadUrl" :download="fileName">Save file</a>
</div>
</div>
</template>
+248
View File
@@ -0,0 +1,248 @@
<script setup>
import { ref, computed } from 'vue';
import {
createPeerConnection,
createOfferCode,
acceptAnswerCode,
getFingerprints,
STUN_PROVIDERS,
CHUNK_SIZE,
MAX_BUFFERED,
waitForBufferDrain,
} from '../lib/webrtc';
const STATUS = {
idle: 'Pick a file to start.',
'creating-offer': 'Gathering connection info…',
'offer-ready': 'Send the code below to the receiver (any chat works).',
connecting: 'Answer accepted — waiting for the P2P connection…',
sending: 'Transferring…',
done: 'Transfer complete!',
closed: 'Connection closed.',
};
const file = ref(null);
const step = ref('idle');
const offerCode = ref('');
const answerInput = ref('');
const progress = ref(0);
const error = ref('');
const copied = ref(false);
const dragover = ref(false);
const fps = ref(null);
const stunChoice = ref('google');
const customStun = ref('');
let pc = null;
let dc = null;
const statusText = computed(() => STATUS[step.value] ?? '');
const resolvedStun = computed(() => {
if (stunChoice.value === 'custom') {
const raw = customStun.value.trim();
return raw ? raw : null;
}
return STUN_PROVIDERS.find((p) => p.id === stunChoice.value)?.url ?? null;
});
function reset() {
pc?.close();
pc = null;
dc = null;
offerCode.value = '';
answerInput.value = '';
progress.value = 0;
error.value = '';
copied.value = false;
fps.value = null;
step.value = 'idle';
}
function pickFiles(e) {
const f = e.target?.files?.[0] ?? e.dataTransfer?.files?.[0];
if (f) {
reset();
file.value = f;
}
}
async function makeOffer() {
if (!file.value) return;
error.value = '';
step.value = 'creating-offer';
pc = createPeerConnection(resolvedStun.value);
pc.onconnectionstatechange = () => {
if (pc && ['disconnected', 'failed', 'closed'].includes(pc.connectionState)) {
step.value = 'closed';
}
};
dc = pc.createDataChannel('file');
dc.binaryType = 'arraybuffer';
dc.onopen = () => sendFile();
dc.onclose = () => {
if (step.value === 'sending' && progress.value < 100) step.value = 'closed';
};
try {
offerCode.value = await createOfferCode(pc);
step.value = 'offer-ready';
} catch (err) {
error.value = String(err);
step.value = 'idle';
}
}
async function useAnswer() {
if (!pc) return;
error.value = '';
try {
await acceptAnswerCode(pc, answerInput.value);
fps.value = getFingerprints(pc);
step.value = 'connecting';
} catch {
error.value = 'Invalid answer code — paste the full code from the receiver.';
}
}
async function sendFile() {
const f = file.value;
if (!dc || !f) return;
step.value = 'sending';
progress.value = 0;
// First frame: metadata as JSON. Everything after is raw bytes.
dc.send(JSON.stringify({ name: f.name, size: f.size, type: f.type }));
let sent = 0;
try {
for (let offset = 0; offset < f.size; offset += CHUNK_SIZE) {
if (dc.readyState !== 'open') break;
if (dc.bufferedAmount > MAX_BUFFERED) await waitForBufferDrain(dc);
const buf = await f.slice(offset, offset + CHUNK_SIZE).arrayBuffer();
dc.send(buf);
sent += buf.byteLength;
progress.value = Math.floor((sent / Math.max(f.size, 1)) * 100);
}
if (dc.readyState === 'open') {
progress.value = 100;
step.value = 'done';
}
} catch (err) {
error.value = String(err);
step.value = 'closed';
}
}
async function copy(text) {
await navigator.clipboard.writeText(text);
copied.value = true;
setTimeout(() => (copied.value = false), 1500);
}
function formatBytes(n) {
if (n < 1024) return n + ' B';
const u = ['KiB', 'MiB', 'GiB'];
let v = n;
let i = -1;
do {
v /= 1024;
i++;
} while (v >= 1024 && i < u.length - 1);
return v.toFixed(1) + ' ' + u[i];
}
</script>
<template>
<div class="panel">
<label class="step">1 — Choose a file</label>
<div
class="dropzone"
:class="{ dragover }"
@dragover.prevent="dragover = true"
@dragleave="dragover = false"
@drop.prevent="dragover = false; pickFiles($event)"
@click="$refs.input.click()"
>
<span v-if="!file">Drop a file here or click to browse</span>
<div v-else class="file-chip" @click.stop>
<span>{{ file.name }}</span>
<span class="status">{{ formatBytes(file.size) }}</span>
</div>
<input
ref="input"
type="file"
style="display: none"
@change="pickFiles"
/>
</div>
<template v-if="file">
<label class="step">2 — Choose a STUN provider</label>
<select v-model="stunChoice" class="stun-select">
<option v-for="p in STUN_PROVIDERS" :key="p.id" :value="p.id">
{{ p.label }}
</option>
<option value="custom">Custom…</option>
</select>
<input
v-if="stunChoice === 'custom'"
v-model="customStun"
class="stun-input"
type="text"
placeholder="stun:your.domain:3478"
/>
<p class="status stun-hint">
STUN is only needed for peers on different networks — a stateless UDP
lookup of your public IP; it never sees the connection or the file.
Same-network or VPN peers work with "None".
</p>
<label class="step">3 — Create your connection code</label>
<button class="primary" :disabled="step !== 'idle'" @click="makeOffer">
Create code
</button>
<template v-if="offerCode">
<textarea :value="offerCode" readonly @focus="$event.target.select()" />
<button @click="copy(offerCode)">{{ copied ? 'Copied!' : 'Copy code' }}</button>
</template>
<template v-if="offerCode">
<label class="step">4 — Paste the receiver's answer code</label>
<textarea
v-model="answerInput"
placeholder="Paste the code the receiver sends back…"
/>
<button class="primary" :disabled="!answerInput.trim()" @click="useAnswer">
Connect
</button>
</template>
<div class="progress" v-if="step === 'sending' || step === 'done'">
<div :style="{ width: progress + '%' }"></div>
</div>
<div v-if="fps" class="fingerprint">
<label class="step">Security check</label>
<div class="fp-row">
<span>Your code</span>
<code>{{ fps.local }}</code>
</div>
<div class="fp-row">
<span>Their code</span>
<code>{{ fps.remote }}</code>
</div>
<p class="status">
To rule out an intercepted exchange, compare with your peer over a
channel you trust: your "Your code" must equal their "Their code",
and vice versa.
</p>
</div>
<p class="status">{{ statusText }}</p>
<p class="error" v-if="error">{{ error }}</p>
</template>
</div>
</template>
+98
View File
@@ -0,0 +1,98 @@
// P2P with manual signaling: no server, no third party.
// Peers exchange SDP blobs by copy/paste. ICE gathering runs to completion
// so the full connection info fits in a single copyable string.
// Chunking / buffering for the data channel.
export const CHUNK_SIZE = 16 * 1024; // 16 KiB per message
export const MAX_BUFFERED = 1024 * 1024; // backpressure limit (bytes)
// Built-in public STUN providers. STUN is a stateless, unencrypted UDP
// lookup of your public IP — the server never sees connection or file data.
export const STUN_PROVIDERS = [
{ id: 'google', label: 'Google', url: 'stun:stun.l.google.com:19302' },
{ id: 'cloudflare', label: 'Cloudflare', url: 'stun:stun.cloudflare.com:3478' },
{ id: 'none', label: 'None (same-network / VPN peers only)', url: null },
];
// stunUrl: a URL from STUN_PROVIDERS, or a user-supplied "stun:host:port"
// string, or null for host candidates only.
export function createPeerConnection(stunUrl = null) {
return new RTCPeerConnection({
iceServers: stunUrl ? [{ urls: stunUrl }] : [],
});
}
function waitForIceComplete(pc) {
if (pc.iceGatheringState === 'complete') return Promise.resolve();
return new Promise((resolve, reject) => {
const onChange = () => {
if (pc.iceGatheringState === 'complete') {
pc.removeEventListener('icegatheringstatechange', onChange);
resolve();
}
};
pc.addEventListener('icegatheringstatechange', onChange);
setTimeout(() => {
pc.removeEventListener('icegatheringstatechange', onChange);
// Resolve anyway — partial candidate lists often still connect fine.
resolve();
}, 5000);
});
}
// Sender side: create an offer and return it as a copyable code.
export async function createOfferCode(pc) {
await pc.setLocalDescription(await pc.createOffer());
await waitForIceComplete(pc);
return encodeSignal(pc.localDescription.sdp);
}
// Receiver side: accept an offer code, return the answer code to send back.
export async function createAnswerCode(pc, offerText) {
await pc.setRemoteDescription({ type: 'offer', sdp: decodeSignal(offerText) });
await pc.setLocalDescription(await pc.createAnswer());
await waitForIceComplete(pc);
return encodeSignal(pc.localDescription.sdp);
}
// Sender side: apply the answer code the receiver sent back.
export function acceptAnswerCode(pc, answerText) {
return pc.setRemoteDescription({ type: 'answer', sdp: decodeSignal(answerText) });
}
// Anti-MITM check: extracts the DTLS certificate fingerprints from both
// descriptions and shortens them for human comparison.
// Rule: my "local" must equal the peer's "remote" (and vice versa).
// If both match, nobody interposed on the code exchange.
export function getFingerprints(pc) {
const extract = (sdp) => {
const m = sdp?.match(/a=fingerprint:(?:sha-256|sha-384|sha-512) ([0-9A-Fa-f:]+)/);
return m ? m[1].toUpperCase() : null;
};
// The fingerprint is already a certificate hash — its first 5 bytes
// (40 bits) are plenty for two humans to read to each other.
const shorten = (fp) => (fp ? fp.split(':').slice(0, 5).join(' ') : '—');
return {
local: shorten(extract(pc.localDescription?.sdp)),
remote: shorten(extract(pc.remoteDescription?.sdp)),
};
}
// SDP is ASCII plus CRLFs, so plain base64 is safe and compact enough (~2-4 KB).
export function encodeSignal(sdp) {
return btoa(sdp).replace(/=+$/, '');
}
export function decodeSignal(text) {
const clean = String(text).trim().replace(/\s+/g, '');
const padded = clean + '='.repeat((4 - (clean.length % 4)) % 4);
return atob(padded);
}
// Waits until the channel's send buffer drains below MAX_BUFFERED.
export function waitForBufferDrain(dc) {
dc.bufferedAmountLowThreshold = MAX_BUFFERED / 2;
return new Promise((resolve) => {
dc.addEventListener('bufferedamountlow', resolve, { once: true });
});
}
+5
View File
@@ -0,0 +1,5 @@
import { createApp } from 'vue';
import App from './App.vue';
import './style.css';
createApp(App).mount('#app');
+241
View File
@@ -0,0 +1,241 @@
:root {
color-scheme: dark;
--bg: #0f1117;
--panel: #181b24;
--border: #2a2f3d;
--accent: #e8452c;
--accent-soft: rgba(232, 69, 44, 0.15);
--text: #e8eaf0;
--muted: #8b91a3;
}
* {
box-sizing: border-box;
}
body {
margin: 0;
background: var(--bg);
color: var(--text);
font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
}
#app {
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
padding-inline: 0.9rem;
}
.panel {
width: 100%;
max-width: 680px;
background: var(--panel);
border: 1px solid var(--border);
border-radius: 12px;
padding: 1.5rem;
display: flex;
flex-direction: column;
gap: 0.9rem;
}
h1 {
margin: 2rem 0 0.25rem;
font-family: ui-monospace, 'Cascadia Code', monospace;
}
.subtitle {
color: var(--muted);
margin: 0 0 1.5rem;
font-size: 0.9rem;
}
.tabs {
display: flex;
gap: 0.5rem;
margin-bottom: 1rem;
}
.tabs button {
flex: 1;
}
button {
background: var(--panel);
color: var(--text);
border: 1px solid var(--border);
border-radius: 8px;
padding: 0.55rem 1rem;
font-size: 0.95rem;
cursor: pointer;
}
button:hover:not(:disabled) {
border-color: var(--accent);
}
button.primary {
background: var(--accent);
border-color: var(--accent);
color: #fff;
font-weight: 600;
}
button:disabled {
opacity: 0.45;
cursor: default;
}
.tabs button.active {
background: var(--accent-soft);
border-color: var(--accent);
color: var(--accent);
font-weight: 600;
}
label.step {
font-size: 0.8rem;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.06em;
color: var(--muted);
}
textarea {
width: 100%;
min-height: 90px;
resize: vertical;
background: var(--bg);
color: var(--text);
border: 1px solid var(--border);
border-radius: 8px;
padding: 0.6rem;
font-family: ui-monospace, monospace;
font-size: 0.75rem;
word-break: break-all;
}
.dropzone {
border: 2px dashed var(--border);
border-radius: 10px;
padding: 2rem;
text-align: center;
color: var(--muted);
cursor: pointer;
}
.dropzone.dragover {
border-color: var(--accent);
background: var(--accent-soft);
}
.progress {
height: 10px;
background: var(--bg);
border-radius: 6px;
overflow: hidden;
}
.progress > div {
height: 100%;
background: var(--accent);
transition: width 0.15s linear;
}
.status {
color: var(--muted);
font-size: 0.85rem;
}
.error {
color: #ff6b5e;
font-size: 0.85rem;
}
.file-chip {
display: flex;
justify-content: space-between;
align-items: center;
gap: 1rem;
background: var(--bg);
border: 1px solid var(--border);
border-radius: 8px;
padding: 0.6rem 0.9rem;
font-size: 0.9rem;
}
a.download {
color: var(--accent);
font-weight: 600;
}
.fingerprint {
background: var(--bg);
border: 1px solid var(--border);
border-radius: 8px;
padding: 0.75rem 0.9rem;
display: flex;
flex-direction: column;
gap: 0.4rem;
}
.fp-row {
display: flex;
justify-content: space-between;
align-items: center;
gap: 1rem;
font-size: 0.9rem;
}
.fp-row code {
font-family: ui-monospace, monospace;
color: var(--accent);
letter-spacing: 0.12em;
}
.fingerprint .status {
margin: 0.2rem 0 0;
}
footer {
max-width: 680px;
width: 100%;
margin: 1.5rem 0 2.5rem;
padding: 0 0.25rem;
color: var(--muted);
font-size: 0.78rem;
line-height: 1.55;
}
footer p {
margin: 0;
}
.stun-select,
.stun-input {
width: 100%;
background: var(--bg);
color: var(--text);
border: 1px solid var(--border);
border-radius: 8px;
padding: 0.55rem 0.75rem;
font-size: 0.95rem;
font-family: inherit;
}
.stun-input {
font-family: ui-monospace, monospace;
font-size: 0.85rem;
}
.stun-select:focus,
.stun-input:focus {
outline: none;
border-color: var(--accent);
}
p.stun-hint {
margin: -0.35rem 0 0;
font-size: 0.78rem;
}