Spaces:
Running
Running
Restore address check, port 443 guide and local checker; checker prints the verdict
Browse files- README.md +4 -1
- del_openfree.py +0 -13
- index.html +129 -37
- local/keyguard-local.ps1 +103 -12
- local/keyguard-local.py +148 -15
README.md
CHANGED
|
@@ -27,7 +27,10 @@ Auto-detects browser language and offers **Korean / English / Chinese** buttons.
|
|
| 27 |
| 📏 **Short / weak keys** | ≤768-bit factorable, <2048 replace, bad exponent |
|
| 28 |
|
| 29 |
## Privacy / 개인정보
|
| 30 |
-
- 100% client-side. No key is stored or sent to any server.
|
|
|
|
|
|
|
|
|
|
| 31 |
- Use only on devices you own or are authorized to test. Follows Responsible Disclosure.
|
| 32 |
|
| 33 |
## Verified / 검증
|
|
|
|
| 27 |
| 📏 **Short / weak keys** | ≤768-bit factorable, <2048 replace, bad exponent |
|
| 28 |
|
| 29 |
## Privacy / 개인정보
|
| 30 |
+
- **Self-check (paste or open a file):** 100% client-side. No key is stored or sent to any server.
|
| 31 |
+
- **Address check:** [KeyGuard API](https://huggingface.co/spaces/FINAL-Bench/KeyGuard-API) connects to port 443 of the address you enter and returns its public certificate. The verdict is computed in your browser. Addresses and results are not stored.
|
| 32 |
+
- **Local collector:** `local/keyguard-local.ps1` (Windows) and `local/keyguard-local.py` (macOS, Linux) collect public keys inside your own private network into one file. No login attempts, no upload.
|
| 33 |
+
- Recovered private keys are never shown. Only the fact that a key is recoverable is shown.
|
| 34 |
- Use only on devices you own or are authorized to test. Follows Responsible Disclosure.
|
| 35 |
|
| 36 |
## Verified / 검증
|
del_openfree.py
DELETED
|
@@ -1,13 +0,0 @@
|
|
| 1 |
-
import os, re
|
| 2 |
-
from huggingface_hub import HfApi
|
| 3 |
-
tok=None
|
| 4 |
-
for line in open(os.path.expanduser("~/.config/spark-secrets/tokens.env")):
|
| 5 |
-
m=re.match(r'\s*VIDRAFT_HF_TOKEN\s*=\s*(.+?)\s*$', line)
|
| 6 |
-
if m: tok=m.group(1).strip().strip('"').strip("'"); break
|
| 7 |
-
assert tok
|
| 8 |
-
api=HfApi(token=tok)
|
| 9 |
-
try:
|
| 10 |
-
api.delete_repo(repo_id="openfree/KeyGuard", repo_type="space", token=tok)
|
| 11 |
-
print("DELETED openfree/KeyGuard")
|
| 12 |
-
except Exception as e:
|
| 13 |
-
print("delete err:", str(e)[:120])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
index.html
CHANGED
|
@@ -138,7 +138,23 @@
|
|
| 138 |
.warnbox{padding:16px 18px;border-radius:14px;border:1px solid var(--warn);background:rgba(251,191,36,.06);font-size:13px;color:var(--muted);margin-top:16px}
|
| 139 |
footer{margin:56px 0 40px;padding-top:26px;border-top:1px solid var(--panel-br);font-size:12.5px;color:var(--faint);text-align:center}
|
| 140 |
/* tabs */
|
| 141 |
-
.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
.tabs button{border:1px solid var(--panel-br);background:var(--panel);color:var(--muted);font-family:inherit;font-size:14px;font-weight:600;padding:11px 20px;border-radius:12px;cursor:pointer;transition:.18s}
|
| 143 |
.tabs button.on{background:var(--grad);color:#0a0b14;border-color:transparent;box-shadow:0 8px 22px rgba(124,108,255,.3)}
|
| 144 |
/* leaderboard */
|
|
@@ -185,7 +201,7 @@
|
|
| 185 |
<p class="sub" data-i18n="sub"></p>
|
| 186 |
</header>
|
| 187 |
|
| 188 |
-
<div class="tabs"><button id="tabCheck" class="on" data-i18n="tab_check"></button><button id="tabBench" data-i18n="tab_bench"></button></div>
|
| 189 |
|
| 190 |
<div id="tab-check">
|
| 191 |
<!-- ABOUT / 설명 -->
|
|
@@ -213,7 +229,7 @@
|
|
| 213 |
<label class="ck"><input type="checkbox" id="consent"><span data-i18n="chk_consent"></span></label>
|
| 214 |
<div class="row">
|
| 215 |
<button class="run" id="runbtn" data-i18n="chk_run"></button>
|
| 216 |
-
<button class="secbtn" id="clearbtn" data-i18n="chk_clear"></button>
|
| 217 |
</div>
|
| 218 |
<div id="results"><div id="verdict"></div><div class="summary" id="summary"></div><div id="reslist"></div><div id="sharedbox"></div></div>
|
| 219 |
</div>
|
|
@@ -263,6 +279,39 @@
|
|
| 263 |
</section>
|
| 264 |
</div><!-- /tab-check -->
|
| 265 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 266 |
<div id="tab-bench" style="display:none">
|
| 267 |
<section class="block" style="margin-top:26px">
|
| 268 |
<div class="eyebrow" data-i18n="lb_eye"></div>
|
|
@@ -290,7 +339,7 @@
|
|
| 290 |
/* ================= i18n ================= */
|
| 291 |
const I18N={
|
| 292 |
ko:{
|
| 293 |
-
tag:"100% 브라우저 안에서 검사 ·
|
| 294 |
h1a:"내 장비 암호키,", h1b:"혹시 불량품 아닐까?",
|
| 295 |
lead:"공장에서 실수로 여러 장비에 똑같은 비밀 소수를 넣어 출고하면, 누군가 그걸 찾는 순간 그 장비들은 전부 열립니다. KeyGuard는 당신의 공개키가 그런 불량 키인지 수학으로 30초 만에 검사합니다.",
|
| 296 |
sub:"개인키 말고 공개키만 넣으세요. 공개키는 원래 공개되는 정보라 안전합니다.",
|
|
@@ -319,7 +368,7 @@ const I18N={
|
|
| 319 |
w4h:"ROCA 결함칩", w4d:"특정 칩(CVE-2017-15361)이 만든 취약 패턴 키를 의심 탐지합니다.",
|
| 320 |
proof_eye:"검증됨", proof_h:"실제 대규모 공개키로 검증 완료",
|
| 321 |
proof_lead:"합성 취약 키를 정확히 탐지하고, 실제 인증서 투명성(CT) 로그의 공개키 100만 개를 12분에 처리해 대규모 동작을 확인했습니다.",
|
| 322 |
-
proof_s1:"심은 취약 키 탐지 정확도 (오탐 0)", proof_s2:"실제 CT 공개키 분석 (스파크)", proof_s3:"서버
|
| 323 |
proof_note:"참고: 공개 CT 로그의 웹 인증서는 대체로 잘 생성되어 취약 키가 드뭅니다. 취약 키는 주로 임베디드·IoT의 자가서명 인증서에 분포 — 그래서 '내 장비를 직접 검사'하는 이 도구가 의미가 있습니다.",
|
| 324 |
faq_eye:"자주 묻는 질문", faq_h:"궁금한 것들",
|
| 325 |
faq1q:"제 개인키가 유출되나요?", faq1a:"아니요. 공개키만 넣고, 그마저도 브라우저 밖으로 나가지 않습니다.",
|
|
@@ -327,7 +376,7 @@ const I18N={
|
|
| 327 |
faq3q:"여러 장비를 한꺼번에 넣어도 되나요?", faq3a:"네, 권장합니다. 장비들끼리 소수를 공유하는지는 여러 키를 함께 넣어야 검사됩니다.",
|
| 328 |
faq4q:"안전으로 나오면 100% 안심인가요?", faq4a:"이 도구가 검사하는 4가지 결함이 없다는 뜻입니다. 암호의 다른 측면은 별도 점검이 필요합니다.",
|
| 329 |
faq_warn:"⚠️ 이 도구는 본인 소유 또는 점검 위임을 받은 장비의 공개키에만 사용하세요. 타인의 장비·시스템을 무단으로 검사·침투하는 것은 법으로 금지되어 있습니다.",
|
| 330 |
-
foot1:"KeyGuard · 공개키 자가진단 ·
|
| 331 |
foot2:"교육 및 본인 자산 점검용 · 책임 있는 보안 점검(Responsible Disclosure) 원칙 준수",
|
| 332 |
b_safe:"안전", b_weak:"주의", b_bad:"위험",
|
| 333 |
s_tot:"검사한 키", s_safe:"안전", s_warn:"주의", s_bad:"위험",
|
|
@@ -347,10 +396,10 @@ const I18N={
|
|
| 347 |
al_consent:"본인 소유/위임 장비 확인에 체크해 주세요.", al_nokey:"유효한 RSA 공개키를 찾지 못했습니다. 형식을 확인해 주세요.",
|
| 348 |
busy:"검사 중…",
|
| 349 |
cr_label:"���원된 소인수 (이 키는 이미 깨진 키)", cr_time:"복원 시간", cr_iter:"Fermat 반복", cr_via:"복원 경로", cr_note:"공개 모듈러스만으로 누구나 복원 가능 → 즉시 폐기 필요",
|
| 350 |
-
vd_cracked:(n)=>`${n}개 키 뚫림 — CRACKED`, vd_cracked_sub:"개인키가 복원됐습니다. 해당 키는 즉시 폐기·교체하세요.",
|
| 351 |
vd_weak:(n)=>`${n}개 키 주의 필요`, vd_weak_sub:"지금 당장 뚫리진 않지만 교체를 권장합니다.",
|
| 352 |
vd_safe:"모두 안전", vd_safe_sub:"이 도구가 검사하는 4대 결함이 없습니다.",
|
| 353 |
-
tab_check:"🔎 자가진단", tab_bench:"🏆 벤치마크",
|
| 354 |
lb_eye:"스파크 실측 · 조�� 없음", lb_h:"취약키 탐지 벤치마크",
|
| 355 |
lb_lead:"표준 취약키 테스트셋에서 탐지 방법들의 재현율·오탐률·속도를 실측해 순위. 단일 방법은 일부만, 결합한 KeyGuard는 전 유형을 잡습니다.",
|
| 356 |
th_det:"탐지기", th_recall:"재현율", th_fpr:"오탐", th_time:"시간", th_cat:"유형별",
|
|
@@ -361,10 +410,10 @@ const I18N={
|
|
| 361 |
lb_m3h:"재현 가능", lb_m3d:"고정 시드(20262025) — 언제든 동일 재현, 조작 불가",
|
| 362 |
lb_notes:["ROCA는 본 셋에 합성 양성이 없어 0%(완전성 위해 포함).","고전 분해는 2048비트 불가로 0%(반복 상한 내 측정).","소규모 자체셋 — 숫자는 측정값만, 과장 없음."],
|
| 363 |
catlabel:{close:"가까운소수",shared:"소수공유",short:"짧은키",bade:"지수"}, me_tag:"우리",
|
| 364 |
-
sample:{fermat:["🤏 가까운 소수","두 소수가 너무 가까운
|
| 365 |
},
|
| 366 |
en:{
|
| 367 |
-
tag:"100% in
|
| 368 |
h1a:"Your device's crypto key —", h1b:"is it a factory defect?",
|
| 369 |
lead:"If a factory mistakenly ships many devices with the same secret prime, anyone who finds it can open them all. KeyGuard checks, with math in 30 seconds, whether your public key is one of those defective keys.",
|
| 370 |
sub:"Paste the PUBLIC key only, never the private key. Public keys are meant to be public, so this is safe.",
|
|
@@ -393,7 +442,7 @@ const I18N={
|
|
| 393 |
w4h:"ROCA faulty chips", w4d:"Detects vulnerable keys from certain chips (CVE-2017-15361).",
|
| 394 |
proof_eye:"Verified", proof_h:"Validated on real large-scale public keys",
|
| 395 |
proof_lead:"Detects planted weak keys exactly, and verified at scale on 1,000,000+ real public keys from Certificate Transparency (CT) logs in 12 minutes.",
|
| 396 |
-
proof_s1:"Detection accuracy on planted weak keys (0 false positives)", proof_s2:"Real CT public keys analyzed (on Spark)", proof_s3:"
|
| 397 |
proof_note:"Note: Web certificates in public CT logs are usually well-generated, so weak keys are rare there. Weak keys mostly live in self-signed certs of embedded/IoT devices — which is why checking YOUR OWN devices with this tool matters.",
|
| 398 |
faq_eye:"FAQ", faq_h:"Common questions",
|
| 399 |
faq1q:"Will my private key leak?", faq1a:"No. You paste only the public key, and even that never leaves your browser.",
|
|
@@ -401,7 +450,7 @@ const I18N={
|
|
| 401 |
faq3q:"Can I paste many devices at once?", faq3a:"Yes, recommended. Shared-prime checks require several keys pasted together.",
|
| 402 |
faq4q:"If it says Safe, am I 100% safe?", faq4a:"It means the four defects this tool checks are absent. Other aspects of your crypto need separate review.",
|
| 403 |
faq_warn:"⚠️ Use this tool only on public keys of devices you own or are authorized to test. Testing or intruding on others' systems without permission is illegal.",
|
| 404 |
-
foot1:"KeyGuard · public-key self-check ·
|
| 405 |
foot2:"For education and checking your own assets · follows Responsible Disclosure",
|
| 406 |
b_safe:"Safe", b_weak:"Caution", b_bad:"Danger",
|
| 407 |
s_tot:"Keys checked", s_safe:"Safe", s_warn:"Caution", s_bad:"Danger",
|
|
@@ -421,10 +470,10 @@ const I18N={
|
|
| 421 |
al_consent:"Please check the ownership/authorization box.", al_nokey:"No valid RSA public key found. Please check the format.",
|
| 422 |
busy:"Checking…",
|
| 423 |
cr_label:"Recovered primes (this key is already broken)", cr_time:"Recovered in", cr_iter:"Fermat iters", cr_via:"Recovered via", cr_note:"anyone can recover these from the public modulus → retire this key now",
|
| 424 |
-
vd_cracked:(n)=>`${n} KEY${n>1?'S':''} CRACKED`, vd_cracked_sub:"The private key was recovered. Retire and replace these keys immediately.",
|
| 425 |
vd_weak:(n)=>`${n} key(s) need attention`, vd_weak_sub:"Not breakable right now, but replacement is recommended.",
|
| 426 |
vd_safe:"All safe", vd_safe_sub:"None of the four defects this tool checks were found.",
|
| 427 |
-
tab_check:"🔎 Self-check", tab_bench:"🏆 Benchmark",
|
| 428 |
lb_eye:"Measured on Spark · no cherry-picking", lb_h:"Weak-Key Detection Benchmark",
|
| 429 |
lb_lead:"Recall, false-positive rate and speed of detection methods on a standard weak-key set, ranked. Single methods catch only part; combined KeyGuard catches every type.",
|
| 430 |
th_det:"Detector", th_recall:"Recall", th_fpr:"False-pos", th_time:"Time", th_cat:"Per-category",
|
|
@@ -435,10 +484,10 @@ const I18N={
|
|
| 435 |
lb_m3h:"Reproducible", lb_m3d:"Fixed seed (20262025) — reproduces the set anytime, no tampering",
|
| 436 |
lb_notes:["ROCA shows 0% (no synthetic ROCA positives in this set; included for completeness).","Classical factoring is 0% (2048-bit infeasible; measured within an iteration cap).","Small self-generated set — numbers are measured values only, no exaggeration."],
|
| 437 |
catlabel:{close:"Close",shared:"Shared",short:"Short",bade:"Exp"}, me_tag:"OURS",
|
| 438 |
-
sample:{fermat:["🤏 Close primes","
|
| 439 |
},
|
| 440 |
zh:{
|
| 441 |
-
tag:"100% 在浏览器内检测 ·
|
| 442 |
h1a:"你设备的加密密钥,", h1b:"会不会是次品?",
|
| 443 |
lead:"如果工厂错误地给多台设备出厂了相同的秘密素数,任何人只要找到它就能打开所有这些设备。KeyGuard 用数学在 30 秒内检测你的公钥是否就是这种次品密钥。",
|
| 444 |
sub:"只粘贴公钥,不要粘贴私钥。公钥本来就是公开的,所以这是安全的。",
|
|
@@ -467,7 +516,7 @@ const I18N={
|
|
| 467 |
w4h:"ROCA 缺陷芯片", w4d:"检测某些芯片(CVE-2017-15361)生成的易受攻击密钥。",
|
| 468 |
proof_eye:"已验证", proof_h:"已在真实大规模公钥上完成验证",
|
| 469 |
proof_lead:"精确检出植入的弱密钥,并在证书透明度(CT)日志的 100 万+ 真实公钥上以 12 分钟完成了大规模验证。",
|
| 470 |
-
proof_s1:"对植入弱密钥的检出准确率(0 误报)", proof_s2:"分析的真实 CT 公钥(在 Spark 上)", proof_s3:"发送到服务器
|
| 471 |
proof_note:"注:公共 CT 日志中的网站证书通常生成良好,弱密钥很少见。弱密钥主要存在于嵌入式/IoT 设备的自签名证书中——这正是用本工具检测'你自己的设备'的意义所在。",
|
| 472 |
faq_eye:"常见问题", faq_h:"你可能想问",
|
| 473 |
faq1q:"我的私钥会泄露吗?", faq1a:"不会。你只粘贴公钥,而且它也不会离开你的浏览器。",
|
|
@@ -475,7 +524,7 @@ const I18N={
|
|
| 475 |
faq3q:"可以一次粘贴多台设备吗?", faq3a:"可以,建议如此。素数共享检测需要同时粘贴多个密钥。",
|
| 476 |
faq4q:"显示安全就 100% 放心吗?", faq4a:"意味着本工具检测的四种缺陷不存在。加密的其他方面需要单独审查。",
|
| 477 |
faq_warn:"⚠️ 本工具仅可用于你拥有或已获授权检测的设备公钥。未经许可检测或入侵他人系统是违法的。",
|
| 478 |
-
foot1:"KeyGuard · 公钥自检 ·
|
| 479 |
foot2:"用于教育及自有资产检测 · 遵循负责任披露(Responsible Disclosure)原则",
|
| 480 |
b_safe:"安全", b_weak:"注意", b_bad:"危险",
|
| 481 |
s_tot:"已检测密钥", s_safe:"安全", s_warn:"注意", s_bad:"危险",
|
|
@@ -495,10 +544,10 @@ const I18N={
|
|
| 495 |
al_consent:"请勾选所有权/授权确认项。", al_nokey:"未找到有效的 RSA 公钥,请检查格式。",
|
| 496 |
busy:"检测中…",
|
| 497 |
cr_label:"已还原的素因子(此密钥已被攻破)", cr_time:"还原耗时", cr_iter:"Fermat 迭代", cr_via:"还原途径", cr_note:"仅凭公开模数任何人都能还原 → 请立即废弃此密钥",
|
| 498 |
-
vd_cracked:(n)=>`${n} 个密钥被攻破 — CRACKED`, vd_cracked_sub:"私钥已被还原。请立即废弃并更换这些密钥。",
|
| 499 |
vd_weak:(n)=>`${n} 个密钥需注意`, vd_weak_sub:"目前不会被破解,但建议更换。",
|
| 500 |
vd_safe:"全部安全", vd_safe_sub:"未发现本工具检测的四种缺陷。",
|
| 501 |
-
tab_check:"🔎 自检", tab_bench:"🏆 基准",
|
| 502 |
lb_eye:"在 Spark 实测 · 无挑选", lb_h:"弱密钥检测基准",
|
| 503 |
lb_lead:"在标准弱密钥测试集上实测各检测方法的召回率、误报率与速度并排名。单一方法只能检出部分,组合的 KeyGuard 可检出所有类型。",
|
| 504 |
th_det:"检测器", th_recall:"召回率", th_fpr:"误报", th_time:"耗时", th_cat:"按类型",
|
|
@@ -509,7 +558,7 @@ const I18N={
|
|
| 509 |
lb_m3h:"可复现", lb_m3d:"固定种子(20262025) — 随时复现,不可篡改",
|
| 510 |
lb_notes:["ROCA 为 0%(本集无合成 ROCA 阳性,为完整性而列入)。","经典分解为 0%(2048 位不可行,在迭代上限内测量)。","小规模自建集 — 数字仅为实测值,无夸大。"],
|
| 511 |
catlabel:{close:"相近",shared:"共享",short:"过短",bade:"指数"}, me_tag:"我们",
|
| 512 |
-
sample:{fermat:["🤏 相近素数","两素数过近的
|
| 513 |
}
|
| 514 |
};
|
| 515 |
let LANG='ko';
|
|
@@ -520,6 +569,7 @@ function applyLang(){
|
|
| 520 |
document.querySelectorAll('[data-i18n-ph]').forEach(el=>{const v=t(el.getAttribute('data-i18n-ph'));if(typeof v==='string')el.setAttribute('placeholder',v);});
|
| 521 |
document.querySelectorAll('#langsw button').forEach(b=>b.classList.toggle('on',b.dataset.lang===LANG));
|
| 522 |
renderChips();renderBoard();
|
|
|
|
| 523 |
}
|
| 524 |
function detectLang(){
|
| 525 |
try{const s=localStorage.getItem('kg-lang');if(s&&I18N[s])return s;}catch(e){}
|
|
@@ -544,8 +594,15 @@ const ROCA_PRIMES=[3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,8
|
|
| 544 |
function rocaHeuristic(n){try{for(const p of ROCA_PRIMES){const P=bi(p);let res=new Set();let x=1n;for(let k=1;k<p;k++){x=(x*65537n)%P;res.add(x.toString());}const r=(n%P);if(r!==0n&&!res.has(r.toString()))return false;}return true;}catch(e){return false;}}
|
| 545 |
function b64ToBytes(b64){const bin=atob(b64.replace(/\s+/g,''));const a=new Uint8Array(bin.length);for(let i=0;i<bin.length;i++)a[i]=bin.charCodeAt(i);return a;}
|
| 546 |
function derIntegers(bytes){const out=[];let i=0;function len(){let l=bytes[i++];if(l&0x80){let k=l&0x7f;l=0;while(k--)l=(l<<8)|bytes[i++];}return l;}function walk(end){while(i<end){const tag=bytes[i++];const l=len();const s=i;if(tag===0x02){let hex='';for(let j=s;j<s+l;j++)hex+=bytes[j].toString(16).padStart(2,'0');if(hex)out.push(BigInt('0x'+hex));i=s+l;}else if(tag===0x30||tag===0x31||tag===0x03){walk(s+l);i=s+l;}else{i=s+l;}}}try{walk(bytes.length);}catch(e){}return out;}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 547 |
function parseNum(s){s=s.trim().replace(/\s/g,'');if(/^0x/i.test(s))return BigInt(s);if(/^[0-9]+$/.test(s))return BigInt(s);if(/^[0-9a-fA-F]+$/.test(s))return BigInt('0x'+s);throw 'bad';}
|
| 548 |
-
function parseKey(line){line=line.trim();if(!line)return null;if(line.
|
|
|
|
| 549 |
function assess(n,e){const bits=bitlen(n);const flags=[];let level='safe';const rec={};
|
| 550 |
if(bits<=768){level='critical';flags.push(t('f_size_c')(bits));}else if(bits<2048){level='weak';flags.push(t('f_size_w')(bits));}
|
| 551 |
if(e<3n||e%2n===0n){level='critical';flags.push(t('f_exp')(e));}
|
|
@@ -573,23 +630,24 @@ async function runCheck(){
|
|
| 573 |
if(BUSY)return;
|
| 574 |
if(!$('consent').checked){alert(t('al_consent'));return;}
|
| 575 |
BUSY=true;const btn=$('runbtn');const prev=btn.textContent;btn.textContent=t('busy');btn.style.opacity='.7';
|
| 576 |
-
await sleep(30);try{await doCheck();}finally{btn.textContent=prev;btn.style.opacity='1';BUSY=false;}
|
| 577 |
}
|
| 578 |
-
async function doCheck(){
|
| 579 |
-
const lines=$('keyin').value.split('\n');const blocks=[];let buf='';
|
| 580 |
-
for(const ln of lines){if(ln.includes('BEGIN'))buf=ln+'\n';else if(buf){buf+=ln+'\n';if(ln.includes('END')){
|
| 581 |
-
const parsed=[];blocks.forEach((b,i)=>{const k=parseKey(b);if(k&&k.n>1n)parsed.push({idx:i+1,...k});});
|
| 582 |
if(!parsed.length){$('results').style.display='none';alert(t('al_nokey'));return;}
|
| 583 |
const shared=[];const sharedMap={};const sharedG={};
|
| 584 |
for(let a=0;a<parsed.length;a++)for(let b=a+1;b<parsed.length;b++){const g=bgcd(parsed[a].n,parsed[b].n);if(g!==1n&&g!==parsed[a].n&&g!==parsed[b].n){const bits=bitlen(g);shared.push([parsed[a].idx,parsed[b].idx,bits]);(sharedMap[parsed[a].idx]=sharedMap[parsed[a].idx]||[]).push(parsed[b].idx);(sharedMap[parsed[b].idx]=sharedMap[parsed[b].idx]||[]).push(parsed[a].idx);sharedG[parsed[a].idx]=g;sharedG[parsed[b].idx]=g;}}
|
| 585 |
-
let nSafe=0,nWeak=0,nBad=0;const rows=[];
|
| 586 |
for(const k of parsed){await sleep(0);const r=assess(k.n,k.e);
|
| 587 |
if(sharedMap[k.idx]){r.level='critical';r.flags.unshift(t('f_shared')(sharedMap[k.idx].map(x=>'#'+x).join(', ')));if(!r.rec.p){const g=sharedG[k.idx];r.rec={p:g,q:k.n/g,method:'shared'};}}
|
| 588 |
-
if(r.level==='safe')nSafe++;else if(r.level==='weak')nWeak++;else nBad++;
|
| 589 |
const emoji=r.level==='safe'?'✓':r.level==='weak'?'!':'✕';const badge=r.level==='safe'?t('b_safe'):r.level==='weak'?t('b_weak'):t('b_bad');
|
| 590 |
-
rows.push(`<div class="res ${r.level}"><div class="ic">${emoji}</div><div class="body"><div class="tt">${esc(t('key_n')(k.idx,r.bits))}</div><div class="ds">${r.flags.length?esc(r.flags.join(' / ')):esc(t('f_nodefect'))}</div>${crackHTML(r.rec,r.bits)}</div><span class="badge">${badge}</span></div>`);}
|
| 591 |
// 극적 판정 배너
|
| 592 |
-
if(nBad>0){$('verdict').innerHTML=`<div class="verdict bad"><div class="
|
|
|
|
| 593 |
else if(nWeak>0){$('verdict').innerHTML=`<div class="verdict bad" style="border-color:var(--warn);background:radial-gradient(120% 140% at 50% 0,rgba(251,191,36,.18),transparent)"><div class="big" style="color:var(--warn)">${esc(t('vd_weak')(nWeak))}</div><div class="sub2">${esc(t('vd_weak_sub'))}</div></div>`;}
|
| 594 |
else{$('verdict').innerHTML=`<div class="verdict safe"><div class="big">🛡️ ${esc(t('vd_safe'))}</div><div class="sub2">${esc(t('vd_safe_sub'))}</div></div>`;}
|
| 595 |
$('summary').innerHTML=`<div class="card stat tot"><div class="n">${parsed.length}</div><div class="l">${esc(t('s_tot'))}</div></div><div class="card stat ok"><div class="n">${nSafe}</div><div class="l">${esc(t('s_safe'))}</div></div><div class="card stat warn"><div class="n">${nWeak}</div><div class="l">${esc(t('s_warn'))}</div></div><div class="card stat bad"><div class="n">${nBad}</div><div class="l">${esc(t('s_bad'))}</div></div>`;
|
|
@@ -604,6 +662,9 @@ function renderChips(){const box=$('schips');if(!box||typeof SAMPLES==='undefine
|
|
| 604 |
box.querySelectorAll('.schip').forEach(b=>b.onclick=()=>{const s=SAMPLES[b.dataset.k];$('keyin').value=s.keys.join('\n');$('consent').checked=true;runCheck();});}
|
| 605 |
$('clearbtn').onclick=()=>{$('keyin').value='';$('results').style.display='none';};
|
| 606 |
$('runbtn').onclick=runCheck;
|
|
|
|
|
|
|
|
|
|
| 607 |
document.querySelectorAll('#langsw button').forEach(b=>b.onclick=()=>{LANG=b.dataset.lang;try{localStorage.setItem('kg-lang',LANG);}catch(e){}applyLang();});
|
| 608 |
$('themeToggle').onclick=()=>{const r=document.documentElement;r.setAttribute('data-theme',r.getAttribute('data-theme')==='dark'?'light':'dark');try{localStorage.setItem('kg-theme',r.getAttribute('data-theme'));}catch(e){}};
|
| 609 |
try{const th=localStorage.getItem('kg-theme');if(th)document.documentElement.setAttribute('data-theme',th);}catch(e){}
|
|
@@ -624,18 +685,49 @@ function renderBoard(){
|
|
| 624 |
}).join('');
|
| 625 |
$('lbnotes').innerHTML=t('lb_notes').map(n=>`<li>${esc(n)}</li>`).join('');
|
| 626 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 627 |
/* ===== tabs ===== */
|
| 628 |
function showTab(which){
|
| 629 |
-
|
| 630 |
-
|
| 631 |
-
|
| 632 |
-
if(!chk)renderBoard();
|
| 633 |
try{localStorage.setItem('kg-tab',which);}catch(e){}
|
| 634 |
}
|
| 635 |
-
$('tabCheck').onclick=()=>showTab('check');$('tabBench').onclick=()=>showTab('bench');
|
| 636 |
|
|
|
|
| 637 |
LANG=detectLang();applyLang();
|
| 638 |
-
try{const tb=localStorage.getItem('kg-tab');if(tb==='bench')showTab(
|
| 639 |
</script>
|
| 640 |
</body>
|
| 641 |
</html>
|
|
|
|
| 138 |
.warnbox{padding:16px 18px;border-radius:14px;border:1px solid var(--warn);background:rgba(251,191,36,.06);font-size:13px;color:var(--muted);margin-top:16px}
|
| 139 |
footer{margin:56px 0 40px;padding-top:26px;border-top:1px solid var(--panel-br);font-size:12.5px;color:var(--faint);text-align:center}
|
| 140 |
/* tabs */
|
| 141 |
+
.p443{margin:8px 0 0;padding-left:20px;color:var(--muted);font-size:14px;line-height:1.7}
|
| 142 |
+
.p443 .w{color:var(--warn);font-weight:600}
|
| 143 |
+
a.secbtn{display:inline-block;text-decoration:none}
|
| 144 |
+
a.sl{font-size:13px;color:var(--accent2)}
|
| 145 |
+
.addrguide .hs{overflow-wrap:anywhere;font-family:var(--mono);font-size:11px}
|
| 146 |
+
.addrguide summary{cursor:pointer;font-size:13.5px;color:var(--muted)}
|
| 147 |
+
.addrguide p{font-size:13.5px;color:var(--muted);margin:10px 0}
|
| 148 |
+
.addrguide .gl{font-size:12px;color:var(--faint);margin:10px 0 4px}
|
| 149 |
+
textarea.cmd{min-height:0;font-size:12px;padding:10px 12px;word-break:break-all}
|
| 150 |
+
.addrguide .secbtn{padding:9px 14px;margin-top:6px}
|
| 151 |
+
#addrmsg{color:var(--ink);font-size:14px}
|
| 152 |
+
.addrin{flex:1;min-width:220px;background:rgba(0,0,0,.22);border:1px solid var(--panel-br);border-radius:14px;color:var(--ink);font-family:var(--mono);font-size:16px;padding:14px 15px;outline:none}
|
| 153 |
+
:root:not([data-theme="dark"]) .addrin{background:#fff}
|
| 154 |
+
.addrin:focus{border-color:var(--accent);box-shadow:0 0 0 4px rgba(124,108,255,.15)}
|
| 155 |
+
.addrrow{display:flex;gap:10px;flex-wrap:wrap;align-items:baseline;border-top:1px solid var(--panel-br);padding:10px 2px;font-size:13px;color:var(--muted);overflow-wrap:anywhere}
|
| 156 |
+
.addrrow b{color:var(--ink);font-family:var(--mono)}
|
| 157 |
+
.tabs{display:flex;flex-wrap:wrap;gap:8px;justify-content:center;margin:6px 0 2px}
|
| 158 |
.tabs button{border:1px solid var(--panel-br);background:var(--panel);color:var(--muted);font-family:inherit;font-size:14px;font-weight:600;padding:11px 20px;border-radius:12px;cursor:pointer;transition:.18s}
|
| 159 |
.tabs button.on{background:var(--grad);color:#0a0b14;border-color:transparent;box-shadow:0 8px 22px rgba(124,108,255,.3)}
|
| 160 |
/* leaderboard */
|
|
|
|
| 201 |
<p class="sub" data-i18n="sub"></p>
|
| 202 |
</header>
|
| 203 |
|
| 204 |
+
<div class="tabs"><button id="tabCheck" class="on" data-i18n="tab_check"></button><button id="tabAddr" data-i18n="tab_addr"></button><button id="tabBench" data-i18n="tab_bench"></button></div>
|
| 205 |
|
| 206 |
<div id="tab-check">
|
| 207 |
<!-- ABOUT / 설명 -->
|
|
|
|
| 229 |
<label class="ck"><input type="checkbox" id="consent"><span data-i18n="chk_consent"></span></label>
|
| 230 |
<div class="row">
|
| 231 |
<button class="run" id="runbtn" data-i18n="chk_run"></button>
|
| 232 |
+
<button class="secbtn" id="filebtn" data-i18n="lc_file"></button><input type="file" id="filein" accept=".txt,.pem,.crt,.cer,.pub,text/plain" multiple style="display:none"><button class="secbtn" id="clearbtn" data-i18n="chk_clear"></button>
|
| 233 |
</div>
|
| 234 |
<div id="results"><div id="verdict"></div><div class="summary" id="summary"></div><div id="reslist"></div><div id="sharedbox"></div></div>
|
| 235 |
</div>
|
|
|
|
| 279 |
</section>
|
| 280 |
</div><!-- /tab-check -->
|
| 281 |
|
| 282 |
+
<div id="tab-addr" style="display:none">
|
| 283 |
+
<div class="card checker" id="addrcard" style="margin-top:26px">
|
| 284 |
+
<h2 data-i18n="ad_h"></h2>
|
| 285 |
+
<p class="hint" data-i18n="ad_hint"></p>
|
| 286 |
+
<div class="row" style="margin-top:0"><input id="addrin" class="addrin" type="text" inputmode="url" autocapitalize="off" autocomplete="off" spellcheck="false" maxlength="260" data-i18n-ph="ad_ph"><button class="secbtn" id="myipbtn" data-i18n="ad_my"></button></div>
|
| 287 |
+
<label class="ck"><input type="checkbox" id="consent2"><span data-i18n="ad_consent"></span></label>
|
| 288 |
+
<div class="row"><button class="run" id="addrbtn" data-i18n="ad_run"></button><button class="secbtn" id="addrclear" data-i18n="ad_clear"></button></div>
|
| 289 |
+
<div id="addrmsg" class="note" role="status" aria-live="polite" style="display:none"></div>
|
| 290 |
+
<div id="addrlist"></div>
|
| 291 |
+
<div id="addrres"></div>
|
| 292 |
+
</div>
|
| 293 |
+
<p class="note" data-i18n="ad_more"></p>
|
| 294 |
+
<div class="card checker" id="card443" style="margin-top:18px">
|
| 295 |
+
<h2 data-i18n="lc_ph_h"></h2>
|
| 296 |
+
<ul class="p443"><li data-i18n="lc_p1"></li><li data-i18n="lc_p2"></li><li data-i18n="lc_p3"></li><li class="w" data-i18n="lc_p4"></li></ul>
|
| 297 |
+
</div>
|
| 298 |
+
<div class="card checker addrguide" id="guide" style="margin-top:18px">
|
| 299 |
+
<h2 data-i18n="lc_lh"></h2>
|
| 300 |
+
<p>1. <span data-i18n="lc_l1"></span></p>
|
| 301 |
+
<div class="row"><a class="secbtn dl" href="local/keyguard-local.ps1" download="keyguard-local.ps1" data-i18n="lc_lw"></a><a class="sl" href="https://huggingface.co/spaces/FINAL-Bench/KeyGuard/blob/main/local/keyguard-local.ps1" target="_blank" rel="noopener" data-i18n="lc_src"></a></div>
|
| 302 |
+
<div class="gl"><span data-i18n="lc_run"></span> · PowerShell</div><textarea id="runwin" class="cmd" readonly rows="2">powershell -ExecutionPolicy Bypass -File "$HOME\Downloads\keyguard-local.ps1"</textarea><button class="secbtn cp" data-for="runwin" data-i18n="gd_copy"></button>
|
| 303 |
+
<div class="gl hs">SHA-256 59a32327a9691de1c947f8c232cad003cb78d86d7e686b598639c575bbdaf9bc</div>
|
| 304 |
+
<div class="row"><a class="secbtn dl" href="local/keyguard-local.py" download="keyguard-local.py" data-i18n="lc_lp"></a><a class="sl" href="https://huggingface.co/spaces/FINAL-Bench/KeyGuard/blob/main/local/keyguard-local.py" target="_blank" rel="noopener" data-i18n="lc_src"></a></div>
|
| 305 |
+
<div class="gl"><span data-i18n="lc_run"></span> · Terminal</div><textarea id="runnix" class="cmd" readonly rows="2">python3 ~/Downloads/keyguard-local.py</textarea><button class="secbtn cp" data-for="runnix" data-i18n="gd_copy"></button>
|
| 306 |
+
<div class="gl hs">SHA-256 8d0d0f40702b230eb2cefda16bcde56419814869f3e3500751b9d92fccde1da0</div>
|
| 307 |
+
<p>2. <span data-i18n="lc_l2"></span></p>
|
| 308 |
+
<button class="secbtn" id="gogo" data-i18n="gd_go"></button>
|
| 309 |
+
<details style="margin-top:16px"><summary data-i18n="lc_one"></summary>
|
| 310 |
+
<p data-i18n="gd_s1"></p><div class="gl">Windows PowerShell</div><textarea id="cmdwin" class="cmd" readonly rows="5"></textarea><button class="secbtn cp" data-for="cmdwin" data-i18n="gd_copy"></button><div class="gl">macOS · Linux</div><textarea id="cmdnix" class="cmd" readonly rows="2"></textarea><button class="secbtn cp" data-for="cmdnix" data-i18n="gd_copy"></button></details>
|
| 311 |
+
<p class="note" data-i18n="lc_auth"></p>
|
| 312 |
+
</div>
|
| 313 |
+
</div><!-- /tab-addr -->
|
| 314 |
+
|
| 315 |
<div id="tab-bench" style="display:none">
|
| 316 |
<section class="block" style="margin-top:26px">
|
| 317 |
<div class="eyebrow" data-i18n="lb_eye"></div>
|
|
|
|
| 339 |
/* ================= i18n ================= */
|
| 340 |
const I18N={
|
| 341 |
ko:{
|
| 342 |
+
tag:"붙여넣은 키는 100% 브라우저 안에서 검사 · 서버로 전송되지 않습니다",
|
| 343 |
h1a:"내 장비 암호키,", h1b:"혹시 불량품 아닐까?",
|
| 344 |
lead:"공장에서 실수로 여러 장비에 똑같은 비밀 소수를 넣어 출고하면, 누군가 그걸 찾는 순간 그 장비들은 전부 열립니다. KeyGuard는 당신의 공개키가 그런 불량 키인지 수학으로 30초 만에 검사합니다.",
|
| 345 |
sub:"개인키 말고 공개키만 넣으세요. 공개키는 원래 공개되는 정보라 안전합니다.",
|
|
|
|
| 368 |
w4h:"ROCA 결함칩", w4d:"특정 칩(CVE-2017-15361)이 만든 취약 패턴 키를 의심 탐지합니다.",
|
| 369 |
proof_eye:"검증됨", proof_h:"실제 대규모 공개키로 검증 완료",
|
| 370 |
proof_lead:"합성 취약 키를 정확히 탐지하고, 실제 인증서 투명성(CT) 로그의 공개키 100만 개를 12분에 처리해 대규모 동작을 확인했습니다.",
|
| 371 |
+
proof_s1:"심은 취약 키 탐지 정확도 (오탐 0)", proof_s2:"실제 CT 공개키 분석 (스파크)", proof_s3:"붙여넣은 키의 서버 전송 (전부 클라이언트)",
|
| 372 |
proof_note:"참고: 공개 CT 로그의 웹 인증서는 대체로 잘 생성되어 취약 키가 드뭅니다. 취약 키는 주로 임베디드·IoT의 자가서명 인증서에 분포 — 그래서 '내 장비를 직접 검사'하는 이 도구가 의미가 있습니다.",
|
| 373 |
faq_eye:"자주 묻는 질문", faq_h:"궁금한 것들",
|
| 374 |
faq1q:"제 개인키가 유출되나요?", faq1a:"아니요. 공개키만 넣고, 그마저도 브라우저 밖으로 나가지 않습니다.",
|
|
|
|
| 376 |
faq3q:"여러 장비를 한꺼번에 넣어도 되나요?", faq3a:"네, 권장합니다. 장비들끼리 소수를 공유하는지는 여러 키를 함께 넣어야 검사됩니다.",
|
| 377 |
faq4q:"안전으로 나오면 100% 안심인가요?", faq4a:"이 도구가 검사하는 4가지 결함이 없다는 뜻입니다. 암호의 다른 측면은 별도 점검이 필요합니다.",
|
| 378 |
faq_warn:"⚠️ 이 도구는 본인 소유 또는 점검 위임을 받은 장비의 공개키에만 사용하세요. 타인의 장비·시스템을 무단으로 검사·침투하는 것은 법으로 금지되어 있습니다.",
|
| 379 |
+
foot1:"KeyGuard · 공개키 자가진단 · 붙여넣기 검사는 브라우저 안에서만 실행됩니다",
|
| 380 |
foot2:"교육 및 본인 자산 점검용 · 책임 있는 보안 점검(Responsible Disclosure) 원칙 준수",
|
| 381 |
b_safe:"안전", b_weak:"주의", b_bad:"위험",
|
| 382 |
s_tot:"검사한 키", s_safe:"안전", s_warn:"주의", s_bad:"위험",
|
|
|
|
| 396 |
al_consent:"본인 소유/위임 장비 확인에 체크해 주세요.", al_nokey:"유효한 RSA 공개키를 찾지 못했습니다. 형식을 확인해 주세요.",
|
| 397 |
busy:"검사 중…",
|
| 398 |
cr_label:"���원된 소인수 (이 키는 이미 깨진 키)", cr_time:"복원 시간", cr_iter:"Fermat 반복", cr_via:"복원 경로", cr_note:"공개 모듈러스만으로 누구나 복원 가능 → 즉시 폐기 필요",
|
| 399 |
+
vd_bad:(n)=>`위험한 키 ${n}개`, vd_bad_sub:"길이 또는 지수가 위험합니다. 키를 교체하세요.", vd_cracked:(n)=>`${n}개 키 뚫림 — CRACKED`, vd_cracked_sub:"개인키가 복원됐습니다. 해당 키는 즉시 폐기·교체하세요.",
|
| 400 |
vd_weak:(n)=>`${n}개 키 주의 필요`, vd_weak_sub:"지금 당장 뚫리진 않지만 교체를 권장합니다.",
|
| 401 |
vd_safe:"모두 안전", vd_safe_sub:"이 도구가 검사하는 4대 결함이 없습니다.",
|
| 402 |
+
tab_check:"🔎 자가진단", tab_bench:"🏆 벤치마크", tab_addr:"🌐 주소로 점검", lc_ph_h:"🚪 443 포트 안내", lc_p1:"443은 HTTPS(보안 웹 접속)가 드나드는 문입니다. 이 점검은 인터넷 쪽에서 그 문이 열린 기기만 볼 수 있습니다.", lc_p2:"집·사무실 공유기나 통신사는 보통 이 문을 닫아 둡니다. 그래서 「내 IP」는 응답 없음이 흔하며, 고장이 아닙니다.", lc_p3:"응답 없음은 열쇠를 보지 못했다는 뜻이고 안전 판정이 아닙니다. 안쪽 기기는 아래 방법으로 점검하십시오.", lc_p4:"점검하려고 공유기의 443 포트를 일부러 열지 마십시오. 닫혀 있는 편이 안전합니다.", lc_lh:"🏠 내 네트워크 점검기 (집·회사 안의 기기)", lc_l1:"스크립트를 내려받아 실행합니다. 내 PC가 속한 사설 네트워크에서 공개키만 읽어 안전·주의·위험을 바로 보여 줍니다. 질문이 나오면 YES를 입력하십시오. 로그인 시도와 인터넷 전송은 없습니다.", lc_l2:"(선택) 같은 폴더에 생기는 keyguard_keys.txt 를 자가진단 탭의 「파일 열기」로 넣으면 브라우저 화면에서도 자세히 볼 수 있습니다.", lc_lw:"내려받기: Windows", lc_lp:"내려받기: macOS · Linux (Python 3)", lc_src:"코드 보기", lc_run:"실행", lc_one:"기기 한 대만 빠르게", lc_auth:"본인 소유이거나 점검 권한이 있는 네트워크에서만 사용하십시오.", lc_file:"📂 파일 열기", gd_h:"🏠 집·회사 안의 기기는 이렇게 점검합니다", gd_s1:"같은 네트워크의 PC에서 아래 명령을 실행합니다. 주소는 점검할 기기(공유기, CCTV, 프린터)로 바꾸십시오.", gd_s2:"출력된 인증서를 자가진단 탭에 붙여넣습니다. 여러 기기를 함께 넣으면 서로 비교합니다. 붙여넣은 내용은 브라우저 밖으로 나가지 않습니다.", gd_copy:"복사", gd_copied:"복사됨", gd_go:"자가진단 탭으로", ad_h:"🌐 도메인·IP로 점검", ad_hint:"점검 서버가 입력한 주소의 443 포트(HTTPS)에만 접속해 공개 인증서를 받아 옵니다. 판정은 이 브라우저에서 합니다. 주소와 결과는 저장하지 않습니다.", ad_ph:"예) example.com 또는 203.0.113.10", ad_my:"📍 내 IP 넣기", ad_consent:"이 주소의 기기는 내가 소유했거나 점검 위임을 받은 기기입니다. 타인의 기기를 무단으로 점검하지 않습니다.", ad_run:"주소 점검", ad_clear:"목록 비우기", ad_more:"기기를 하나씩 더 점검하면 목록에 쌓이고, 같은 소수를 쓰는지 서로 비교합니다. 사설 IP(192.168.x.x 등)는 인터넷에서 닿지 않으므로 자가진단 탭에 인증서를 붙여넣으십시오.", ad_self:"자체 서명", ad_exp:"만료", ad_issuer:"발급", ad_got:"내 접속 IP를 넣었습니다. 위임 확인에 체크하고 점검을 누르십시오.", ad_ec:"타원곡선 키를 쓰는 기기입니다. RSA 점검 대상이 아닙니다.", ad_other:"RSA 키가 아닙니다. 점검 대상이 아닙니다.", ad_noaddr:"주소를 입력해 주세요.", ad_err:{"bad_target": "주소 형식을 확인해 주세요. 도메인이나 IP 하나만 넣을 수 있고 포트와 경로는 받지 않습니다.", "private_target": "내부 주소는 인터넷에서 닿지 않습니다. 아래 방법으로 이 PC에서 점검하십시오.", "dns": "주소를 찾지 못했습니다.", "connect": "443 포트가 닫혀 있습니다. 인터넷 쪽에서 이 기기의 열쇠를 볼 수 없다는 뜻이며 안전 판정은 아닙니다.", "timeout": "밖에서 보이지 않는 기기입니다(443 응답 없음). 고장이 아니며, 인터넷 쪽에서 이 기기의 열쇠를 볼 수 없다는 뜻입니다. 안전 판정은 아닙니다.", "tls": "TLS 연결을 맺지 못했습니다.", "rate": "요청이 많습니다. 잠시 뒤 다시 해 주세요.", "consent": "위임 확인에 체크해 주세요.", "server": "점검 서버를 깨우는 중입니다. 1분쯤 뒤에 다시 눌러 주세요.", "nomyip": "접속 IP를 확인하지 못했습니다."},
|
| 403 |
lb_eye:"스파크 실측 · 조�� 없음", lb_h:"취약키 탐지 벤치마크",
|
| 404 |
lb_lead:"표준 취약키 테스트셋에서 탐지 방법들의 재현율·오탐률·속도를 실측해 순위. 단일 방법은 일부만, 결합한 KeyGuard는 전 유형을 잡습니다.",
|
| 405 |
th_det:"탐지기", th_recall:"재현율", th_fpr:"오탐", th_time:"시간", th_cat:"유형별",
|
|
|
|
| 410 |
lb_m3h:"재현 가능", lb_m3d:"고정 시드(20262025) — 언제든 동일 재현, 조작 불가",
|
| 411 |
lb_notes:["ROCA는 본 셋에 합성 양성이 없어 0%(완전성 위해 포함).","고전 분해는 2048비트 불가로 0%(반복 상한 내 측정).","소규모 자체셋 — 숫자는 측정값만, 과장 없음."],
|
| 412 |
catlabel:{close:"가까운소수",shared:"소수공유",short:"짧은키",bade:"지수"}, me_tag:"우리",
|
| 413 |
+
sample:{fermat:["🤏 가까운 소수","두 소수가 너무 가까운 2048비트 키 — Fermat로 즉시 분해"],shared:["🔗 소수 공유 (2대)","두 장비가 같은 소수 사용 — batch-GCD로 양쪽 다 뚫림"],short:["📏 너무 짧은 키","512비트 — 현재 분해 가능 범위"],bade:["⚠️ 비정상 지수","공개지수 e=2 (잘못된 설정)"],safe:["✓ 정상 키","잘 생성된 2048비트 실제 인증서 키 — 안전"],mix:["🎯 전부 섞기","위 모든 유형을 한 번에 — 종합 리포트"]}
|
| 414 |
},
|
| 415 |
en:{
|
| 416 |
+
tag:"Pasted keys are checked 100% in your browser · never sent to a server",
|
| 417 |
h1a:"Your device's crypto key —", h1b:"is it a factory defect?",
|
| 418 |
lead:"If a factory mistakenly ships many devices with the same secret prime, anyone who finds it can open them all. KeyGuard checks, with math in 30 seconds, whether your public key is one of those defective keys.",
|
| 419 |
sub:"Paste the PUBLIC key only, never the private key. Public keys are meant to be public, so this is safe.",
|
|
|
|
| 442 |
w4h:"ROCA faulty chips", w4d:"Detects vulnerable keys from certain chips (CVE-2017-15361).",
|
| 443 |
proof_eye:"Verified", proof_h:"Validated on real large-scale public keys",
|
| 444 |
proof_lead:"Detects planted weak keys exactly, and verified at scale on 1,000,000+ real public keys from Certificate Transparency (CT) logs in 12 minutes.",
|
| 445 |
+
proof_s1:"Detection accuracy on planted weak keys (0 false positives)", proof_s2:"Real CT public keys analyzed (on Spark)", proof_s3:"Pasted keys sent to a server (all client-side)",
|
| 446 |
proof_note:"Note: Web certificates in public CT logs are usually well-generated, so weak keys are rare there. Weak keys mostly live in self-signed certs of embedded/IoT devices — which is why checking YOUR OWN devices with this tool matters.",
|
| 447 |
faq_eye:"FAQ", faq_h:"Common questions",
|
| 448 |
faq1q:"Will my private key leak?", faq1a:"No. You paste only the public key, and even that never leaves your browser.",
|
|
|
|
| 450 |
faq3q:"Can I paste many devices at once?", faq3a:"Yes, recommended. Shared-prime checks require several keys pasted together.",
|
| 451 |
faq4q:"If it says Safe, am I 100% safe?", faq4a:"It means the four defects this tool checks are absent. Other aspects of your crypto need separate review.",
|
| 452 |
faq_warn:"⚠️ Use this tool only on public keys of devices you own or are authorized to test. Testing or intruding on others' systems without permission is illegal.",
|
| 453 |
+
foot1:"KeyGuard · public-key self-check · pasted keys are checked only inside your browser",
|
| 454 |
foot2:"For education and checking your own assets · follows Responsible Disclosure",
|
| 455 |
b_safe:"Safe", b_weak:"Caution", b_bad:"Danger",
|
| 456 |
s_tot:"Keys checked", s_safe:"Safe", s_warn:"Caution", s_bad:"Danger",
|
|
|
|
| 470 |
al_consent:"Please check the ownership/authorization box.", al_nokey:"No valid RSA public key found. Please check the format.",
|
| 471 |
busy:"Checking…",
|
| 472 |
cr_label:"Recovered primes (this key is already broken)", cr_time:"Recovered in", cr_iter:"Fermat iters", cr_via:"Recovered via", cr_note:"anyone can recover these from the public modulus → retire this key now",
|
| 473 |
+
vd_bad:(n)=>`${n} KEY${n>1?'S':''} AT HIGH RISK`, vd_bad_sub:"Dangerous length or exponent. Replace these keys.", vd_cracked:(n)=>`${n} KEY${n>1?'S':''} CRACKED`, vd_cracked_sub:"The private key was recovered. Retire and replace these keys immediately.",
|
| 474 |
vd_weak:(n)=>`${n} key(s) need attention`, vd_weak_sub:"Not breakable right now, but replacement is recommended.",
|
| 475 |
vd_safe:"All safe", vd_safe_sub:"None of the four defects this tool checks were found.",
|
| 476 |
+
tab_check:"🔎 Self-check", tab_bench:"🏆 Benchmark", tab_addr:"🌐 Check an address", lc_ph_h:"🚪 About port 443", lc_p1:"443 is the door used by HTTPS. This check can only see devices whose door is open to the internet.", lc_p2:"Home and office routers or carriers usually keep it closed, so no response for your own IP is common. It is not a fault.", lc_p3:"No response means the key was not seen. It is not a Safe verdict. Check devices inside your network as shown below.", lc_p4:"Do not open port 443 on your router just for this check. Closed is safer.", lc_lh:"🏠 Local collector (devices inside your home or office)", lc_l1:"Download and run the script. It reads public keys only, in the private network of this PC, and prints Safe, Caution or Danger. Type YES when asked. No login attempts and no internet traffic.", lc_l2:"(Optional) Open keyguard_keys.txt from the same folder in the Self-check tab to see the details in your browser.", lc_lw:"Download for Windows", lc_lp:"Download for macOS · Linux (Python 3)", lc_src:"View code", lc_run:"Run", lc_one:"Quick check of a single device", lc_auth:"Use it only on networks you own or are authorized to test.", lc_file:"📂 Open file", gd_h:"🏠 Check a device inside your home or office", gd_s1:"Run this command on a PC in the same network. Replace the address with your router, camera or printer.", gd_s2:"Paste the printed certificate into the Self-check tab. Paste several devices together to compare them. Pasted text never leaves your browser.", gd_copy:"Copy", gd_copied:"Copied", gd_go:"Go to Self-check", ad_h:"🌐 Check a domain or IP", ad_hint:"Our server connects only to port 443 (HTTPS) of the address and fetches its public certificate. The verdict is computed in this browser. Addresses and results are not stored.", ad_ph:"e.g. example.com or 203.0.113.10", ad_my:"📍 Use my IP", ad_consent:"The device at this address is mine or I am authorized to test it. I will not test anyone else's device without permission.", ad_run:"Check address", ad_clear:"Clear list", ad_more:"Check more devices one by one. They are added to the list and compared with each other for shared primes. Private addresses (192.168.x.x and similar) cannot be reached from the internet, so paste their certificates in the Self-check tab.", ad_self:"self-signed", ad_exp:"expires", ad_issuer:"issuer", ad_got:"Your access IP is filled in. Tick the authorization box and run the check.", ad_ec:"This device uses an elliptic-curve key, so the RSA checks do not apply.", ad_other:"This is not an RSA key, so the RSA checks do not apply.", ad_noaddr:"Please enter an address.", ad_err:{"bad_target": "Check the address. Enter one domain or IP, with no port or path.", "private_target": "Private addresses cannot be reached from the internet. Check the device from this PC as shown below.", "dns": "The address could not be resolved.", "connect": "Port 443 is closed. The key of this device cannot be seen from the internet. This is not a Safe verdict.", "timeout": "This device is not visible from the internet (no response on port 443). It is not a fault. Its key cannot be seen from outside. This is not a Safe verdict.", "tls": "A TLS connection could not be established.", "rate": "Too many requests. Please try again shortly.", "consent": "Please tick the authorization box.", "server": "The check server is waking up. Please try again in about a minute.", "nomyip": "Your access IP could not be determined."},
|
| 477 |
lb_eye:"Measured on Spark · no cherry-picking", lb_h:"Weak-Key Detection Benchmark",
|
| 478 |
lb_lead:"Recall, false-positive rate and speed of detection methods on a standard weak-key set, ranked. Single methods catch only part; combined KeyGuard catches every type.",
|
| 479 |
th_det:"Detector", th_recall:"Recall", th_fpr:"False-pos", th_time:"Time", th_cat:"Per-category",
|
|
|
|
| 484 |
lb_m3h:"Reproducible", lb_m3d:"Fixed seed (20262025) — reproduces the set anytime, no tampering",
|
| 485 |
lb_notes:["ROCA shows 0% (no synthetic ROCA positives in this set; included for completeness).","Classical factoring is 0% (2048-bit infeasible; measured within an iteration cap).","Small self-generated set — numbers are measured values only, no exaggeration."],
|
| 486 |
catlabel:{close:"Close",shared:"Shared",short:"Short",bade:"Exp"}, me_tag:"OURS",
|
| 487 |
+
sample:{fermat:["🤏 Close primes","2048-bit key with primes too close — factored instantly by Fermat"],shared:["🔗 Shared prime (2 devices)","Two devices share a prime — both broken by batch-GCD"],short:["📏 Key too short","512-bit — within factorable range"],bade:["⚠️ Bad exponent","Public exponent e=2 (misconfigured)"],safe:["✓ Healthy key","A well-generated real 2048-bit certificate key — safe"],mix:["🎯 Mix everything","All types at once — full report"]}
|
| 488 |
},
|
| 489 |
zh:{
|
| 490 |
+
tag:"粘贴的密钥 100% 在浏览器内检测 · 绝不发送到服务器",
|
| 491 |
h1a:"你设备的加密密钥,", h1b:"会不会是次品?",
|
| 492 |
lead:"如果工厂错误地给多台设备出厂了相同的秘密素数,任何人只要找到它就能打开所有这些设备。KeyGuard 用数学在 30 秒内检测你的公钥是否就是这种次品密钥。",
|
| 493 |
sub:"只粘贴公钥,不要粘贴私钥。公钥本来就是公开的,所以这是安全的。",
|
|
|
|
| 516 |
w4h:"ROCA 缺陷芯片", w4d:"检测某些芯片(CVE-2017-15361)生成的易受攻击密钥。",
|
| 517 |
proof_eye:"已验证", proof_h:"已在真实大规模公钥上完成验证",
|
| 518 |
proof_lead:"精确检出植入的弱密钥,并在证书透明度(CT)日志的 100 万+ 真实公钥上以 12 分钟完成了大规模验证。",
|
| 519 |
+
proof_s1:"对植入弱密钥的检出准确率(0 误报)", proof_s2:"分析的真实 CT 公钥(在 Spark 上)", proof_s3:"粘贴的密钥发送到服务器(全部在客户端)",
|
| 520 |
proof_note:"注:公共 CT 日志中的网站证书通常生成良好,弱密钥很少见。弱密钥主要存在于嵌入式/IoT 设备的自签名证书中——这正是用本工具检测'你自己的设备'的意义所在。",
|
| 521 |
faq_eye:"常见问题", faq_h:"你可能想问",
|
| 522 |
faq1q:"我的私钥会泄露吗?", faq1a:"不会。你只粘贴公钥,而且它也不会离开你的浏览器。",
|
|
|
|
| 524 |
faq3q:"可以一次粘贴多台设备吗?", faq3a:"可以,建议如此。素数共享检测需要同时粘贴多个密钥。",
|
| 525 |
faq4q:"显示安全就 100% 放心吗?", faq4a:"意味着本工具检测的四种缺陷不存在。加密的其他方面需要单独审查。",
|
| 526 |
faq_warn:"⚠️ 本工具仅可用于你拥有或已获授权检测的设备公钥。未经许可检测或入侵他人系统是违法的。",
|
| 527 |
+
foot1:"KeyGuard · 公钥自检 · 粘贴检测仅在你的浏览器内运行",
|
| 528 |
foot2:"用于教育及自有资产检测 · 遵循负责任披露(Responsible Disclosure)原则",
|
| 529 |
b_safe:"安全", b_weak:"注意", b_bad:"危险",
|
| 530 |
s_tot:"已检测密钥", s_safe:"安全", s_warn:"注意", s_bad:"危险",
|
|
|
|
| 544 |
al_consent:"请勾选所有权/授权确认项。", al_nokey:"未找到有效的 RSA 公钥,请检查格式。",
|
| 545 |
busy:"检测中…",
|
| 546 |
cr_label:"已还原的素因子(此密钥已被攻破)", cr_time:"还原耗时", cr_iter:"Fermat 迭代", cr_via:"还原途径", cr_note:"仅凭公开模数任何人都能还原 → 请立即废弃此密钥",
|
| 547 |
+
vd_bad:(n)=>`${n} 个高风险密钥`, vd_bad_sub:"长度或指数存在风险,请更换密钥。", vd_cracked:(n)=>`${n} 个密钥被攻破 — CRACKED`, vd_cracked_sub:"私钥已被还原。请立即废弃并更换这些密钥。",
|
| 548 |
vd_weak:(n)=>`${n} 个密钥需注意`, vd_weak_sub:"目前不会被破解,但建议更换。",
|
| 549 |
vd_safe:"全部安全", vd_safe_sub:"未发现本工具检测的四种缺陷。",
|
| 550 |
+
tab_check:"🔎 自检", tab_bench:"🏆 基准", tab_addr:"🌐 按地址检测", lc_ph_h:"🚪 关于 443 端口", lc_p1:"443 是 HTTPS 使用的门。本检测只能看到向互联网开放此门的设备。", lc_p2:"家庭或办公室路由器和运营商通常会关闭它,因此「我的 IP」无响应很常见,这不是故障。", lc_p3:"无响应表示没有看到密钥,不是安全判定。内部设备请按下面的方法检测。", lc_p4:"请不要为了检测而在路由器上开放 443 端口。关闭更安全。", lc_lh:"🏠 本地采集器(家庭或公司内部的设备)", lc_l1:"下载并运行脚本。它只读取本机所在内网的公钥,并直接显示安全、注意或危险。提示时输入 YES。不尝试登录,不向互联网发送数据。", lc_l2:"(可选)在自检页用「打开文件」载入同一文件���中的 keyguard_keys.txt,可在浏览器中查看详情。", lc_lw:"下载:Windows", lc_lp:"下载:macOS · Linux(Python 3)", lc_src:"查看代码", lc_run:"运行", lc_one:"快速检测单台设备", lc_auth:"仅在你拥有或已获授权检测的网络中使用。", lc_file:"📂 打开文件", gd_h:"🏠 检测家庭或公司内部的设备", gd_s1:"在同一网络的电脑上运行以下命令。请把地址换成要检测的路由器、摄像头或打印机。", gd_s2:"把输出的证书粘贴到自检页。同时粘贴多台设备可相互比较。粘贴的内容不会离开浏览器。", gd_copy:"复制", gd_copied:"已复制", gd_go:"前往自检", ad_h:"🌐 按域名或 IP 检测", ad_hint:"检测服务器只连接该地址的 443 端口(HTTPS),取得其公开证书。判定在本浏览器内完成。不保存地址和结果。", ad_ph:"例如 example.com 或 203.0.113.10", ad_my:"📍 填入我的 IP", ad_consent:"该地址的设备归我所有或我已获授权检测。我不会未经许可检测他人的设备。", ad_run:"检测地址", ad_clear:"清空列表", ad_more:"可逐个检测更多设备,结果会加入列表并相互比较是否共享素数。内网地址(192.168.x.x 等)无法从互联网访问,请在自检页粘贴其证书。", ad_self:"自签名", ad_exp:"到期", ad_issuer:"签发", ad_got:"已填入你的访问 IP。请勾选授权确认后开始检测。", ad_ec:"该设备使用椭圆曲线密钥,不适用 RSA 检测。", ad_other:"不是 RSA 密钥,不适用 RSA 检测。", ad_noaddr:"请输入地址。", ad_err:{"bad_target": "请检查地址格式。只能输入一个域名或 IP,不含端口和路径。", "private_target": "内网地址无法从互联网访问,请按以下方法在本机检测。", "dns": "无法解析该地址。", "connect": "443 端口已关闭,外部看不到该设备的密钥。这不是安全判定。", "timeout": "该设备在互联网上不可见(443 无响应)。这不是故障,表示外部看不到其密钥。这不是安全判定。", "tls": "无法建立 TLS 连接。", "rate": "请求过多,请稍后再试。", "consent": "请勾选授权确认。", "server": "检测服务器正在唤醒,请约一分钟后重试。", "nomyip": "无法确定你的访问 IP。"},
|
| 551 |
lb_eye:"在 Spark 实测 · 无挑选", lb_h:"弱密钥检测基准",
|
| 552 |
lb_lead:"在标准弱密钥测试集上实测各检测方法的召回率、误报率与速度并排名。单一方法只能检出部分,组合的 KeyGuard 可检出所有类型。",
|
| 553 |
th_det:"检测器", th_recall:"召回率", th_fpr:"误报", th_time:"耗时", th_cat:"按类型",
|
|
|
|
| 558 |
lb_m3h:"可复现", lb_m3d:"固定种子(20262025) — 随时复现,不可篡改",
|
| 559 |
lb_notes:["ROCA 为 0%(本集无合成 ROCA 阳性,为完整性而列入)。","经典分解为 0%(2048 位不可行,在迭代上限内测量)。","小规模自建集 — 数字仅为实测值,无夸大。"],
|
| 560 |
catlabel:{close:"相近",shared:"共享",short:"过短",bade:"指数"}, me_tag:"我们",
|
| 561 |
+
sample:{fermat:["🤏 相近素数","两素数过近的 2048 位密钥 — 被 Fermat 瞬间分解"],shared:["🔗 素数共享 (2台)","两台设备共享素数 — 被 batch-GCD 同时攻破"],short:["📏 密钥过短","512 位 — 处于可分解范围"],bade:["⚠️ 异常指数","公开指数 e=2(配置错误)"],safe:["✓ 正常密钥","生成良好的真实 2048 位证书密钥 — 安全"],mix:["🎯 全部混合","一次检测以上所有类型 — 综合报告"]}
|
| 562 |
}
|
| 563 |
};
|
| 564 |
let LANG='ko';
|
|
|
|
| 569 |
document.querySelectorAll('[data-i18n-ph]').forEach(el=>{const v=t(el.getAttribute('data-i18n-ph'));if(typeof v==='string')el.setAttribute('placeholder',v);});
|
| 570 |
document.querySelectorAll('#langsw button').forEach(b=>b.classList.toggle('on',b.dataset.lang===LANG));
|
| 571 |
renderChips();renderBoard();
|
| 572 |
+
if(typeof ADDR!=='undefined'&&ADDR.length)renderAddr();
|
| 573 |
}
|
| 574 |
function detectLang(){
|
| 575 |
try{const s=localStorage.getItem('kg-lang');if(s&&I18N[s])return s;}catch(e){}
|
|
|
|
| 594 |
function rocaHeuristic(n){try{for(const p of ROCA_PRIMES){const P=bi(p);let res=new Set();let x=1n;for(let k=1;k<p;k++){x=(x*65537n)%P;res.add(x.toString());}const r=(n%P);if(r!==0n&&!res.has(r.toString()))return false;}return true;}catch(e){return false;}}
|
| 595 |
function b64ToBytes(b64){const bin=atob(b64.replace(/\s+/g,''));const a=new Uint8Array(bin.length);for(let i=0;i<bin.length;i++)a[i]=bin.charCodeAt(i);return a;}
|
| 596 |
function derIntegers(bytes){const out=[];let i=0;function len(){let l=bytes[i++];if(l&0x80){let k=l&0x7f;l=0;while(k--)l=(l<<8)|bytes[i++];}return l;}function walk(end){while(i<end){const tag=bytes[i++];const l=len();const s=i;if(tag===0x02){let hex='';for(let j=s;j<s+l;j++)hex+=bytes[j].toString(16).padStart(2,'0');if(hex)out.push(BigInt('0x'+hex));i=s+l;}else if(tag===0x30||tag===0x31||tag===0x03){walk(s+l);i=s+l;}else{i=s+l;}}}try{walk(bytes.length);}catch(e){}return out;}
|
| 597 |
+
const RSA_OID=[0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x01];
|
| 598 |
+
function rsaFromDer(by){let o=-1;for(let i=0;i+RSA_OID.length<=by.length;i++){let m=true;for(let j=0;j<RSA_OID.length;j++)if(by[i+j]!==RSA_OID[j]){m=false;break;}if(m){o=i+RSA_OID.length;break;}}
|
| 599 |
+
let ints;if(o<0){ints=derIntegers(by);}else{let i=o;if(by[i]===0x05&&by[i+1]===0x00)i+=2;if(by[i]!==0x03)return null;i++;let l=by[i++];if(l&0x80){let k=l&0x7f;l=0;while(k--)l=(l<<8)|by[i++];}if(by[i]!==0x00)return null;ints=derIntegers(by.slice(i+1,i+l));}
|
| 600 |
+
return ints.length>=2?{n:ints[0],e:ints[1]}:null;}
|
| 601 |
+
function sshRsa(line){const m=line.match(/^ssh-rsa\s+([A-Za-z0-9+\/=]+)/);if(!m)return null;const by=b64ToBytes(m[1]);let i=0;const f=[];while(i+4<=by.length&&f.length<3){const l=((by[i]<<24)|(by[i+1]<<16)|(by[i+2]<<8)|by[i+3])>>>0;i+=4;if(i+l>by.length)return null;f.push(by.slice(i,i+l));i+=l;}
|
| 602 |
+
if(f.length<3)return null;const b=x=>{let h='';for(const c of x)h+=c.toString(16).padStart(2,'0');return BigInt('0x'+(h||'0'));};return{n:b(f[2]),e:b(f[1])};}
|
| 603 |
function parseNum(s){s=s.trim().replace(/\s/g,'');if(/^0x/i.test(s))return BigInt(s);if(/^[0-9]+$/.test(s))return BigInt(s);if(/^[0-9a-fA-F]+$/.test(s))return BigInt('0x'+s);throw 'bad';}
|
| 604 |
+
function parseKey(line){line=line.trim();if(!line)return null;if(line.startsWith('ssh-rsa')){try{return sshRsa(line);}catch(e){return null;}}
|
| 605 |
+
if(line.includes('BEGIN')){const m=line.match(/-----BEGIN ([^-]+)-----([\s\S]*?)-----END/);if(!m||/PRIVATE/.test(m[1]))return null;try{return rsaFromDer(b64ToBytes(m[2]));}catch(e){return null;}}if(line.includes(':')){const[a,b]=line.split(':');try{return{n:parseNum(a),e:parseNum(b)};}catch(e){return null;}}try{return{n:parseNum(line),e:65537n};}catch(e){return null;}}
|
| 606 |
function assess(n,e){const bits=bitlen(n);const flags=[];let level='safe';const rec={};
|
| 607 |
if(bits<=768){level='critical';flags.push(t('f_size_c')(bits));}else if(bits<2048){level='weak';flags.push(t('f_size_w')(bits));}
|
| 608 |
if(e<3n||e%2n===0n){level='critical';flags.push(t('f_exp')(e));}
|
|
|
|
| 630 |
if(BUSY)return;
|
| 631 |
if(!$('consent').checked){alert(t('al_consent'));return;}
|
| 632 |
BUSY=true;const btn=$('runbtn');const prev=btn.textContent;btn.textContent=t('busy');btn.style.opacity='.7';
|
| 633 |
+
$('checker').appendChild($('results'));await sleep(30);try{await doCheck();}finally{btn.textContent=prev;btn.style.opacity='1';BUSY=false;}
|
| 634 |
}
|
| 635 |
+
async function doCheck(src){
|
| 636 |
+
const lines=(src==null?$('keyin').value:src).split('\n');const blocks=[],labs=[];let buf='',lab='';const put=b=>{blocks.push(b);labs.push(lab);lab='';};
|
| 637 |
+
for(const ln of lines){if(!buf&&/^\s*#/.test(ln)){lab=ln.replace(/^\s*#\s*/,'').trim().slice(0,80);continue;}if(ln.includes('BEGIN'))buf=ln+'\n';else if(buf){buf+=ln+'\n';if(ln.includes('END')){put(buf);buf='';}}else if(ln.trim())put(ln);}
|
| 638 |
+
const parsed=[];blocks.forEach((b,i)=>{const k=parseKey(b);if(k&&k.n>1n)parsed.push({idx:i+1,lab:labs[i],...k});});
|
| 639 |
if(!parsed.length){$('results').style.display='none';alert(t('al_nokey'));return;}
|
| 640 |
const shared=[];const sharedMap={};const sharedG={};
|
| 641 |
for(let a=0;a<parsed.length;a++)for(let b=a+1;b<parsed.length;b++){const g=bgcd(parsed[a].n,parsed[b].n);if(g!==1n&&g!==parsed[a].n&&g!==parsed[b].n){const bits=bitlen(g);shared.push([parsed[a].idx,parsed[b].idx,bits]);(sharedMap[parsed[a].idx]=sharedMap[parsed[a].idx]||[]).push(parsed[b].idx);(sharedMap[parsed[b].idx]=sharedMap[parsed[b].idx]||[]).push(parsed[a].idx);sharedG[parsed[a].idx]=g;sharedG[parsed[b].idx]=g;}}
|
| 642 |
+
let nSafe=0,nWeak=0,nBad=0,nCracked=0;const rows=[];
|
| 643 |
for(const k of parsed){await sleep(0);const r=assess(k.n,k.e);
|
| 644 |
if(sharedMap[k.idx]){r.level='critical';r.flags.unshift(t('f_shared')(sharedMap[k.idx].map(x=>'#'+x).join(', ')));if(!r.rec.p){const g=sharedG[k.idx];r.rec={p:g,q:k.n/g,method:'shared'};}}
|
| 645 |
+
if(r.level==='safe')nSafe++;else if(r.level==='weak')nWeak++;else nBad++;if(r.rec.p)nCracked++;
|
| 646 |
const emoji=r.level==='safe'?'✓':r.level==='weak'?'!':'✕';const badge=r.level==='safe'?t('b_safe'):r.level==='weak'?t('b_weak'):t('b_bad');
|
| 647 |
+
rows.push(`<div class="res ${r.level}"><div class="ic">${emoji}</div><div class="body"><div class="tt">${esc(t('key_n')(k.idx,r.bits))}${k.lab?' · '+esc(k.lab):''}</div><div class="ds">${r.flags.length?esc(r.flags.join(' / ')):esc(t('f_nodefect'))}</div>${crackHTML(r.rec,r.bits)}</div><span class="badge">${badge}</span></div>`);}
|
| 648 |
// 극적 판정 배너
|
| 649 |
+
if(nBad>0&&nCracked===0){$('verdict').innerHTML=`<div class="verdict bad"><div class="big">${esc(t('vd_bad')(nBad))}</div><div class="sub2">${esc(t('vd_bad_sub'))}</div></div>`;}
|
| 650 |
+
else if(nBad>0){$('verdict').innerHTML=`<div class="verdict bad"><div class="lock">🔓</div><div class="big">${esc(t('vd_cracked')(nCracked))}</div><div class="sub2">${esc(t('vd_cracked_sub'))}</div></div>`;}
|
| 651 |
else if(nWeak>0){$('verdict').innerHTML=`<div class="verdict bad" style="border-color:var(--warn);background:radial-gradient(120% 140% at 50% 0,rgba(251,191,36,.18),transparent)"><div class="big" style="color:var(--warn)">${esc(t('vd_weak')(nWeak))}</div><div class="sub2">${esc(t('vd_weak_sub'))}</div></div>`;}
|
| 652 |
else{$('verdict').innerHTML=`<div class="verdict safe"><div class="big">🛡️ ${esc(t('vd_safe'))}</div><div class="sub2">${esc(t('vd_safe_sub'))}</div></div>`;}
|
| 653 |
$('summary').innerHTML=`<div class="card stat tot"><div class="n">${parsed.length}</div><div class="l">${esc(t('s_tot'))}</div></div><div class="card stat ok"><div class="n">${nSafe}</div><div class="l">${esc(t('s_safe'))}</div></div><div class="card stat warn"><div class="n">${nWeak}</div><div class="l">${esc(t('s_warn'))}</div></div><div class="card stat bad"><div class="n">${nBad}</div><div class="l">${esc(t('s_bad'))}</div></div>`;
|
|
|
|
| 662 |
box.querySelectorAll('.schip').forEach(b=>b.onclick=()=>{const s=SAMPLES[b.dataset.k];$('keyin').value=s.keys.join('\n');$('consent').checked=true;runCheck();});}
|
| 663 |
$('clearbtn').onclick=()=>{$('keyin').value='';$('results').style.display='none';};
|
| 664 |
$('runbtn').onclick=runCheck;
|
| 665 |
+
async function loadFiles(fs){let o=[];for(const f of [...fs].slice(0,20)){if(f.size>2000000)continue;const x=(await f.text()).replace(/^\ufeff/,'');if(/PRIVATE KEY/.test(x))continue;o.push(/^\s*#/.test(x)?x:'# '+f.name+'\n'+x);}if(o.length)$('keyin').value=o.join('\n');}
|
| 666 |
+
$('filebtn').onclick=()=>$('filein').click();$('filein').onchange=async e=>{await loadFiles(e.target.files);e.target.value='';};
|
| 667 |
+
$('keyin').addEventListener('dragover',e=>e.preventDefault());$('keyin').addEventListener('drop',async e=>{if(e.dataTransfer.files.length){e.preventDefault();await loadFiles(e.dataTransfer.files);}});
|
| 668 |
document.querySelectorAll('#langsw button').forEach(b=>b.onclick=()=>{LANG=b.dataset.lang;try{localStorage.setItem('kg-lang',LANG);}catch(e){}applyLang();});
|
| 669 |
$('themeToggle').onclick=()=>{const r=document.documentElement;r.setAttribute('data-theme',r.getAttribute('data-theme')==='dark'?'light':'dark');try{localStorage.setItem('kg-theme',r.getAttribute('data-theme'));}catch(e){}};
|
| 670 |
try{const th=localStorage.getItem('kg-theme');if(th)document.documentElement.setAttribute('data-theme',th);}catch(e){}
|
|
|
|
| 685 |
}).join('');
|
| 686 |
$('lbnotes').innerHTML=t('lb_notes').map(n=>`<li>${esc(n)}</li>`).join('');
|
| 687 |
}
|
| 688 |
+
/* ===== address check ===== */
|
| 689 |
+
const API="https://final-bench-keyguard-api.hf.space/";let ADDR=[];let WOKE=false;
|
| 690 |
+
function adMsg(x){const m=$('addrmsg');m.textContent=x||'';m.style.display=x?'block':'none';}
|
| 691 |
+
function guide(host){const g=$('guide');if(host===undefined)return;
|
| 692 |
+
const h=/^(10|192\.168|172\.(1[6-9]|2\d|3[01]))(\.\d{1,3}){2,3}$/.test(host)?host:'192.168.0.1';
|
| 693 |
+
$('cmdwin').value=`$h='${h}';$c=New-Object Net.Sockets.TcpClient($h,443);$s=New-Object Net.Security.SslStream($c.GetStream(),$false,{$true});$s.AuthenticateAsClient($h);'-----BEGIN CERTIFICATE-----';[Convert]::ToBase64String($s.RemoteCertificate.GetRawCertData(),1);'-----END CERTIFICATE-----'`;
|
| 694 |
+
$('cmdnix').value=`openssl s_client -connect ${h}:443 </dev/null 2>/dev/null | openssl x509`;if(host)g.scrollIntoView({behavior:'smooth',block:'nearest'});}
|
| 695 |
+
document.querySelectorAll('.cp').forEach(b=>b.onclick=async()=>{const e=$(b.dataset.for);e.select();let ok=false;try{await navigator.clipboard.writeText(e.value);ok=true;}catch(x){try{ok=document.execCommand('copy');}catch(y){}}if(ok){b.textContent=t('gd_copied');setTimeout(()=>b.textContent=t('gd_copy'),1500);}});
|
| 696 |
+
$('gogo').onclick=()=>{showTab('check');$('keyin').scrollIntoView({block:'center'});$('keyin').focus();};
|
| 697 |
+
function adErr(c){const e=t('ad_err');return e[c]||e.tls;}
|
| 698 |
+
function renderAddr(){let n=0;$('addrlist').innerHTML=ADDR.map(a=>{const rs=a.type==='RSA'&&a.key;const no=rs?'#'+(++n):'ℹ';
|
| 699 |
+
const meta=[a.type+(a.key?' '+bitlen(a.key.n):a.bits?' '+a.bits:''),a.tls,a.self_signed?t('ad_self'):(a.issuer?t('ad_issuer')+' '+a.issuer:''),a.not_after?t('ad_exp')+' '+a.not_after:''].filter(Boolean).join(' · ');
|
| 700 |
+
return `<div class="addrrow"><span>${no}</span><b>${esc(a.target)}</b><span>${esc(meta)}</span>${rs?'':`<span>${esc(a.type==='EC'?t('ad_ec'):a.type==='RSA'?t('al_nokey'):t('ad_other'))}</span>`}</div>`;}).join('');}
|
| 701 |
+
async function runAddr(){
|
| 702 |
+
if(BUSY)return;const v=$('addrin').value.trim();
|
| 703 |
+
if(!v){adMsg(t('ad_noaddr'));return;}
|
| 704 |
+
if(!$('consent2').checked){adMsg(adErr('consent'));return;}
|
| 705 |
+
BUSY=true;const btn=$('addrbtn');btn.textContent=t('busy');btn.style.opacity='.7';adMsg('');
|
| 706 |
+
try{
|
| 707 |
+
let j;try{const r=await fetch(API+'api/cert',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({target:v,consent:true})});j=await r.json();}catch(e){j={ok:false,error:'server'};}
|
| 708 |
+
if(!j.ok){adMsg(adErr(j.error));if(['timeout','connect','private_target'].includes(j.error))guide(v);return;}
|
| 709 |
+
j.key=j.type==='RSA'?parseKey(j.pem):null;
|
| 710 |
+
ADDR=ADDR.filter(a=>a.target!==j.target);ADDR.push(j);if(ADDR.length>50)ADDR.shift();
|
| 711 |
+
const ks=ADDR.filter(a=>a.key);
|
| 712 |
+
if(ks.length){const src=[];ks.forEach(a=>src.push('# '+a.target,a.key.n.toString()+':'+a.key.e.toString()));$('addrres').appendChild($('results'));renderAddr();await doCheck(src.join('\n'));}
|
| 713 |
+
else{$('results').style.display='none';renderAddr();}
|
| 714 |
+
}finally{btn.textContent=t('ad_run');btn.style.opacity='1';BUSY=false;}
|
| 715 |
+
}
|
| 716 |
+
$('addrbtn').onclick=runAddr;$('addrin').addEventListener('keydown',e=>{if(e.key==='Enter')runAddr();});
|
| 717 |
+
$('addrclear').onclick=()=>{ADDR=[];$('addrin').value='';$('addrlist').innerHTML='';adMsg('');$('results').style.display='none';};
|
| 718 |
+
$('myipbtn').onclick=async()=>{try{const j=await(await fetch(API+'api/myip')).json();if(!j.ip||!j.public){adMsg(adErr('nomyip'));return;}$('addrin').value=j.ip;adMsg(t('ad_got'));}catch(e){adMsg(adErr('server'));}};
|
| 719 |
/* ===== tabs ===== */
|
| 720 |
function showTab(which){
|
| 721 |
+
[['check','tabCheck','tab-check'],['addr','tabAddr','tab-addr'],['bench','tabBench','tab-bench']].forEach(([k,b,p])=>{$(p).style.display=k===which?'block':'none';$(b).classList.toggle('on',k===which);});
|
| 722 |
+
if(which==='bench')renderBoard();
|
| 723 |
+
if(which==='addr'&&!WOKE){WOKE=true;fetch(API+'api/myip').catch(()=>{});}
|
|
|
|
| 724 |
try{localStorage.setItem('kg-tab',which);}catch(e){}
|
| 725 |
}
|
| 726 |
+
$('tabCheck').onclick=()=>showTab('check');$('tabAddr').onclick=()=>showTab('addr');$('tabBench').onclick=()=>showTab('bench');
|
| 727 |
|
| 728 |
+
guide('');
|
| 729 |
LANG=detectLang();applyLang();
|
| 730 |
+
try{const tb=localStorage.getItem('kg-tab');if(tb==='bench'||tb==='addr')showTab(tb);}catch(e){}
|
| 731 |
</script>
|
| 732 |
</body>
|
| 733 |
</html>
|
local/keyguard-local.ps1
CHANGED
|
@@ -1,14 +1,74 @@
|
|
| 1 |
-
# KeyGuard Local for Windows (PowerShell 5.1 or 7):
|
| 2 |
#
|
| 3 |
# powershell -ExecutionPolicy Bypass -File .\keyguard-local.ps1
|
| 4 |
# powershell -ExecutionPolicy Bypass -File .\keyguard-local.ps1 -Hosts 192.168.0.1,192.168.0.20
|
| 5 |
#
|
| 6 |
# What it does: TCP connect, one TLS handshake per open port (and ssh-keyscan on port 22 when available).
|
| 7 |
-
# What it never does: no login attempts, no private keys, no internet traffic, no upload. The file stays on this computer.
|
| 8 |
-
#
|
| 9 |
# Use it only on networks and devices you own or are authorized to test. MIT License, VIDRAFT.
|
| 10 |
-
param([string[]]$Hosts, [string]$Subnet, [int[]]$Ports = @(443, 8443, 22), [string]$Out
|
| 11 |
$ErrorActionPreference = 'Stop'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
function Test-PrivateIp([string]$ip) {
|
| 14 |
if ($ip -notmatch '^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$') { return $false }
|
|
@@ -67,7 +127,9 @@ Write-Host ("Target: {0} to {1} ({2} addresses), ports {3}" -f $list[0], $list[-
|
|
| 67 |
if (-not $Yes) {
|
| 68 |
Write-Host 'Use this only on a network you own or are authorized to test.'
|
| 69 |
Write-Host '본인 소유이거나 점검 권한이 있는 네트워크에서만 사용하십시오.'
|
| 70 |
-
|
|
|
|
|
|
|
| 71 |
}
|
| 72 |
|
| 73 |
$todo = @(foreach ($h in $list) { foreach ($q in $Ports) { [pscustomobject]@{ ip = $h; port = $q } } })
|
|
@@ -82,13 +144,42 @@ for ($i = 0; $i -lt $todo.Count; $i += 64) {
|
|
| 82 |
}
|
| 83 |
Write-Progress -Activity 'KeyGuard Local' -Completed
|
| 84 |
Write-Host ("Open ports: {0}" -f $open.Count)
|
| 85 |
-
$lines = @('# KeyGuard Local: public keys only'); $
|
| 86 |
foreach ($t in $open) {
|
|
|
|
| 87 |
$k = if ($t.port -eq 22) { Get-SshRsa $t.ip } else { Get-CertPem $t.ip $t.port }
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
}
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
Write-Host (
|
| 93 |
-
Write-Host (
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# KeyGuard Local for Windows (PowerShell 5.1 or 7): check the RSA PUBLIC keys of devices in your own private network and print the verdict.
|
| 2 |
#
|
| 3 |
# powershell -ExecutionPolicy Bypass -File .\keyguard-local.ps1
|
| 4 |
# powershell -ExecutionPolicy Bypass -File .\keyguard-local.ps1 -Hosts 192.168.0.1,192.168.0.20
|
| 5 |
#
|
| 6 |
# What it does: TCP connect, one TLS handshake per open port (and ssh-keyscan on port 22 when available).
|
| 7 |
+
# What it never does: no login attempts, no private keys, no internet traffic, no upload. The verdict is computed here and the key file stays on this computer.
|
| 8 |
+
# The same file can also be opened in the Self-check tab of https://huggingface.co/spaces/FINAL-Bench/KeyGuard (checked inside your browser).
|
| 9 |
# Use it only on networks and devices you own or are authorized to test. MIT License, VIDRAFT.
|
| 10 |
+
param([string[]]$Hosts, [string]$Subnet, [int[]]$Ports = @(443, 8443, 22), [string]$Out, [switch]$Yes)
|
| 11 |
$ErrorActionPreference = 'Stop'
|
| 12 |
+
try { Add-Type -AssemblyName System.Numerics -ErrorAction SilentlyContinue } catch { }
|
| 13 |
+
$ko = (Get-UICulture).TwoLetterISOLanguageName -eq 'ko'
|
| 14 |
+
function T([string]$k, [string]$e) { if ($ko) { $k } else { $e } }
|
| 15 |
+
$Big = [System.Numerics.BigInteger]
|
| 16 |
+
function ConvertTo-Big([byte[]]$b) {
|
| 17 |
+
# big endian unsigned bytes -> BigInteger
|
| 18 |
+
$x = New-Object byte[] ($b.Length + 1); for ($i = 0; $i -lt $b.Length; $i++) { $x[$i] = $b[$b.Length - 1 - $i] }
|
| 19 |
+
return New-Object System.Numerics.BigInteger (, $x)
|
| 20 |
+
}
|
| 21 |
+
function Get-Sub([byte[]]$b, [int]$i, [int]$n) { $o = New-Object byte[] $n; [Array]::Copy($b, $i, $o, 0, $n); return , $o }
|
| 22 |
+
function Get-RsaKey([string]$text) {
|
| 23 |
+
# @{n;e} of an RSA certificate or ssh-rsa line, else $null
|
| 24 |
+
try {
|
| 25 |
+
if ($text.StartsWith('ssh-rsa ')) {
|
| 26 |
+
$b = [Convert]::FromBase64String($text.Split(' ')[1]); $f = @(); $i = 0
|
| 27 |
+
while ($i + 4 -le $b.Length -and $f.Count -lt 3) { $n = ([int]$b[$i] -shl 24) + ([int]$b[$i + 1] -shl 16) + ([int]$b[$i + 2] -shl 8) + $b[$i + 3]; $f += , (Get-Sub $b ($i + 4) $n); $i += 4 + $n }
|
| 28 |
+
return @{ n = (ConvertTo-Big $f[2]); e = (ConvertTo-Big $f[1]) }
|
| 29 |
+
}
|
| 30 |
+
$c = New-Object Security.Cryptography.X509Certificates.X509Certificate2 (, [Convert]::FromBase64String(($text -replace '-----[^-]+-----', '' -replace '\s', '')))
|
| 31 |
+
if ($c.PublicKey.Oid.Value -ne '1.2.840.113549.1.1.1') { return $null }
|
| 32 |
+
$b = $c.PublicKey.EncodedKeyValue.RawData; $v = @()
|
| 33 |
+
$i = 1; if ($b[$i] -band 0x80) { $i += 1 + ($b[$i] -band 0x7F) } else { $i++ }
|
| 34 |
+
while ($v.Count -lt 2) {
|
| 35 |
+
if ($b[$i] -ne 2) { return $null }
|
| 36 |
+
$i++; $n = [int]$b[$i]; $i++
|
| 37 |
+
if ($n -band 0x80) { $k = $n -band 0x7F; $n = 0; for ($q = 0; $q -lt $k; $q++) { $n = ($n -shl 8) + $b[$i]; $i++ } }
|
| 38 |
+
$v += , (Get-Sub $b $i $n); $i += $n
|
| 39 |
+
}
|
| 40 |
+
return @{ n = (ConvertTo-Big $v[0]); e = (ConvertTo-Big $v[1]) }
|
| 41 |
+
} catch { return $null }
|
| 42 |
+
}
|
| 43 |
+
function Get-BitLen($n) { $b = $n.ToByteArray(); $i = $b.Length - 1; while ($i -gt 0 -and $b[$i] -eq 0) { $i-- }; $k = 0; $v = [int]$b[$i]; while ($v) { $k++; $v = $v -shr 1 }; return $i * 8 + $k }
|
| 44 |
+
function Get-Isqrt($n) {
|
| 45 |
+
if ($n.IsZero) { return $n }
|
| 46 |
+
$x = $Big::Pow(2, [int][Math]::Ceiling((Get-BitLen $n) / 2.0))
|
| 47 |
+
while ($true) { $y = $Big::Divide($Big::Add($x, $Big::Divide($n, $x)), 2); if ($y -ge $x) { return $x }; $x = $y }
|
| 48 |
+
}
|
| 49 |
+
$Sq = @{}; foreach ($m in 64, 63, 65, 11) { $h = New-Object bool[] $m; for ($i = 0; $i -lt $m; $i++) { $h[($i * $i) % $m] = $true }; $Sq[$m] = $h }
|
| 50 |
+
function Test-Fermat($n) {
|
| 51 |
+
if ($n.IsEven) { return $true }
|
| 52 |
+
$a = Get-Isqrt $n; if ($Big::Multiply($a, $a) -lt $n) { $a = $Big::Add($a, 1) }
|
| 53 |
+
$d = $Big::Subtract($Big::Multiply($a, $a), $n); $step = $Big::Add($Big::Multiply($a, 2), 1)
|
| 54 |
+
for ($k = 0; $k -lt 2000; $k++) {
|
| 55 |
+
$m = [int]$Big::Remainder($d, 2882880) # 64*63*65*11
|
| 56 |
+
if ($Sq[64][$m % 64] -and $Sq[63][$m % 63] -and $Sq[65][$m % 65] -and $Sq[11][$m % 11]) {
|
| 57 |
+
$q = Get-Isqrt $d
|
| 58 |
+
if ($Big::Multiply($q, $q) -eq $d -and $Big::Subtract($a, $q) -gt 1) { return $true }
|
| 59 |
+
}
|
| 60 |
+
$d = $Big::Add($d, $step); $step = $Big::Add($step, 2); $a = $Big::Add($a, 1)
|
| 61 |
+
}
|
| 62 |
+
return $false
|
| 63 |
+
}
|
| 64 |
+
function Test-Roca($n) {
|
| 65 |
+
foreach ($q in 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 151, 163, 167) {
|
| 66 |
+
$r = [int]$Big::Remainder($n, $q); if ($r -eq 0) { continue }
|
| 67 |
+
$x = 1; $hit = $false; for ($i = 1; $i -lt $q; $i++) { $x = ($x * (65537 % $q)) % $q; if ($x -eq $r) { $hit = $true; break } }
|
| 68 |
+
if (-not $hit) { return $false }
|
| 69 |
+
}
|
| 70 |
+
return $true
|
| 71 |
+
}
|
| 72 |
|
| 73 |
function Test-PrivateIp([string]$ip) {
|
| 74 |
if ($ip -notmatch '^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$') { return $false }
|
|
|
|
| 127 |
if (-not $Yes) {
|
| 128 |
Write-Host 'Use this only on a network you own or are authorized to test.'
|
| 129 |
Write-Host '본인 소유이거나 점검 권한이 있는 네트워크에서만 사용하십시오.'
|
| 130 |
+
$q = ''
|
| 131 |
+
for ($i = 0; $i -lt 3; $i++) { $q = ([string](Read-Host 'Type YES to continue, NO to stop / 계속하려면 YES, 그만두려면 NO')).Trim().ToUpper(); if ($q -in 'YES', 'Y', 'NO', 'N') { break } }
|
| 132 |
+
if ($q -notin 'YES', 'Y') { Write-Host 'Stopped.'; exit 1 }
|
| 133 |
}
|
| 134 |
|
| 135 |
$todo = @(foreach ($h in $list) { foreach ($q in $Ports) { [pscustomobject]@{ ip = $h; port = $q } } })
|
|
|
|
| 144 |
}
|
| 145 |
Write-Progress -Activity 'KeyGuard Local' -Completed
|
| 146 |
Write-Host ("Open ports: {0}" -f $open.Count)
|
| 147 |
+
$lines = @('# KeyGuard Local: public keys only'); $keys = @(); $rows = @()
|
| 148 |
foreach ($t in $open) {
|
| 149 |
+
$lab = '{0}:{1}' -f $t.ip, $t.port
|
| 150 |
$k = if ($t.port -eq 22) { Get-SshRsa $t.ip } else { Get-CertPem $t.ip $t.port }
|
| 151 |
+
$v = $null
|
| 152 |
+
if ($k) { $lines += "# $lab"; $lines += $k; $v = Get-RsaKey $k }
|
| 153 |
+
if ($v) { $keys += [pscustomobject]@{ lab = $lab; n = $v.n; e = $v.e; share = @() } }
|
| 154 |
+
elseif ($k) { $rows += (' [-] {0} {1}' -f $lab, (T 'RSA 키가 아님 (점검 대상 아님)' 'not an RSA key (not applicable)')) }
|
| 155 |
+
else { $rows += (' [-] {0} {1}' -f $lab, (T '공개키를 주지 않음' 'no public key offered')) }
|
| 156 |
+
}
|
| 157 |
+
for ($i = 0; $i -lt $keys.Count; $i++) { for ($j = 0; $j -lt $i; $j++) {
|
| 158 |
+
$g = $Big::GreatestCommonDivisor($keys[$i].n, $keys[$j].n)
|
| 159 |
+
if (-not $g.IsOne -and $g -ne $keys[$i].n -and $g -ne $keys[$j].n) { $keys[$i].share += $keys[$j].lab; $keys[$j].share += $keys[$i].lab }
|
| 160 |
+
} }
|
| 161 |
+
$name = @((T '안전' 'SAFE'), (T '주의' 'CAUTION'), (T '위험' 'DANGER')); $col = @('Green', 'Yellow', 'Red'); $cnt = @(0, 0, 0)
|
| 162 |
+
Write-Host ''
|
| 163 |
+
Write-Host (T '=== 점검 결과 ===' '=== RESULT ===')
|
| 164 |
+
foreach ($k in $keys) {
|
| 165 |
+
$bits = Get-BitLen $k.n; $lv = 0; $why = @()
|
| 166 |
+
if ($k.share.Count) { $lv = 2; $why += (T '같은 소수를 쓰는 기기: ' 'shares a prime with ') + ($k.share -join ', ') }
|
| 167 |
+
if ($bits -le 768) { $lv = 2; $why += (T '짧은 키' 'short key') } elseif ($bits -lt 2048) { $lv = [Math]::Max($lv, 1); $why += (T '2048비트 미만' 'under 2048 bits') }
|
| 168 |
+
if ($k.e -lt 3 -or $k.e.IsEven) { $lv = 2; $why += (T '비정상 지수' 'abnormal exponent') }
|
| 169 |
+
if (Test-Fermat $k.n) { $lv = 2; $why += (T '두 소수가 너무 가까움' 'primes too close') }
|
| 170 |
+
if ($bits -ge 512 -and (Test-Roca $k.n)) { $lv = [Math]::Max($lv, 1); $why += 'ROCA CVE-2017-15361' }
|
| 171 |
+
if (-not $why.Count) { $why += (T '4대 결함 없음' 'none of the four defects') }
|
| 172 |
+
$cnt[$lv]++
|
| 173 |
+
Write-Host (' [{0}] {1} RSA {2} {3}' -f $name[$lv], $k.lab, $bits, ($why -join ' / ')) -ForegroundColor $col[$lv]
|
| 174 |
}
|
| 175 |
+
foreach ($x in $rows) { Write-Host $x }
|
| 176 |
+
Write-Host ((T ' 합계: 안전 {0}, 주의 {1}, 위험 {2}, 대상 아님 {3}' ' Total: safe {0}, caution {1}, danger {2}, not applicable {3}') -f $cnt[0], $cnt[1], $cnt[2], $rows.Count)
|
| 177 |
+
if (-not $open.Count) { Write-Host (T ' 열린 포트를 찾지 못했습니다. 안전 판정은 아닙니다.' ' No open port was found. This is not a Safe verdict.') }
|
| 178 |
+
if ($cnt[1] + $cnt[2]) { Write-Host (T ' 위험·주의 키: 사용을 멈추고 펌웨어를 갱신한 뒤 새 키를 만드십시오.' ' Danger or Caution: retire the key, update the firmware and generate a new key.') }
|
| 179 |
+
$dir = if ($PSScriptRoot) { $PSScriptRoot } else { (Get-Location).Path }
|
| 180 |
+
$path = if (-not $Out) { Join-Path $dir 'keyguard_keys.txt' } elseif ([IO.Path]::IsPathRooted($Out)) { $Out } else { Join-Path (Get-Location).Path $Out }
|
| 181 |
+
Write-Host ''
|
| 182 |
+
try {
|
| 183 |
+
[IO.File]::WriteAllText($path, (($lines -join "`n") -replace "`r", '') + "`n", (New-Object Text.UTF8Encoding($false)))
|
| 184 |
+
Write-Host ((T '공개키 파일: {0}' 'Public key file: {0}') -f $path)
|
| 185 |
+
} catch { Write-Host ((T '파일을 쓰지 못했습니다: {0}' 'Could not write the file: {0}') -f $_.Exception.Message) }
|
local/keyguard-local.py
CHANGED
|
@@ -1,17 +1,17 @@
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
# -*- coding: utf-8 -*-
|
| 3 |
-
"""KeyGuard Local:
|
| 4 |
|
| 5 |
python3 keyguard-local.py # scan the /24 of this computer (asks first)
|
| 6 |
python3 keyguard-local.py --hosts 192.168.0.1,192.168.0.20
|
| 7 |
python3 keyguard-local.py --ports 443,8443,22 --out keyguard_keys.txt
|
| 8 |
|
| 9 |
What it does: TCP connect, one TLS handshake per open port (and ssh-keyscan on port 22 when available).
|
| 10 |
-
What it never does: no login attempts, no private keys, no internet traffic, no upload. The file stays on this computer.
|
| 11 |
-
|
| 12 |
Use it only on networks and devices you own or are authorized to test. Standard library only. MIT License, VIDRAFT.
|
| 13 |
"""
|
| 14 |
-
import argparse, ipaddress, re, shutil, socket, ssl, subprocess, sys
|
| 15 |
from concurrent.futures import ThreadPoolExecutor
|
| 16 |
|
| 17 |
NETS = [ipaddress.ip_network(n) for n in ("10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "127.0.0.0/8")]
|
|
@@ -76,6 +76,116 @@ def ssh_rsa(ip, port):
|
|
| 76 |
return m.group(0) if m else None
|
| 77 |
|
| 78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
def main():
|
| 80 |
import warnings
|
| 81 |
warnings.simplefilter("ignore", DeprecationWarning) # TLS 1.0 is allowed on purpose: old devices are the target
|
|
@@ -83,7 +193,7 @@ def main():
|
|
| 83 |
p.add_argument("--hosts", help="comma separated private IPs instead of the whole /24")
|
| 84 |
p.add_argument("--subnet", help="private /24 or smaller, e.g. 192.168.0.0/24")
|
| 85 |
p.add_argument("--ports", default="443,8443,22")
|
| 86 |
-
p.add_argument("--out", default="keyguard_keys.txt")
|
| 87 |
p.add_argument("--yes", action="store_true", help="skip the question (you confirm that you are authorized)")
|
| 88 |
a = p.parse_args()
|
| 89 |
try:
|
|
@@ -104,22 +214,45 @@ def main():
|
|
| 104 |
print("Target: %s%s (%d addresses), ports %s" % (hosts[0], " to %s" % hosts[-1] if len(hosts) > 1 else "", len(hosts), ports))
|
| 105 |
if not a.yes:
|
| 106 |
print("Use this only on a network you own or are authorized to test.\n본인 소유이거나 점검 권한이 있는 네트워크에서만 사용하십시오.")
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
sys.exit("Stopped.")
|
| 109 |
with ThreadPoolExecutor(64) as ex:
|
| 110 |
found = [x for x in ex.map(is_open, [(str(h), q) for h in hosts for q in ports]) if x]
|
| 111 |
print("Open ports: %d" % len(found))
|
| 112 |
with ThreadPoolExecutor(16) as ex:
|
| 113 |
keys = list(ex.map(lambda x: ssh_rsa(*x) if x[1] == 22 else cert(*x), found))
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
|
| 125 |
if __name__ == "__main__":
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
# -*- coding: utf-8 -*-
|
| 3 |
+
"""KeyGuard Local: check the RSA PUBLIC keys of devices in your own private network and print the verdict.
|
| 4 |
|
| 5 |
python3 keyguard-local.py # scan the /24 of this computer (asks first)
|
| 6 |
python3 keyguard-local.py --hosts 192.168.0.1,192.168.0.20
|
| 7 |
python3 keyguard-local.py --ports 443,8443,22 --out keyguard_keys.txt
|
| 8 |
|
| 9 |
What it does: TCP connect, one TLS handshake per open port (and ssh-keyscan on port 22 when available).
|
| 10 |
+
What it never does: no login attempts, no private keys, no internet traffic, no upload. The verdict is computed here and the key file stays on this computer.
|
| 11 |
+
The same file can also be opened in the Self-check tab of https://huggingface.co/spaces/FINAL-Bench/KeyGuard (checked inside your browser).
|
| 12 |
Use it only on networks and devices you own or are authorized to test. Standard library only. MIT License, VIDRAFT.
|
| 13 |
"""
|
| 14 |
+
import argparse, base64, ipaddress, locale, math, os, re, shutil, socket, ssl, subprocess, sys
|
| 15 |
from concurrent.futures import ThreadPoolExecutor
|
| 16 |
|
| 17 |
NETS = [ipaddress.ip_network(n) for n in ("10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "127.0.0.0/8")]
|
|
|
|
| 76 |
return m.group(0) if m else None
|
| 77 |
|
| 78 |
|
| 79 |
+
KO = (os.environ.get("LANG") or (locale.getlocale()[0] or "")).lower().startswith(("ko", "korean"))
|
| 80 |
+
T = lambda ko, en: ko if KO else en
|
| 81 |
+
ROCA = (3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 151, 163, 167)
|
| 82 |
+
OID_RSA = bytes.fromhex("06092a864886f70d010101")
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def der_ints(b):
|
| 86 |
+
"""The first two INTEGERs of a DER SEQUENCE."""
|
| 87 |
+
def tl(i):
|
| 88 |
+
n = b[i + 1]
|
| 89 |
+
if n & 0x80:
|
| 90 |
+
k = n & 0x7F
|
| 91 |
+
return i + 2 + k, int.from_bytes(b[i + 2:i + 2 + k], "big")
|
| 92 |
+
return i + 2, n
|
| 93 |
+
i, _ = tl(0)
|
| 94 |
+
out = []
|
| 95 |
+
for _ in range(2):
|
| 96 |
+
if b[i] != 2:
|
| 97 |
+
return None
|
| 98 |
+
s, n = tl(i)
|
| 99 |
+
out.append(int.from_bytes(b[s:s + n], "big"))
|
| 100 |
+
i = s + n
|
| 101 |
+
return out
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def rsa_of(text):
|
| 105 |
+
"""(n, e) of an RSA certificate or ssh-rsa line, else None."""
|
| 106 |
+
try:
|
| 107 |
+
if text.startswith("ssh-rsa "):
|
| 108 |
+
b, f, i = base64.b64decode(text.split()[1]), [], 0
|
| 109 |
+
while i + 4 <= len(b) and len(f) < 3:
|
| 110 |
+
n = int.from_bytes(b[i:i + 4], "big")
|
| 111 |
+
f.append(b[i + 4:i + 4 + n])
|
| 112 |
+
i += 4 + n
|
| 113 |
+
return int.from_bytes(f[2], "big"), int.from_bytes(f[1], "big")
|
| 114 |
+
b = base64.b64decode("".join(text.splitlines()[1:-1]))
|
| 115 |
+
i = b.find(OID_RSA)
|
| 116 |
+
if i < 0:
|
| 117 |
+
return None
|
| 118 |
+
i += len(OID_RSA)
|
| 119 |
+
i += 2 if b[i:i + 2] == b"\x05\x00" else 0
|
| 120 |
+
if b[i] != 3:
|
| 121 |
+
return None
|
| 122 |
+
n = b[i + 1]
|
| 123 |
+
i = i + 2 + (n & 0x7F if n & 0x80 else 0)
|
| 124 |
+
v = der_ints(b[i + 1:])
|
| 125 |
+
return (v[0], v[1]) if v else None
|
| 126 |
+
except (ValueError, IndexError):
|
| 127 |
+
return None
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
def fermat(n, steps=2000):
|
| 131 |
+
if n % 2 == 0:
|
| 132 |
+
return 2
|
| 133 |
+
a = math.isqrt(n)
|
| 134 |
+
a += a * a < n
|
| 135 |
+
for _ in range(steps):
|
| 136 |
+
d = a * a - n
|
| 137 |
+
r = math.isqrt(d)
|
| 138 |
+
if r * r == d and a - r > 1:
|
| 139 |
+
return a - r
|
| 140 |
+
a += 1
|
| 141 |
+
return None
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
def roca(n):
|
| 145 |
+
for p in ROCA:
|
| 146 |
+
seen, x = set(), 1
|
| 147 |
+
for _ in range(1, p):
|
| 148 |
+
x = x * 65537 % p
|
| 149 |
+
seen.add(x)
|
| 150 |
+
if n % p and n % p not in seen:
|
| 151 |
+
return False
|
| 152 |
+
return True
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
def verdicts(keys):
|
| 156 |
+
"""keys: [(label, n, e)] -> [(label, bits, level, reasons)] level: 0 safe, 1 caution, 2 danger"""
|
| 157 |
+
shared = {}
|
| 158 |
+
for i in range(len(keys)):
|
| 159 |
+
for j in range(i):
|
| 160 |
+
g = math.gcd(keys[i][1], keys[j][1])
|
| 161 |
+
if g not in (1, keys[i][1], keys[j][1]):
|
| 162 |
+
shared.setdefault(i, []).append(keys[j][0])
|
| 163 |
+
shared.setdefault(j, []).append(keys[i][0])
|
| 164 |
+
out = []
|
| 165 |
+
for i, (lab, n, e) in enumerate(keys):
|
| 166 |
+
bits, lv, why = n.bit_length(), 0, []
|
| 167 |
+
if i in shared:
|
| 168 |
+
lv = 2
|
| 169 |
+
why.append(T("같은 소수를 쓰는 기기: ", "shares a prime with ") + ", ".join(shared[i]))
|
| 170 |
+
if bits <= 768:
|
| 171 |
+
lv = 2
|
| 172 |
+
why.append(T("짧은 키", "short key"))
|
| 173 |
+
elif bits < 2048:
|
| 174 |
+
lv = max(lv, 1)
|
| 175 |
+
why.append(T("2048비트 미만", "under 2048 bits"))
|
| 176 |
+
if e < 3 or e % 2 == 0:
|
| 177 |
+
lv = 2
|
| 178 |
+
why.append(T("비정상 지수", "abnormal exponent"))
|
| 179 |
+
if fermat(n):
|
| 180 |
+
lv = 2
|
| 181 |
+
why.append(T("두 소수가 너무 가까움", "primes too close"))
|
| 182 |
+
if bits >= 512 and roca(n):
|
| 183 |
+
lv = max(lv, 1)
|
| 184 |
+
why.append("ROCA CVE-2017-15361")
|
| 185 |
+
out.append((lab, bits, lv, why))
|
| 186 |
+
return out
|
| 187 |
+
|
| 188 |
+
|
| 189 |
def main():
|
| 190 |
import warnings
|
| 191 |
warnings.simplefilter("ignore", DeprecationWarning) # TLS 1.0 is allowed on purpose: old devices are the target
|
|
|
|
| 193 |
p.add_argument("--hosts", help="comma separated private IPs instead of the whole /24")
|
| 194 |
p.add_argument("--subnet", help="private /24 or smaller, e.g. 192.168.0.0/24")
|
| 195 |
p.add_argument("--ports", default="443,8443,22")
|
| 196 |
+
p.add_argument("--out", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "keyguard_keys.txt"))
|
| 197 |
p.add_argument("--yes", action="store_true", help="skip the question (you confirm that you are authorized)")
|
| 198 |
a = p.parse_args()
|
| 199 |
try:
|
|
|
|
| 214 |
print("Target: %s%s (%d addresses), ports %s" % (hosts[0], " to %s" % hosts[-1] if len(hosts) > 1 else "", len(hosts), ports))
|
| 215 |
if not a.yes:
|
| 216 |
print("Use this only on a network you own or are authorized to test.\n본인 소유이거나 점검 권한이 있는 네트워크에서만 사용하십시오.")
|
| 217 |
+
for _ in range(3):
|
| 218 |
+
q = input("Type YES to continue, NO to stop / 계속하려면 YES, 그만두려면 NO: ").strip().upper()
|
| 219 |
+
if q in ("YES", "Y", "NO", "N"):
|
| 220 |
+
break
|
| 221 |
+
if q not in ("YES", "Y"):
|
| 222 |
sys.exit("Stopped.")
|
| 223 |
with ThreadPoolExecutor(64) as ex:
|
| 224 |
found = [x for x in ex.map(is_open, [(str(h), q) for h in hosts for q in ports]) if x]
|
| 225 |
print("Open ports: %d" % len(found))
|
| 226 |
with ThreadPoolExecutor(16) as ex:
|
| 227 |
keys = list(ex.map(lambda x: ssh_rsa(*x) if x[1] == 22 else cert(*x), found))
|
| 228 |
+
got, rsa_keys, rows = [], [], []
|
| 229 |
+
for (ip, port), k in zip(found, keys):
|
| 230 |
+
lab = "%s:%d" % (ip, port)
|
| 231 |
+
if k:
|
| 232 |
+
got.append("# %s\n%s\n" % (lab, k))
|
| 233 |
+
v = rsa_of(k) if k else None
|
| 234 |
+
if v:
|
| 235 |
+
rsa_keys.append((lab,) + v)
|
| 236 |
+
else:
|
| 237 |
+
rows.append((lab, T("RSA 키가 아님 (점검 대상 아님)", "not an RSA key (not applicable)") if k else T("공개키를 주지 않음", "no public key offered")))
|
| 238 |
+
res = verdicts(rsa_keys)
|
| 239 |
+
name = (T("안전", "SAFE"), T("주의", "CAUTION"), T("위험", "DANGER"))
|
| 240 |
+
print("\n" + T("=== 점검 결과 ===", "=== RESULT ==="))
|
| 241 |
+
for lab, bits, lv, why in res:
|
| 242 |
+
print(" [%s] %s RSA %d %s" % (name[lv], lab, bits, " / ".join(why) or T("4대 결함 없음", "none of the four defects")))
|
| 243 |
+
for lab, why in rows:
|
| 244 |
+
print(" [-] %s %s" % (lab, why))
|
| 245 |
+
print(T(" 합계: 안전 %d, 주의 %d, 위험 %d, 대상 아님 %d", " Total: safe %d, caution %d, danger %d, not applicable %d") % (sum(r[2] == 0 for r in res), sum(r[2] == 1 for r in res), sum(r[2] == 2 for r in res), len(rows)))
|
| 246 |
+
if not found:
|
| 247 |
+
print(T(" 열린 포트를 찾지 못했습니다. 안전 판정은 아닙니다.", " No open port was found. This is not a Safe verdict."))
|
| 248 |
+
if any(r[2] for r in res):
|
| 249 |
+
print(T(" 위험·주의 키: 사용을 멈추고 펌웨어를 갱신한 뒤 새 키를 만드십시오.", " Danger or Caution: retire the key, update the firmware and generate a new key."))
|
| 250 |
+
try:
|
| 251 |
+
with open(a.out, "w", encoding="utf-8", newline="\n") as f:
|
| 252 |
+
f.write("# KeyGuard Local: public keys only\n" + "".join(got))
|
| 253 |
+
print(T("\n공개키 파일: %s", "\nPublic key file: %s") % a.out)
|
| 254 |
+
except OSError as e:
|
| 255 |
+
print(T("\n파일을 쓰지 못했습니다: %s", "\nCould not write the file: %s") % e)
|
| 256 |
|
| 257 |
|
| 258 |
if __name__ == "__main__":
|