-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
480 lines (437 loc) · 21 KB
/
Copy pathindex.html
File metadata and controls
480 lines (437 loc) · 21 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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>OpenNHP JS SDK Demo</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
<script>
tailwind.config = {
theme: {
extend: {
fontFamily: {
sans: ['Inter', 'sans-serif'],
mono: ['JetBrains Mono', 'monospace'],
},
colors: {
nhp: {
dark: '#0a0f1a',
card: '#111827',
border: '#1f2937',
accent: '#3b82f6',
success: '#10b981',
error: '#ef4444',
}
}
}
}
}
</script>
<style>
body {
background: radial-gradient(ellipse at top, #1a1f35 0%, #0a0f1a 50%, #050810 100%);
}
.glass-card {
background: rgba(17, 24, 39, 0.7);
backdrop-filter: blur(12px);
border: 1px solid rgba(255, 255, 255, 0.08);
}
.input-field {
background: rgba(0, 0, 0, 0.3);
border: 1px solid rgba(255, 255, 255, 0.1);
transition: all 0.3s ease;
}
.input-field:focus {
border-color: #3b82f6;
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}
.btn-primary {
background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
transition: all 0.3s ease;
}
.btn-primary:hover {
transform: translateY(-1px);
box-shadow: 0 4px 20px rgba(59, 130, 246, 0.4);
}
.status-pulse {
animation: pulse 2s infinite;
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.5; }
}
.lang-btn.active {
color: #60a5fa;
}
</style>
</head>
<body class="min-h-screen font-sans text-gray-100 flex flex-col">
<!-- Language Switcher -->
<nav class="w-full py-4 px-6">
<div class="max-w-4xl mx-auto flex justify-end gap-4 text-sm">
<a href="#" class="lang-btn text-gray-400 hover:text-blue-300 transition" data-lang="en" onclick="setLang('en'); return false;">English</a>
<a href="#" class="lang-btn text-gray-400 hover:text-blue-300 transition" data-lang="zh" onclick="setLang('zh'); return false;">中文</a>
<a href="#" class="lang-btn text-gray-400 hover:text-blue-300 transition" data-lang="es" onclick="setLang('es'); return false;">Español</a>
</div>
</nav>
<!-- Main Content -->
<main class="flex-1 flex items-center justify-center px-4 py-8">
<div class="w-full max-w-lg">
<!-- Header -->
<div class="text-center mb-8">
<h1 class="text-4xl font-bold mb-2 bg-gradient-to-r from-blue-400 to-cyan-400 bg-clip-text text-transparent">
OpenNHP Javascript SDK
</h1>
<p class="text-gray-400 text-sm font-mono" data-i18n="subtitle">Network Hiding Protocol</p>
</div>
<!-- Protected Server Info -->
<div class="glass-card rounded-xl p-6 mb-6">
<div class="flex items-center justify-between mb-4">
<span class="text-gray-300 text-sm" data-i18n="protectedServer">The Protected Server is</span>
<a href="https://acdemo.opennhp.org" target="_blank"
class="text-blue-400 hover:text-blue-300 font-mono text-sm transition">
https://acdemo.opennhp.org
</a>
</div>
<button onclick="scanPorts()"
class="px-4 py-2 text-sm font-medium text-cyan-400 bg-cyan-500/10 border border-cyan-500/30 rounded-lg hover:bg-cyan-500/20 hover:border-cyan-400/50 hover:text-cyan-300 transition-all duration-300 flex items-center gap-2 mb-6">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"/>
</svg>
<span data-i18n="scanPorts">Scan Its Ports >></span>
</button>
<!-- Status Indicators -->
<div class="space-y-3">
<div class="flex items-center gap-3 p-3 rounded-lg bg-black/30">
<div class="w-2 h-2 rounded-full bg-red-500 status-pulse"></div>
<span class="text-sm text-gray-300" data-i18n="beforeLogin">Before Login:</span>
<span class="text-sm text-red-400 font-medium" data-i18n="timeoutStatus">Connection should be TIMEOUT ❌</span>
</div>
<div class="flex items-center gap-3 p-3 rounded-lg bg-black/30">
<div class="w-2 h-2 rounded-full bg-emerald-500 status-pulse"></div>
<span class="text-sm text-gray-300" data-i18n="afterLogin">After Login:</span>
<span class="text-sm text-emerald-400 font-medium" data-i18n="successStatus">Connection should be SUCCESSFUL ✅</span>
</div>
</div>
</div>
<!-- Login Form -->
<div class="glass-card rounded-xl p-6 mb-6">
<form id="loginForm" onsubmit="handleLogin(event)">
<div class="mb-4">
<label class="block text-sm text-gray-400 mb-2" data-i18n="username">Username</label>
<input type="text" id="username"
class="input-field w-full px-4 py-3 rounded-lg text-white placeholder-gray-500 outline-none"
data-i18n-placeholder="enterUsername">
</div>
<div class="mb-6">
<label class="block text-sm text-gray-400 mb-2" data-i18n="password">Password</label>
<input type="password" id="password"
class="input-field w-full px-4 py-3 rounded-lg text-white placeholder-gray-500 outline-none"
data-i18n-placeholder="enterPassword">
</div>
<button type="submit"
class="btn-primary w-full py-3 rounded-lg text-white font-semibold" data-i18n="loginBtn">
Login
</button>
<div id="agentPublicKey" class="mt-2 text-xs text-gray-500 text-center font-mono"></div>
<div id="knockStatus" class="mt-2 text-xs text-gray-400 text-center"></div>
</form>
<!-- Divider -->
<div class="flex items-center my-6">
<div class="flex-1 border-t border-gray-700"></div>
<span class="px-4 text-gray-500 text-sm" data-i18n="or">or</span>
<div class="flex-1 border-t border-gray-700"></div>
</div>
<!-- Okta Login -->
<button onclick="oktaLogin()"
class="w-full py-3 rounded-lg bg-white/5 border border-white/10 text-white font-medium hover:bg-white/10 transition flex items-center justify-center gap-3">
<svg class="w-5 h-5" viewBox="0 0 24 24" fill="currentColor">
<path d="M12 0C5.389 0 0 5.389 0 12s5.389 12 12 12 12-5.389 12-12S18.611 0 12 0zm0 18c-3.314 0-6-2.686-6-6s2.686-6 6-6 6 2.686 6 6-2.686 6-6 6z"/>
</svg>
<span data-i18n="oktaLogin">Okta Login</span>
</button>
<!-- Login/Logout Status -->
<div class="mt-4 text-center">
<span id="authStatus" class="text-sm text-gray-500">
<a href="#" onclick="oktaLogin(); return false;" class="text-blue-400 hover:text-blue-300" data-i18n="login">Login</a>
<span class="mx-2">|</span>
<a href="#" onclick="handleLogout(); return false;" class="text-gray-400 hover:text-gray-300" data-i18n="logout">Logout</a>
</span>
</div>
</div>
<!-- IP Info -->
<div class="glass-card rounded-xl p-4 flex items-center justify-between">
<div class="flex items-center gap-3">
<div class="w-10 h-10 rounded-lg bg-blue-500/20 flex items-center justify-center">
<span class="text-xl"><></span>
</div>
<div>
<div class="text-xs text-gray-500" data-i18n="yourIP">Your IP Address</div>
<div id="userIP" class="font-mono text-sm text-gray-300" data-i18n="fetchingIP">Fetching IP...</div>
</div>
</div>
<div class="flex items-center gap-2 text-gray-500">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 12h.01M12 12h.01M19 12h.01M6 12a1 1 0 11-2 0 1 1 0 012 0zm7 0a1 1 0 11-2 0 1 1 0 012 0zm7 0a1 1 0 11-2 0 1 1 0 012 0z"/>
</svg>
<span class="font-mono text-lg">5</span>
</div>
</div>
</div>
</main>
<!-- Footer -->
<footer class="py-4 text-center text-gray-600 text-sm">
<p><span data-i18n="poweredBy">Powered by</span> <a href="https://github.com/OpenNHP/opennhp" target="_blank" class="text-blue-400 hover:text-blue-300">OpenNHP</a></p>
</footer>
<script>
// i18n translations
const translations = {
en: {
subtitle: "Network-infrastructure Hiding Protocol (NHP)",
protectedServer: "The Protected Server is",
scanPorts: "Scan Its Ports >>",
beforeLogin: "Before Login:",
afterLogin: "After Login:",
timeoutStatus: "Connection should be TIMEOUT ❌",
successStatus: "Connection should be SUCCESSFUL ✅",
username: "Username",
password: "Password",
enterUsername: "Enter username",
enterPassword: "Enter password",
loginBtn: "Login",
or: "or",
oktaLogin: "Okta Login",
login: "Login",
logout: "Logout",
yourIP: "Your IP Address",
fetchingIP: "Fetching IP...",
unableToFetch: "Unable to fetch IP",
poweredBy: "Powered by",
loginAttempt: "Login attempt with username:",
pleaseEnter: "Please enter username and password",
logoutClicked: "Logout clicked",
redirectOkta: "Redirecting to Okta login...",
scanningPorts: "Scanning ports on acdemo.opennhp.org..."
},
zh: {
subtitle: "零信任网络隐身协议(NHP)",
protectedServer: "受保护的服务器是",
scanPorts: "扫描端口 >>",
beforeLogin: "登录前:",
afterLogin: "登录后:",
timeoutStatus: "连接应该超时 ❌",
successStatus: "连接应该成功 ✅",
username: "用户名",
password: "密码",
enterUsername: "请输入用户名",
enterPassword: "请输入密码",
loginBtn: "登录",
or: "或",
oktaLogin: "Okta 登录",
login: "登录",
logout: "登出",
yourIP: "您的 IP 地址",
fetchingIP: "正在获取 IP...",
unableToFetch: "无法获取 IP",
poweredBy: "技术支持",
loginAttempt: "登录尝试,用户名:",
pleaseEnter: "请输入用户名和密码",
logoutClicked: "已点击登出",
redirectOkta: "正在跳转到 Okta 登录...",
scanningPorts: "正在扫描 acdemo.opennhp.org 的端口..."
},
es: {
subtitle: "Protocolo de Ocultación de Red",
protectedServer: "El servidor protegido es",
scanPorts: "Escanear puertos >>",
beforeLogin: "Antes de iniciar sesión:",
afterLogin: "Después de iniciar sesión:",
timeoutStatus: "La conexión debería ser TIMEOUT ❌",
successStatus: "La conexión debería ser EXITOSA ✅",
username: "Usuario",
password: "Contraseña",
enterUsername: "Ingrese usuario",
enterPassword: "Ingrese contraseña",
loginBtn: "Iniciar sesión",
or: "o",
oktaLogin: "Iniciar con Okta",
login: "Entrar",
logout: "Salir",
yourIP: "Tu dirección IP",
fetchingIP: "Obteniendo IP...",
unableToFetch: "No se pudo obtener IP",
poweredBy: "Desarrollado por",
loginAttempt: "Intento de inicio de sesión con usuario:",
pleaseEnter: "Por favor ingrese usuario y contraseña",
logoutClicked: "Cierre de sesión clickeado",
redirectOkta: "Redirigiendo a inicio de sesión de Okta...",
scanningPorts: "Escaneando puertos en acdemo.opennhp.org..."
}
};
let currentLang = localStorage.getItem('lang') || 'en';
// Set language
function setLang(lang) {
currentLang = lang;
localStorage.setItem('lang', lang);
// Update all elements with data-i18n attribute
document.querySelectorAll('[data-i18n]').forEach(el => {
const key = el.getAttribute('data-i18n');
if (translations[lang][key]) {
el.textContent = translations[lang][key];
}
});
// Update placeholders
document.querySelectorAll('[data-i18n-placeholder]').forEach(el => {
const key = el.getAttribute('data-i18n-placeholder');
if (translations[lang][key]) {
el.placeholder = translations[lang][key];
}
});
// Update language button styles
document.querySelectorAll('.lang-btn').forEach(btn => {
btn.classList.remove('active');
if (btn.getAttribute('data-lang') === lang) {
btn.classList.add('active');
}
});
// Update HTML lang attribute
document.documentElement.lang = lang;
}
// Fetch user IP
async function fetchIP() {
try {
const response = await fetch('https://api.ipify.org?format=json');
const data = await response.json();
document.getElementById('userIP').textContent = data.ip;
document.getElementById('userIP').removeAttribute('data-i18n');
} catch (error) {
document.getElementById('userIP').textContent = translations[currentLang].unableToFetch;
}
}
// Handle login
function handleLogin(event) {
event.preventDefault();
const useWebRTC = true;
if (useWebRTC) {
performKnock();
} else {
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
if (username && password) {
alert(translations[currentLang].loginAttempt + ' ' + username);
} else {
alert(translations[currentLang].pleaseEnter);
}
}
}
// Handle logout
function handleLogout() {
window.location.href = 'https://nhp.opennhp.org/plugins/okta?resid=demo&action=logout';
}
// Okta login
function oktaLogin() {
window.location.href = 'https://nhp.opennhp.org/plugins/okta?resid=demo&action=oauth';
}
// Scan ports
function scanPorts() {
window.open('https://dnschecker.org/port-scanner.php?query=acdemo.opennhp.org&ptype=server', '_blank');
}
// Initialize
document.addEventListener('DOMContentLoaded', () => {
setLang(currentLang);
fetchIP();
});
</script>
<!-- NHP Agent Module -->
<script type="module">
import { NHPAgent } from './nhp-js/dist/index.js';
// Make agent available globally for the onclick handler
window.NHPAgent = NHPAgent;
window.performKnock = async function () {
// pre-defined values
const cipherScheme = 'curve25519'; // 'gmsm' for gmsm
const serverHost = 'nhp.opennhp.org';
//const serverHost = 'https://192.168.80.43';
//const serverPort = 443;
//const serverKey = 'E3o8gUUxI5dUAUiEOi6SvgV9bWKmjpWWQaOO6GChO2A=';
const serverKey = 'T29VClxfuJa7AKA2D+4gBvGXnyGZA35AdqRkdjk49Vs=';
const userId = 'demo browser agent';
const resourceId = 'demo';
const serviceId = 'example';
const serviceIdOkta = 'okta';
// use demo keys
const agentPrivateKey = "QL2U9Ag18Fqdc1Bpw4wx/sNJbFqq36rfhtkPm2WId1c=";
const agentPublicKey = "Z0QA6bPlRpq8xWsVFe8NGR43bjGHjK0mX7CT1daudAA=";
try {
// Create and initialize agent
const agent = new NHPAgent({
privateKey: agentPrivateKey,
cipherScheme: cipherScheme,
transport: 'webrtc',
logLevel: 'debug'
});
await agent.init();
const publicKeyElement = document.getElementById('agentPublicKey');
if (publicKeyElement) {
publicKeyElement.textContent = `Public Key: ${agent.getPublicKey()}`;
}
const knockStatusElement = document.getElementById('knockStatus');
if (knockStatusElement) {
knockStatusElement.textContent = 'Agent initialized...';
}
// Set identity
agent.setIdentity({
userId,
deviceId: 'browser-' + Date.now(),
organizationId: 'demo'
});
// Add server
agent.addServer({
publicKey: serverKey,
host: serverHost,
port: serverPort
});
if (knockStatusElement) {
knockStatusElement.textContent = 'Sending knock request...';
}
// Knock on resource
const result = await agent.knockResource({
resourceId,
serviceId,
serverHost,
serverPort
});
if (result.success) {
if (knockStatusElement) {
knockStatusElement.textContent = 'Access Granted!';
knockStatusElement.className = 'mt-2 text-xs text-green-400 text-center';
}
status.className = 'success';
status.innerHTML = `
<strong>Access Granted!</strong><br>
Expires: ${new Date(result.expiresAt).toLocaleString()}<br>
<pre>${JSON.stringify(result, null, 2)}</pre>
`;
} else {
if (knockStatusElement) {
knockStatusElement.textContent = `Access Denied: ${result.error}`;
knockStatusElement.className = 'mt-2 text-xs text-red-400 text-center';
}
}
await agent.close();
} catch (error) {
// 更新状态
if (knockStatusElement) {
knockStatusElement.textContent = `Error: ${error.message}`;
knockStatusElement.className = 'mt-2 text-xs text-red-400 text-center';
}
console.error(error);
} finally {
}
};
</script>
</body>
</html>