-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview.js
More file actions
297 lines (263 loc) · 12.9 KB
/
view.js
File metadata and controls
297 lines (263 loc) · 12.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
const AudioContext = window.AudioContext || window.webkitAudioContext;
let audioCtx;
function initAudio() { if (!audioCtx) audioCtx = new AudioContext(); }
function playBeep(freq, type, duration, vol) {
if (!audioCtx) return;
const osc = audioCtx.createOscillator();
const gain = audioCtx.createGain();
osc.type = type;
osc.frequency.setValueAtTime(freq, audioCtx.currentTime);
gain.gain.setValueAtTime(vol, audioCtx.currentTime);
gain.gain.exponentialRampToValueAtTime(0.01, audioCtx.currentTime + duration);
osc.connect(gain);
gain.connect(audioCtx.destination);
osc.start();
osc.stop(audioCtx.currentTime + duration);
}
function base64ToBuffer(base64) {
const binaryString = window.atob(base64);
const len = binaryString.length;
const bytes = new Uint8Array(len);
for (let i = 0; i < len; i++) { bytes[i] = binaryString.charCodeAt(i); }
return bytes.buffer;
}
async function deriveKey(pinStr, saltBase64) {
const enc = new TextEncoder();
const saltBuffer = base64ToBuffer(saltBase64);
const keyMaterial = await window.crypto.subtle.importKey("raw", enc.encode(pinStr), { name: "PBKDF2" }, false, ["deriveKey"]);
return await window.crypto.subtle.deriveKey(
{ name: "PBKDF2", salt: saltBuffer, iterations: 100000, hash: "SHA-256" },
keyMaterial, { name: "AES-GCM", length: 256 }, false, ["encrypt", "decrypt"]
);
}
async function decryptBuffer(encryptedBase64, key, ivBase64) {
const encryptedBuffer = base64ToBuffer(encryptedBase64);
const ivBuffer = new Uint8Array(base64ToBuffer(ivBase64));
return await window.crypto.subtle.decrypt({ name: "AES-GCM", iv: ivBuffer }, key, encryptedBuffer);
}
async function verifyBiometrics() {
try {
// [FIX 1] Check if OS actually has a system password/PIN set up.
// If not, bypass the lock completely to prevent the Windows "Admin Required" error.
if (window.PublicKeyCredential) {
const isAvailable = await window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable();
if (!isAvailable) {
console.warn("No system password/biometrics found. Bypassing check.");
return true;
}
} else {
return true; // Bypass if WebAuthn is entirely unsupported
}
const challenge = new Uint8Array(32);
window.crypto.getRandomValues(challenge);
await navigator.credentials.create({
publicKey: {
challenge,
rp: { name: "ZeroKey", id: window.location.hostname },
user: { id: new Uint8Array(16), name: "user", displayName: "User" },
pubKeyCredParams: [{ type: "public-key", alg: -7 }],
authenticatorSelection: {
authenticatorAttachment: "platform", // Forces local device lock screen/biometrics
userVerification: "required"
},
timeout: 60000
}
});
return true;
} catch (err) {
console.error("Biometric failed or cancelled:", err);
return false;
}
}
function getDistance(lat1, lon1, lat2, lon2) {
const R = 6371e3; const rad = Math.PI / 180;
const a = Math.sin((lat2-lat1)*rad/2)**2 + Math.cos(lat1*rad)*Math.cos(lat2*rad)*Math.sin((lon2-lon1)*rad/2)**2;
return R * (2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)));
}
function triggerGlitchLockout(reason) {
document.getElementById('mainCard').classList.add('glitch-active');
if (navigator.vibrate) navigator.vibrate([100, 50, 100, 50, 500]);
playBeep(150, 'sawtooth', 0.5, 0.5);
document.getElementById('lockedState').classList.add('hidden');
document.getElementById('destroyedState').classList.remove('hidden');
document.getElementById('destroyTitle').innerText = "SECURITY BREACH";
document.getElementById('destroyTitle').classList.replace('text-slate-400', 'text-red-500');
document.getElementById('destroyIcon').classList.replace('ph-wind', 'ph-shield-warning');
document.getElementById('destroyIcon').classList.replace('text-slate-400', 'text-red-500');
document.getElementById('destroyDesc').innerText = `${reason} Payload wiped.`;
}
function cipherReveal(element, finalString) {
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#$%&*<>";
let iterations = 0;
const interval = setInterval(() => {
element.innerText = finalString.split("").map((char, index) => {
if(index < iterations) return char;
return chars[Math.floor(Math.random() * chars.length)];
}).join("");
if(iterations >= finalString.length) clearInterval(interval);
iterations += 1/2;
}, 30);
}
const urlParams = new URLSearchParams(window.location.search);
const payloadId = urlParams.get('id');
const hashKey = window.location.hash.substring(1);
let activeObjectUrl = null;
let failedAttempts = 0;
document.getElementById('verifyHumanBtn').addEventListener('click', () => {
initAudio(); playBeep(600, 'sine', 0.1, 0.1);
document.getElementById('antiBotState').classList.add('hidden');
document.getElementById('lockedState').classList.remove('hidden');
if (hashKey === "LOCKED") document.getElementById('pinContainer').classList.remove('hidden');
});
document.getElementById('decryptBtn').addEventListener('click', async () => {
if (!payloadId || !hashKey) return alert("Broken link.");
let activePin = hashKey;
if (hashKey === "LOCKED") {
activePin = document.getElementById('receiverPin').value.trim();
if (!activePin) return alert("Decryption PIN is required.");
} else {
const isAuthorized = await verifyBiometrics();
if (!isAuthorized) {
failedAttempts++;
if (failedAttempts >= 3) {
await fetch('/api/destroySecret', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ id: payloadId })
});
return triggerGlitchLockout("Max biometric failures.");
}
return alert("Authentication required by device owner.");
}
}
const btn = document.getElementById('decryptBtn');
btn.innerHTML = '<i class="ph ph-spinner animate-spin text-xl"></i> Decrypting...';
btn.disabled = true;
try {
const response = await fetch(`/api/getSecret?id=${payloadId}`, { method: 'GET' });
if (!response.ok) throw new Error("Intercepted or destroyed.");
const dbData = await response.json();
const cryptoKey = await deriveKey(activePin, dbData.salt);
const decryptedTextBuffer = await decryptBuffer(dbData.encrypted_payload, cryptoKey, dbData.iv);
const payloadJson = new TextDecoder().decode(decryptedTextBuffer);
const payload = JSON.parse(payloadJson);
if (payload.geo) {
btn.innerHTML = '<i class="ph ph-crosshair animate-pulse text-xl"></i> Verifying GPS...';
try {
await new Promise((res, rej) => navigator.geolocation.getCurrentPosition(
pos => {
const d = getDistance(payload.geo.lat, payload.geo.lng, pos.coords.latitude, pos.coords.longitude);
// [FIX 2] Split the error logic. Only reject as 'bounds' if they are physically too far away.
if (d > 50) {
rej({ type: 'bounds', msg: `Out of bounds by ${Math.round(d)}m.` });
} else {
res();
}
},
err => rej({ type: 'denied', msg: "Location access denied or timed out. Please allow GPS to decrypt." }),
{ enableHighAccuracy: true, timeout: 15000 }
));
} catch (geoErr) {
if (geoErr.type === 'bounds') {
// True security breach. Burn the payload.
await fetch('/api/destroySecret', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ id: payloadId })
});
return triggerGlitchLockout(geoErr.msg);
} else {
// Just a denied permission or timeout. Don't delete data, just reset the button.
alert(geoErr.msg);
btn.innerHTML = '<i class="ph ph-fire text-xl"></i> Decrypt & Read';
btn.disabled = false;
return; // Halt execution safely
}
}
}
if (payload.file) {
btn.innerHTML = '<i class="ph ph-file-lock animate-spin text-xl"></i> Rendering Media...';
activeObjectUrl = payload.file.data;
document.getElementById('mediaContainer').classList.remove('hidden');
if (payload.file.type && payload.file.type.startsWith('image/')) {
const img = document.getElementById('decryptedImage');
img.src = activeObjectUrl;
img.classList.remove('hidden');
} else {
const fileDiv = document.getElementById('decryptedFile');
document.getElementById('decryptedFileName').innerHTML = `<i class="ph ph-file-dashed text-blue-400 text-xl"></i> <span class="truncate">${payload.file.name}</span>`;
const dwnBtn = document.getElementById('downloadFileBtn');
dwnBtn.href = activeObjectUrl;
dwnBtn.download = payload.file.name;
fileDiv.classList.remove('hidden');
fileDiv.classList.add('flex');
}
}
await fetch('/api/destroySecret', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ id: payloadId })
});
playBeep(800, 'sine', 0.1, 0.2);
window.history.replaceState(null, null, window.location.pathname);
document.getElementById('lockedState').classList.add('hidden');
document.getElementById('decryptedState').classList.remove('hidden');
cipherReveal(document.getElementById('secretMessage'), payload.text || "No text payload attached.");
startSelfDestructTimer();
} catch (error) {
failedAttempts++;
if (failedAttempts >= 3) {
await fetch('/api/destroySecret', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ id: payloadId })
});
triggerGlitchLockout("Decryption failed.");
} else {
alert("Decryption failed. Wrong PIN or corrupted data.");
}
btn.innerHTML = '<i class="ph ph-fire text-xl"></i> Decrypt & Read';
btn.disabled = false;
}
});
function startSelfDestructTimer() {
let timeLeft = 30;
const timeDisplay = document.getElementById('time');
const burnRing = document.getElementById('burnRing');
const containers = document.querySelectorAll('.secret-text-container');
const secretMessage = document.getElementById('secretMessage');
const countdown = setInterval(() => {
timeLeft--;
timeDisplay.innerText = timeLeft;
burnRing.style.strokeDashoffset = 125.6 - ((timeLeft / 30) * 125.6);
if (timeLeft <= 10 && timeLeft > 0) {
playBeep(100, 'sine', 0.1, 0.5);
try { gsap.to(timeDisplay, { color: "#ef4444", scale: 1.25, yoyo: true, repeat: 1, duration: 0.2 }); } catch(e){}
}
if (timeLeft <= 0) {
clearInterval(countdown);
playBeep(200, 'square', 0.3, 0.1);
if (navigator.vibrate) navigator.vibrate([50, 50, 300]);
secretMessage.classList.add('disintegrate');
if(document.getElementById('decryptedImage')) document.getElementById('decryptedImage').classList.add('disintegrate');
try {
gsap.to(containers, {
opacity: 0, height: 0, duration: 1.5, delay: 1.5,
onComplete: () => {
document.getElementById('decryptedState').classList.add('hidden');
document.getElementById('destroyedState').classList.remove('hidden');
secretMessage.innerText = '';
document.getElementById('decryptedImage').src = '';
activeObjectUrl = null;
}
});
} catch(e) {
document.getElementById('decryptedState').classList.add('hidden');
document.getElementById('destroyedState').classList.remove('hidden');
secretMessage.innerText = '';
document.getElementById('decryptedImage').src = '';
activeObjectUrl = null;
}
}
}, 1000);
}