keywarden-audit 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- keywarden_audit-0.1.1/PKG-INFO +17 -0
- keywarden_audit-0.1.1/keywarden/__init__.py +0 -0
- keywarden_audit-0.1.1/keywarden/app.py +27 -0
- keywarden_audit-0.1.1/keywarden/assets/icon.svg +29 -0
- keywarden_audit-0.1.1/keywarden/core/__init__.py +0 -0
- keywarden_audit-0.1.1/keywarden/core/audit.py +34 -0
- keywarden_audit-0.1.1/keywarden/core/demo.py +25 -0
- keywarden_audit-0.1.1/keywarden/core/hibp.py +62 -0
- keywarden_audit-0.1.1/keywarden/core/importers.py +70 -0
- keywarden_audit-0.1.1/keywarden/core/models.py +98 -0
- keywarden_audit-0.1.1/keywarden/core/report.py +82 -0
- keywarden_audit-0.1.1/keywarden/core/strength.py +45 -0
- keywarden_audit-0.1.1/keywarden/core/texts.py +110 -0
- keywarden_audit-0.1.1/keywarden/net/__init__.py +0 -0
- keywarden_audit-0.1.1/keywarden/net/hibp_client.py +75 -0
- keywarden_audit-0.1.1/keywarden/ui/__init__.py +0 -0
- keywarden_audit-0.1.1/keywarden/ui/main_window.py +260 -0
- keywarden_audit-0.1.1/keywarden_audit.egg-info/PKG-INFO +17 -0
- keywarden_audit-0.1.1/keywarden_audit.egg-info/SOURCES.txt +27 -0
- keywarden_audit-0.1.1/keywarden_audit.egg-info/dependency_links.txt +1 -0
- keywarden_audit-0.1.1/keywarden_audit.egg-info/entry_points.txt +2 -0
- keywarden_audit-0.1.1/keywarden_audit.egg-info/requires.txt +1 -0
- keywarden_audit-0.1.1/keywarden_audit.egg-info/top_level.txt +1 -0
- keywarden_audit-0.1.1/pyproject.toml +34 -0
- keywarden_audit-0.1.1/setup.cfg +4 -0
- keywarden_audit-0.1.1/tests/test_audit.py +52 -0
- keywarden_audit-0.1.1/tests/test_hibp.py +41 -0
- keywarden_audit-0.1.1/tests/test_importers.py +74 -0
- keywarden_audit-0.1.1/tests/test_report.py +41 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: keywarden-audit
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Local password-vault auditor: weak, reused and breached passwords
|
|
5
|
+
Author: BlackLotus Software
|
|
6
|
+
License-Expression: GPL-3.0-or-later
|
|
7
|
+
Project-URL: Homepage, https://gitlab.com/MMonteiro01/keywarden
|
|
8
|
+
Project-URL: Repository, https://gitlab.com/MMonteiro01/keywarden
|
|
9
|
+
Keywords: password,security,audit,breach,haveibeenpwned,privacy
|
|
10
|
+
Classifier: Environment :: X11 Applications :: Qt
|
|
11
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
12
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Topic :: Security
|
|
15
|
+
Requires-Python: >=3.11
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
Requires-Dist: PySide6
|
|
File without changes
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
"""Arranque da aplicação Keywarden."""
|
|
3
|
+
import sys
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from PySide6.QtGui import QIcon
|
|
6
|
+
from PySide6.QtWidgets import QApplication
|
|
7
|
+
|
|
8
|
+
from keywarden.ui.main_window import MainWindow
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
_ICON = Path(__file__).parent / "assets" / "icon.svg"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def main() -> None:
|
|
16
|
+
app = QApplication(sys.argv)
|
|
17
|
+
app.setApplicationName("Keywarden")
|
|
18
|
+
if _ICON.exists():
|
|
19
|
+
app.setWindowIcon(QIcon(str(_ICON)))
|
|
20
|
+
window = MainWindow()
|
|
21
|
+
window.show()
|
|
22
|
+
sys.exit(app.exec())
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
if __name__ == "__main__":
|
|
27
|
+
main()
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="512" height="512">
|
|
2
|
+
<defs>
|
|
3
|
+
<linearGradient id="bg" x1="0" y1="0" x2="0" y2="1">
|
|
4
|
+
<stop offset="0" stop-color="#19222b"/>
|
|
5
|
+
<stop offset="1" stop-color="#0b1015"/>
|
|
6
|
+
</linearGradient>
|
|
7
|
+
<linearGradient id="teal" x1="0" y1="0" x2="1" y2="1">
|
|
8
|
+
<stop offset="0" stop-color="#a6e7bd"/>
|
|
9
|
+
<stop offset="1" stop-color="#36bd8f"/>
|
|
10
|
+
</linearGradient>
|
|
11
|
+
</defs>
|
|
12
|
+
|
|
13
|
+
<!-- badge -->
|
|
14
|
+
<rect x="16" y="16" width="480" height="480" rx="112" fill="url(#bg)"/>
|
|
15
|
+
<rect x="16" y="16" width="480" height="480" rx="112" fill="none" stroke="#2b3a46" stroke-width="3"/>
|
|
16
|
+
|
|
17
|
+
<!-- escudo -->
|
|
18
|
+
<path d="M256 96
|
|
19
|
+
L392 146
|
|
20
|
+
L392 268
|
|
21
|
+
C392 352 332 404 256 430
|
|
22
|
+
C180 404 120 352 120 268
|
|
23
|
+
L120 146 Z"
|
|
24
|
+
fill="none" stroke="url(#teal)" stroke-width="26" stroke-linejoin="round"/>
|
|
25
|
+
|
|
26
|
+
<!-- buraco de fechadura -->
|
|
27
|
+
<circle cx="256" cy="238" r="34" fill="url(#teal)"/>
|
|
28
|
+
<path d="M242 262 L270 262 L282 332 L230 332 Z" fill="url(#teal)"/>
|
|
29
|
+
</svg>
|
|
File without changes
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
"""Auditoria offline do cofre: robustez + reutilização. Puro, sem rede.
|
|
3
|
+
|
|
4
|
+
A verificação de fugas (HIBP) é feita à parte e preenche o breach_count
|
|
5
|
+
depois; esta camada trata de tudo o que não precisa de internet.
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from collections import defaultdict
|
|
10
|
+
|
|
11
|
+
from . import strength
|
|
12
|
+
from .models import AuditReport, Entry, EntryAudit
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def audit(entries: list[Entry]) -> AuditReport:
|
|
16
|
+
"""Produz o relatório offline (fracas + reutilizadas)."""
|
|
17
|
+
# Mapeia cada password aos títulos das entradas que a usam.
|
|
18
|
+
users_by_pw: dict[str, list[str]] = defaultdict(list)
|
|
19
|
+
for e in entries:
|
|
20
|
+
users_by_pw[e.password].append(e.title)
|
|
21
|
+
|
|
22
|
+
audits: list[EntryAudit] = []
|
|
23
|
+
for e in entries:
|
|
24
|
+
others = [t for t in users_by_pw[e.password] if t != e.title]
|
|
25
|
+
audits.append(EntryAudit(
|
|
26
|
+
entry=e,
|
|
27
|
+
length=len(e.password),
|
|
28
|
+
classes=strength.char_classes(e.password),
|
|
29
|
+
is_common=strength.is_common(e.password),
|
|
30
|
+
only_digits=e.password.isdigit(),
|
|
31
|
+
weak_reasons=strength.weak_reasons(e.password),
|
|
32
|
+
reused_with=others,
|
|
33
|
+
))
|
|
34
|
+
return AuditReport(audits=audits)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
"""Cofre de exemplo, para experimentar a app sem o cofre real. Formato Proton Pass."""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from .models import Entry
|
|
6
|
+
|
|
7
|
+
_DEMO_CSV = (
|
|
8
|
+
"name,url,username,password,note,totp,vault\n"
|
|
9
|
+
"Gmail,https://gmail.com,me@proton.me,123456,,,Pessoal\n"
|
|
10
|
+
"Twitter,https://twitter.com,blacklotus,123456,,,Pessoal\n"
|
|
11
|
+
"GitHub,https://github.com,blacklotus,benfica,,,Trabalho\n"
|
|
12
|
+
"Banco,https://banco.pt,joao,Zx9#mK2$pL,,,Pessoal\n"
|
|
13
|
+
"Reddit,https://reddit.com,me,qwerty,,,Pessoal\n"
|
|
14
|
+
"Netflix,https://netflix.com,me@proton.me,password1,,,Pessoal\n"
|
|
15
|
+
"Fórum,https://forum.exemplo.pt,blacklotus,123456,,,Pessoal\n"
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def demo_csv_text() -> str:
|
|
20
|
+
return _DEMO_CSV
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def demo_entries() -> list[Entry]:
|
|
24
|
+
from .importers import import_csv_text
|
|
25
|
+
return import_csv_text(_DEMO_CSV)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
"""Verificação de fugas via Have I Been Pwned, com k-anonymity. Funções puras.
|
|
3
|
+
|
|
4
|
+
Modelo de privacidade (o ponto central desta app):
|
|
5
|
+
1. Faz-se SHA-1 da password -> 40 caracteres hexadecimais.
|
|
6
|
+
2. Enviam-se à API só os PRIMEIROS 5 caracteres desse hash (o "prefixo").
|
|
7
|
+
3. A API devolve todos os sufixos conhecidos que começam por esse prefixo,
|
|
8
|
+
cada um com o número de vezes que apareceu em fugas.
|
|
9
|
+
4. A correspondência é feita LOCALMENTE: procuramos o nosso sufixo na lista.
|
|
10
|
+
|
|
11
|
+
A password — e até o hash completo — nunca saem do computador. A API só vê
|
|
12
|
+
5 caracteres, partilhados por milhares de passwords diferentes.
|
|
13
|
+
|
|
14
|
+
Este módulo não toca na rede. A chamada HTTP está em net/hibp_client.py;
|
|
15
|
+
aqui ficam só as partes puras, testáveis sem internet.
|
|
16
|
+
"""
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import hashlib
|
|
20
|
+
|
|
21
|
+
RANGE_URL = "https://api.pwnedpasswords.com/range/{prefix}"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def sha1_hex(password: str) -> str:
|
|
25
|
+
"""SHA-1 da password em hexadecimal maiúsculo (40 caracteres)."""
|
|
26
|
+
return hashlib.sha1(password.encode("utf-8")).hexdigest().upper()
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def prefix_suffix(password: str) -> tuple[str, str]:
|
|
30
|
+
"""Divide o hash em (prefixo de 5, sufixo de 35). O prefixo é o que se envia."""
|
|
31
|
+
h = sha1_hex(password)
|
|
32
|
+
return h[:5], h[5:]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def range_url(password: str) -> str:
|
|
36
|
+
"""URL a consultar para esta password (contém só o prefixo)."""
|
|
37
|
+
return RANGE_URL.format(prefix=prefix_suffix(password)[0])
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def count_in_response(response_text: str, suffix: str) -> int:
|
|
41
|
+
"""Procura o sufixo na resposta da API. Devolve o nº de fugas (0 = não encontrado).
|
|
42
|
+
|
|
43
|
+
A resposta tem uma linha por sufixo, no formato SUFIXO:CONTAGEM
|
|
44
|
+
(as linhas podem vir separadas por \\r\\n).
|
|
45
|
+
"""
|
|
46
|
+
target = suffix.upper()
|
|
47
|
+
for line in response_text.splitlines():
|
|
48
|
+
line = line.strip()
|
|
49
|
+
if not line or ":" not in line:
|
|
50
|
+
continue
|
|
51
|
+
suf, _, count = line.partition(":")
|
|
52
|
+
if suf.strip().upper() == target:
|
|
53
|
+
try:
|
|
54
|
+
return int(count.strip())
|
|
55
|
+
except ValueError:
|
|
56
|
+
return 0
|
|
57
|
+
return 0
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def breach_count(password: str, response_text: str) -> int:
|
|
61
|
+
"""Conveniência: dado o texto da resposta ao prefixo, devolve a contagem."""
|
|
62
|
+
return count_in_response(response_text, prefix_suffix(password)[1])
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
"""Importação de cofres a partir de CSV. Deteta o formato e normaliza.
|
|
3
|
+
|
|
4
|
+
Cada gestor/browser exporta com nomes de colunas diferentes; em vez de um
|
|
5
|
+
parser por formato, reconhecemos as colunas pelo nome (tolerante a maiúsculas
|
|
6
|
+
e a variações). Entradas sem password são ignoradas (ex.: notas seguras).
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import csv
|
|
11
|
+
import io
|
|
12
|
+
from urllib.parse import urlparse
|
|
13
|
+
|
|
14
|
+
from .models import Entry
|
|
15
|
+
|
|
16
|
+
# Nomes de coluna possíveis para cada campo (em minúsculas), por ordem de preferência.
|
|
17
|
+
_PASSWORD_KEYS = ("password", "login_password", "pwd", "senha")
|
|
18
|
+
_USERNAME_KEYS = ("username", "login_username", "user", "login name", "login", "email", "utilizador")
|
|
19
|
+
_TITLE_KEYS = ("name", "title", "account", "nome", "título", "titulo")
|
|
20
|
+
_URL_KEYS = ("url", "login_uri", "uri", "website", "site", "web site", "formactionorigin")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _pick(row: dict[str, str], keys: tuple[str, ...]) -> str:
|
|
24
|
+
"""Primeiro valor não-vazio entre as colunas candidatas."""
|
|
25
|
+
for k in keys:
|
|
26
|
+
v = row.get(k)
|
|
27
|
+
if v and v.strip():
|
|
28
|
+
return v.strip()
|
|
29
|
+
return ""
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _domain(url: str) -> str:
|
|
33
|
+
"""Extrai um título legível a partir de um URL (o host, sem www.)."""
|
|
34
|
+
if not url:
|
|
35
|
+
return ""
|
|
36
|
+
u = url if "://" in url else "https://" + url
|
|
37
|
+
host = urlparse(u).netloc or url
|
|
38
|
+
return host[4:] if host.startswith("www.") else host
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def import_csv_text(text: str) -> list[Entry]:
|
|
42
|
+
"""Converte o conteúdo de um CSV numa lista de Entry."""
|
|
43
|
+
# Remove BOM e deteta o delimitador (vírgula ou ponto-e-vírgula).
|
|
44
|
+
text = text.lstrip("")
|
|
45
|
+
sample = text[:2048]
|
|
46
|
+
delim = ";" if sample.count(";") > sample.count(",") else ","
|
|
47
|
+
|
|
48
|
+
reader = csv.DictReader(io.StringIO(text), delimiter=delim)
|
|
49
|
+
if not reader.fieldnames:
|
|
50
|
+
return []
|
|
51
|
+
# Normaliza os nomes das colunas (minúsculas, sem espaços à volta).
|
|
52
|
+
norm = {name: (name or "").strip().lower() for name in reader.fieldnames}
|
|
53
|
+
|
|
54
|
+
entries: list[Entry] = []
|
|
55
|
+
for raw in reader:
|
|
56
|
+
row = {norm.get(k, k): (v or "") for k, v in raw.items()}
|
|
57
|
+
password = _pick(row, _PASSWORD_KEYS)
|
|
58
|
+
if not password:
|
|
59
|
+
continue # sem password não há o que auditar
|
|
60
|
+
url = _pick(row, _URL_KEYS)
|
|
61
|
+
title = _pick(row, _TITLE_KEYS) or _domain(url) or "(sem título)"
|
|
62
|
+
username = _pick(row, _USERNAME_KEYS)
|
|
63
|
+
entries.append(Entry(title=title, username=username, password=password, url=url))
|
|
64
|
+
return entries
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def import_csv(path: str) -> list[Entry]:
|
|
68
|
+
"""Lê um ficheiro CSV e normaliza-o."""
|
|
69
|
+
with open(path, encoding="utf-8", errors="replace") as f:
|
|
70
|
+
return import_csv_text(f.read())
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
"""Modelos de domínio — Python puro, sem Qt nem rede. Testável na consola."""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from enum import Enum
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Severity(str, Enum):
|
|
10
|
+
"""Gravidade de uma entrada auditada, da mais alta para a mais baixa."""
|
|
11
|
+
COMPROMISED = "compromised" # apareceu em fugas conhecidas
|
|
12
|
+
REUSED = "reused" # a mesma password noutras entradas
|
|
13
|
+
WEAK = "weak" # curta / comum / pouca variedade
|
|
14
|
+
OK = "ok" # sem problemas detetados
|
|
15
|
+
|
|
16
|
+
@property
|
|
17
|
+
def weight(self) -> int:
|
|
18
|
+
return {
|
|
19
|
+
Severity.COMPROMISED: 3,
|
|
20
|
+
Severity.REUSED: 2,
|
|
21
|
+
Severity.WEAK: 1,
|
|
22
|
+
Severity.OK: 0,
|
|
23
|
+
}[self]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@dataclass
|
|
27
|
+
class Entry:
|
|
28
|
+
"""Uma entrada do cofre, tal como importada. Só dados."""
|
|
29
|
+
title: str
|
|
30
|
+
username: str
|
|
31
|
+
password: str
|
|
32
|
+
url: str = ""
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@dataclass
|
|
36
|
+
class EntryAudit:
|
|
37
|
+
"""Resultado da auditoria a uma entrada."""
|
|
38
|
+
entry: Entry
|
|
39
|
+
length: int
|
|
40
|
+
classes: int # nº de classes de caracteres (1..4)
|
|
41
|
+
is_common: bool
|
|
42
|
+
only_digits: bool
|
|
43
|
+
weak_reasons: list[str] = field(default_factory=list)
|
|
44
|
+
reused_with: list[str] = field(default_factory=list) # títulos que partilham a password
|
|
45
|
+
breach_count: int | None = None # None = não verificado; 0 = não encontrada; >0 = nº de fugas
|
|
46
|
+
|
|
47
|
+
@property
|
|
48
|
+
def is_reused(self) -> bool:
|
|
49
|
+
return bool(self.reused_with)
|
|
50
|
+
|
|
51
|
+
@property
|
|
52
|
+
def is_weak(self) -> bool:
|
|
53
|
+
return bool(self.weak_reasons)
|
|
54
|
+
|
|
55
|
+
@property
|
|
56
|
+
def is_compromised(self) -> bool:
|
|
57
|
+
return bool(self.breach_count)
|
|
58
|
+
|
|
59
|
+
@property
|
|
60
|
+
def severity(self) -> Severity:
|
|
61
|
+
"""A pior condição manda. Comprometida > reutilizada > fraca > ok."""
|
|
62
|
+
if self.is_compromised:
|
|
63
|
+
return Severity.COMPROMISED
|
|
64
|
+
if self.is_reused:
|
|
65
|
+
return Severity.REUSED
|
|
66
|
+
if self.is_weak:
|
|
67
|
+
return Severity.WEAK
|
|
68
|
+
return Severity.OK
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@dataclass
|
|
72
|
+
class AuditReport:
|
|
73
|
+
"""Resultado agregado da auditoria ao cofre inteiro."""
|
|
74
|
+
audits: list[EntryAudit] = field(default_factory=list)
|
|
75
|
+
|
|
76
|
+
@property
|
|
77
|
+
def total(self) -> int:
|
|
78
|
+
return len(self.audits)
|
|
79
|
+
|
|
80
|
+
@property
|
|
81
|
+
def compromised(self) -> int:
|
|
82
|
+
return sum(1 for a in self.audits if a.is_compromised)
|
|
83
|
+
|
|
84
|
+
@property
|
|
85
|
+
def reused(self) -> int:
|
|
86
|
+
return sum(1 for a in self.audits if a.is_reused)
|
|
87
|
+
|
|
88
|
+
@property
|
|
89
|
+
def weak(self) -> int:
|
|
90
|
+
return sum(1 for a in self.audits if a.is_weak)
|
|
91
|
+
|
|
92
|
+
@property
|
|
93
|
+
def ok(self) -> int:
|
|
94
|
+
return sum(1 for a in self.audits if a.severity is Severity.OK)
|
|
95
|
+
|
|
96
|
+
def by_severity(self) -> list[EntryAudit]:
|
|
97
|
+
"""Ordena da entrada mais arriscada para a menos arriscada."""
|
|
98
|
+
return sorted(self.audits, key=lambda a: a.severity.weight, reverse=True)
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
"""Relatório da auditoria em Markdown. NUNCA inclui as palavras-passe em claro."""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
|
|
7
|
+
from . import texts
|
|
8
|
+
from .models import AuditReport, Severity
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _reasons(keys: list[str]) -> str:
|
|
12
|
+
return "; ".join(texts.t(k) for k in keys)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def build_markdown(report: AuditReport, source: str = "",
|
|
16
|
+
when: datetime | None = None) -> str:
|
|
17
|
+
when = when or datetime.now()
|
|
18
|
+
out: list[str] = [texts.t("rep_title"), ""]
|
|
19
|
+
out.append(texts.t("rep_date", when=f"{when:%Y-%m-%d %H:%M}"))
|
|
20
|
+
if source:
|
|
21
|
+
out.append(texts.t("rep_source", src=source))
|
|
22
|
+
out.append("")
|
|
23
|
+
|
|
24
|
+
# Resumo
|
|
25
|
+
out.append(texts.t("rep_summary"))
|
|
26
|
+
out.append("")
|
|
27
|
+
out.append("- " + texts.t("sum_total", n=report.total))
|
|
28
|
+
out.append("- " + texts.t("sum_compromised", n=report.compromised))
|
|
29
|
+
out.append("- " + texts.t("sum_reused", n=report.reused))
|
|
30
|
+
out.append("- " + texts.t("sum_weak", n=report.weak))
|
|
31
|
+
out.append("- " + texts.t("sum_ok", n=report.ok))
|
|
32
|
+
out.append("")
|
|
33
|
+
|
|
34
|
+
# Comprometidas (prioridade máxima)
|
|
35
|
+
out.append(texts.t("rep_compromised_h"))
|
|
36
|
+
out.append("")
|
|
37
|
+
comp = [a for a in report.audits if a.is_compromised]
|
|
38
|
+
if comp:
|
|
39
|
+
for a in sorted(comp, key=lambda x: x.breach_count or 0, reverse=True):
|
|
40
|
+
out.append(texts.t("rep_compromised_line",
|
|
41
|
+
site=a.entry.title,
|
|
42
|
+
user=a.entry.username or texts.t("no_user"),
|
|
43
|
+
n=a.breach_count))
|
|
44
|
+
else:
|
|
45
|
+
out.append(texts.t("rep_none"))
|
|
46
|
+
out.append("")
|
|
47
|
+
|
|
48
|
+
# Reutilizadas (agrupadas por password, sem a mostrar)
|
|
49
|
+
out.append(texts.t("rep_reused_h"))
|
|
50
|
+
out.append("")
|
|
51
|
+
seen_groups: set[frozenset[str]] = set()
|
|
52
|
+
reused_any = False
|
|
53
|
+
for a in report.audits:
|
|
54
|
+
if not a.is_reused:
|
|
55
|
+
continue
|
|
56
|
+
group = frozenset([a.entry.title, *a.reused_with])
|
|
57
|
+
if group in seen_groups:
|
|
58
|
+
continue
|
|
59
|
+
seen_groups.add(group)
|
|
60
|
+
reused_any = True
|
|
61
|
+
out.append(texts.t("rep_reused_line", sites=", ".join(sorted(group))))
|
|
62
|
+
if not reused_any:
|
|
63
|
+
out.append(texts.t("rep_none"))
|
|
64
|
+
out.append("")
|
|
65
|
+
|
|
66
|
+
# Fracas
|
|
67
|
+
out.append(texts.t("rep_weak_h"))
|
|
68
|
+
out.append("")
|
|
69
|
+
weak = [a for a in report.audits if a.is_weak]
|
|
70
|
+
if weak:
|
|
71
|
+
for a in weak:
|
|
72
|
+
out.append(texts.t("rep_weak_line",
|
|
73
|
+
site=a.entry.title,
|
|
74
|
+
user=a.entry.username or texts.t("no_user"),
|
|
75
|
+
reasons=_reasons(a.weak_reasons)))
|
|
76
|
+
else:
|
|
77
|
+
out.append(texts.t("rep_none"))
|
|
78
|
+
out.append("")
|
|
79
|
+
|
|
80
|
+
out.append("---")
|
|
81
|
+
out.append(texts.t("rep_footer"))
|
|
82
|
+
return "\n".join(out)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
"""Análise de robustez de uma password (offline). Funções puras."""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
|
|
7
|
+
# Amostra curta das passwords mais comuns (sinalizador, não dicionário).
|
|
8
|
+
_TOP_COMMON = {
|
|
9
|
+
"123456", "password", "123456789", "12345678", "12345", "qwerty",
|
|
10
|
+
"1234567", "111111", "123123", "abc123", "1234567890", "000000",
|
|
11
|
+
"iloveyou", "admin", "password1", "qwerty123", "senha", "benfica",
|
|
12
|
+
"sporting", "porto", "123321", "666666", "123qwe", "dragon", "monkey",
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def char_classes(pw: str) -> int:
|
|
17
|
+
"""Número de classes de caracteres presentes (minúsc./maiúsc./dígito/símbolo)."""
|
|
18
|
+
classes = 0
|
|
19
|
+
if re.search(r"[a-z]", pw):
|
|
20
|
+
classes += 1
|
|
21
|
+
if re.search(r"[A-Z]", pw):
|
|
22
|
+
classes += 1
|
|
23
|
+
if re.search(r"[0-9]", pw):
|
|
24
|
+
classes += 1
|
|
25
|
+
if re.search(r"[^a-zA-Z0-9]", pw):
|
|
26
|
+
classes += 1
|
|
27
|
+
return classes
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def is_common(pw: str) -> bool:
|
|
31
|
+
return pw.lower() in _TOP_COMMON
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def weak_reasons(pw: str) -> list[str]:
|
|
35
|
+
"""Devolve CHAVES de texto (traduzíveis) para os motivos de fraqueza."""
|
|
36
|
+
reasons: list[str] = []
|
|
37
|
+
if is_common(pw):
|
|
38
|
+
reasons.append("reason_common")
|
|
39
|
+
if len(pw) < 8:
|
|
40
|
+
reasons.append("reason_short")
|
|
41
|
+
if pw.isdigit():
|
|
42
|
+
reasons.append("reason_digits")
|
|
43
|
+
if char_classes(pw) <= 1 and not pw.isdigit():
|
|
44
|
+
reasons.append("reason_one_class")
|
|
45
|
+
return reasons
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
"""Textos da interface em EN (por omissão) e PT-PT. Centralizados e testáveis."""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
DEFAULT_LANG = "en"
|
|
6
|
+
_LANGS = ("en", "pt")
|
|
7
|
+
_lang = DEFAULT_LANG
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def set_lang(lang: str) -> None:
|
|
11
|
+
global _lang
|
|
12
|
+
_lang = lang if lang in _LANGS else DEFAULT_LANG
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def get_lang() -> str:
|
|
16
|
+
return _lang
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def t(key: str, **kwargs) -> str:
|
|
20
|
+
entry = STRINGS.get(key)
|
|
21
|
+
if entry is None:
|
|
22
|
+
return key
|
|
23
|
+
text = entry.get(_lang) or entry.get(DEFAULT_LANG) or key
|
|
24
|
+
return text.format(**kwargs) if kwargs else text
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
STRINGS: dict[str, dict[str, str]] = {
|
|
28
|
+
# ---- idioma --------------------------------------------------------------
|
|
29
|
+
"lang_label": {"en": "Language:", "pt": "Idioma:"},
|
|
30
|
+
"lang_en": {"en": "English", "pt": "Inglês"},
|
|
31
|
+
"lang_pt": {"en": "Portuguese", "pt": "Português"},
|
|
32
|
+
|
|
33
|
+
# ---- botões / topo -------------------------------------------------------
|
|
34
|
+
"import_btn": {"en": "Import CSV…", "pt": "Importar CSV…"},
|
|
35
|
+
"demo_btn": {"en": "Try with demo data", "pt": "Experimentar com dados de exemplo"},
|
|
36
|
+
"check_btn": {"en": "Check for breaches (online)", "pt": "Verificar fugas (online)"},
|
|
37
|
+
"report_btn": {"en": "Export report…", "pt": "Exportar relatório…"},
|
|
38
|
+
"dlg_choose_csv": {"en": "Choose exported CSV", "pt": "Escolher CSV exportado"},
|
|
39
|
+
"dlg_import_error": {"en": "Could not import", "pt": "Não foi possível importar"},
|
|
40
|
+
"import_empty": {"en": "No entries with a password were found in that file.",
|
|
41
|
+
"pt": "Não foram encontradas entradas com password nesse ficheiro."},
|
|
42
|
+
"imported_n": {"en": "Imported {n} entries.", "pt": "Importadas {n} entradas."},
|
|
43
|
+
|
|
44
|
+
# ---- nota de privacidade -------------------------------------------------
|
|
45
|
+
"privacy_note": {
|
|
46
|
+
"en": "Everything runs locally. The breach check never sends your passwords: "
|
|
47
|
+
"it uses k-anonymity — only the first 5 characters of a hash leave your computer.",
|
|
48
|
+
"pt": "Tudo corre localmente. A verificação de fugas nunca envia as tuas passwords: "
|
|
49
|
+
"usa k-anonymity — só os primeiros 5 caracteres de um hash saem do teu computador.",
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
# ---- tabela --------------------------------------------------------------
|
|
53
|
+
"col_site": {"en": "Site", "pt": "Site"},
|
|
54
|
+
"col_user": {"en": "Username", "pt": "Utilizador"},
|
|
55
|
+
"col_status": {"en": "Status", "pt": "Estado"},
|
|
56
|
+
"col_breaches": {"en": "Breaches", "pt": "Fugas"},
|
|
57
|
+
"no_user": {"en": "(no username)", "pt": "(sem utilizador)"},
|
|
58
|
+
"placeholder": {"en": "Import a CSV export, or try the demo data.",
|
|
59
|
+
"pt": "Importa uma exportação CSV, ou experimenta os dados de exemplo."},
|
|
60
|
+
|
|
61
|
+
# ---- severidades ---------------------------------------------------------
|
|
62
|
+
"sev_compromised": {"en": "Compromised", "pt": "Comprometida"},
|
|
63
|
+
"sev_reused": {"en": "Reused", "pt": "Reutilizada"},
|
|
64
|
+
"sev_weak": {"en": "Weak", "pt": "Fraca"},
|
|
65
|
+
"sev_ok": {"en": "OK", "pt": "OK"},
|
|
66
|
+
|
|
67
|
+
# ---- motivos de fraqueza (chaves vindas do strength.py) ------------------
|
|
68
|
+
"reason_common": {"en": "among the most used passwords",
|
|
69
|
+
"pt": "está entre as passwords mais usadas"},
|
|
70
|
+
"reason_short": {"en": "fewer than 8 characters", "pt": "tem menos de 8 caracteres"},
|
|
71
|
+
"reason_digits": {"en": "digits only", "pt": "é só dígitos"},
|
|
72
|
+
"reason_one_class": {"en": "a single character type", "pt": "usa só um tipo de caractere"},
|
|
73
|
+
|
|
74
|
+
# ---- progresso da verificação -------------------------------------------
|
|
75
|
+
"checking": {"en": "Checking {done}/{total}…", "pt": "A verificar {done}/{total}…"},
|
|
76
|
+
"check_done": {"en": "Breach check complete.", "pt": "Verificação de fugas concluída."},
|
|
77
|
+
"check_offline": {"en": "Could not reach the breach database (are you online?).",
|
|
78
|
+
"pt": "Não foi possível contactar a base de fugas (estás online?)."},
|
|
79
|
+
|
|
80
|
+
# ---- resumo --------------------------------------------------------------
|
|
81
|
+
"sum_total": {"en": "Entries: {n}", "pt": "Entradas: {n}"},
|
|
82
|
+
"sum_compromised": {"en": "Compromised: {n}", "pt": "Comprometidas: {n}"},
|
|
83
|
+
"sum_reused": {"en": "Reused: {n}", "pt": "Reutilizadas: {n}"},
|
|
84
|
+
"sum_weak": {"en": "Weak: {n}", "pt": "Fracas: {n}"},
|
|
85
|
+
"sum_ok": {"en": "Looking good: {n}", "pt": "Sem problemas: {n}"},
|
|
86
|
+
|
|
87
|
+
# ---- relatório -----------------------------------------------------------
|
|
88
|
+
"rep_title": {"en": "# Password vault audit — Keywarden",
|
|
89
|
+
"pt": "# Auditoria do cofre de palavras-passe — Keywarden"},
|
|
90
|
+
"rep_date": {"en": "**Date:** {when}", "pt": "**Data:** {when}"},
|
|
91
|
+
"rep_source": {"en": "**Source:** {src}", "pt": "**Origem:** {src}"},
|
|
92
|
+
"rep_summary": {"en": "## Summary", "pt": "## Resumo"},
|
|
93
|
+
"rep_compromised_h": {"en": "## Compromised passwords (change these first)",
|
|
94
|
+
"pt": "## Palavras-passe comprometidas (muda estas primeiro)"},
|
|
95
|
+
"rep_compromised_line": {"en": "- **{site}** ({user}) — seen in breaches {n} times",
|
|
96
|
+
"pt": "- **{site}** ({user}) — vista em fugas {n} vezes"},
|
|
97
|
+
"rep_reused_h": {"en": "## Reused passwords", "pt": "## Palavras-passe reutilizadas"},
|
|
98
|
+
"rep_reused_line": {"en": "- The same password is used on: {sites}",
|
|
99
|
+
"pt": "- A mesma password é usada em: {sites}"},
|
|
100
|
+
"rep_weak_h": {"en": "## Weak passwords", "pt": "## Palavras-passe fracas"},
|
|
101
|
+
"rep_weak_line": {"en": "- **{site}** ({user}) — {reasons}",
|
|
102
|
+
"pt": "- **{site}** ({user}) — {reasons}"},
|
|
103
|
+
"rep_none": {"en": "_None found._", "pt": "_Nenhuma encontrada._"},
|
|
104
|
+
"rep_footer": {
|
|
105
|
+
"en": "_Generated by Keywarden. Your passwords are not stored in this report. "
|
|
106
|
+
"Audit your own vault only._",
|
|
107
|
+
"pt": "_Gerado pelo Keywarden. As tuas passwords não ficam guardadas neste relatório. "
|
|
108
|
+
"Audita apenas o teu próprio cofre._",
|
|
109
|
+
},
|
|
110
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
"""Chamada ao Have I Been Pwned via QNetworkAccessManager (assíncrono).
|
|
3
|
+
|
|
4
|
+
A ÚNICA peça que toca na rede. Usa as funções puras de core.hibp e envia
|
|
5
|
+
apenas o prefixo de 5 caracteres (k-anonymity). Pede ainda 'Add-Padding' ao
|
|
6
|
+
HIBP, que enche a resposta com entradas falsas para o tamanho não revelar nada.
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from PySide6.QtCore import QObject, QUrl, Signal
|
|
11
|
+
from PySide6.QtNetwork import QNetworkAccessManager, QNetworkReply, QNetworkRequest
|
|
12
|
+
|
|
13
|
+
from ..core import hibp
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class BreachChecker(QObject):
|
|
17
|
+
progress = Signal(int, int) # concluídos, total
|
|
18
|
+
result = Signal(str, int) # password, nº de fugas (0 = não encontrada)
|
|
19
|
+
finished = Signal()
|
|
20
|
+
error = Signal(str) # emitido uma vez se algum pedido falhou
|
|
21
|
+
|
|
22
|
+
def __init__(self, max_concurrent: int = 4, parent=None):
|
|
23
|
+
super().__init__(parent)
|
|
24
|
+
self._nam = QNetworkAccessManager(self)
|
|
25
|
+
self._max = max_concurrent
|
|
26
|
+
self._queue: list[str] = []
|
|
27
|
+
self._inflight = 0
|
|
28
|
+
self._done = 0
|
|
29
|
+
self._total = 0
|
|
30
|
+
self._had_error = False
|
|
31
|
+
|
|
32
|
+
def check(self, passwords: list[str]) -> None:
|
|
33
|
+
"""Verifica a lista de passwords (deduplicada). Emite result por cada uma."""
|
|
34
|
+
uniq = sorted({p for p in passwords if p})
|
|
35
|
+
self._queue = uniq
|
|
36
|
+
self._total = len(uniq)
|
|
37
|
+
self._done = 0
|
|
38
|
+
self._inflight = 0
|
|
39
|
+
self._had_error = False
|
|
40
|
+
if not uniq:
|
|
41
|
+
self.finished.emit()
|
|
42
|
+
return
|
|
43
|
+
for _ in range(min(self._max, len(uniq))):
|
|
44
|
+
self._start_next()
|
|
45
|
+
|
|
46
|
+
def _start_next(self) -> None:
|
|
47
|
+
if not self._queue:
|
|
48
|
+
return
|
|
49
|
+
pw = self._queue.pop(0)
|
|
50
|
+
req = QNetworkRequest(QUrl(hibp.range_url(pw)))
|
|
51
|
+
req.setHeader(QNetworkRequest.UserAgentHeader, "Keywarden")
|
|
52
|
+
req.setRawHeader(b"Add-Padding", b"true") # privacidade: resposta de tamanho uniforme
|
|
53
|
+
reply = self._nam.get(req)
|
|
54
|
+
reply.setProperty("pw", pw)
|
|
55
|
+
reply.finished.connect(lambda r=reply: self._on_reply(r))
|
|
56
|
+
self._inflight += 1
|
|
57
|
+
|
|
58
|
+
def _on_reply(self, reply: QNetworkReply) -> None:
|
|
59
|
+
pw = reply.property("pw")
|
|
60
|
+
if reply.error() == QNetworkReply.NoError:
|
|
61
|
+
text = bytes(reply.readAll()).decode(errors="replace")
|
|
62
|
+
self.result.emit(pw, hibp.breach_count(pw, text))
|
|
63
|
+
else:
|
|
64
|
+
self._had_error = True
|
|
65
|
+
reply.deleteLater()
|
|
66
|
+
self._inflight -= 1
|
|
67
|
+
self._done += 1
|
|
68
|
+
self.progress.emit(self._done, self._total)
|
|
69
|
+
|
|
70
|
+
if self._queue:
|
|
71
|
+
self._start_next()
|
|
72
|
+
elif self._inflight == 0:
|
|
73
|
+
if self._had_error:
|
|
74
|
+
self.error.emit("network")
|
|
75
|
+
self.finished.emit()
|
|
File without changes
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
"""Janela principal do Keywarden. Importar → auditar → verificar fugas → relatório.
|
|
3
|
+
|
|
4
|
+
Bilingue (EN/PT). As palavras-passe vivem só em memória e nunca vão para o
|
|
5
|
+
relatório; a verificação de fugas usa k-anonymity (ver net/hibp_client).
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from datetime import datetime
|
|
10
|
+
|
|
11
|
+
from PySide6.QtGui import QColor
|
|
12
|
+
from PySide6.QtWidgets import (
|
|
13
|
+
QMainWindow, QWidget, QVBoxLayout, QHBoxLayout, QPushButton, QLabel,
|
|
14
|
+
QComboBox, QTableWidget, QTableWidgetItem, QHeaderView, QProgressBar,
|
|
15
|
+
QFileDialog, QMessageBox,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
from ..core import demo, report, texts
|
|
19
|
+
from ..core.audit import audit
|
|
20
|
+
from ..core.importers import import_csv
|
|
21
|
+
from ..core.models import AuditReport, EntryAudit, Severity
|
|
22
|
+
from ..core.texts import t
|
|
23
|
+
from ..net.hibp_client import BreachChecker
|
|
24
|
+
|
|
25
|
+
# Cores por severidade (coerentes em tema escuro).
|
|
26
|
+
_SEV_COLOR = {
|
|
27
|
+
Severity.COMPROMISED: "#e06c75", # vermelho
|
|
28
|
+
Severity.REUSED: "#e5a06a", # laranja
|
|
29
|
+
Severity.WEAK: "#e0cf6a", # amarelo
|
|
30
|
+
Severity.OK: "#8fd19e", # verde
|
|
31
|
+
}
|
|
32
|
+
_SEV_KEY = {
|
|
33
|
+
Severity.COMPROMISED: "sev_compromised",
|
|
34
|
+
Severity.REUSED: "sev_reused",
|
|
35
|
+
Severity.WEAK: "sev_weak",
|
|
36
|
+
Severity.OK: "sev_ok",
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class MainWindow(QMainWindow):
|
|
41
|
+
def __init__(self):
|
|
42
|
+
super().__init__()
|
|
43
|
+
self.setWindowTitle("Keywarden")
|
|
44
|
+
self.resize(820, 640)
|
|
45
|
+
self._report: AuditReport = AuditReport()
|
|
46
|
+
self._source = ""
|
|
47
|
+
self._checker: BreachChecker | None = None
|
|
48
|
+
self._build_ui()
|
|
49
|
+
self._retranslate()
|
|
50
|
+
|
|
51
|
+
# ================================================================ UI
|
|
52
|
+
def _build_ui(self) -> None:
|
|
53
|
+
central = QWidget()
|
|
54
|
+
self.setCentralWidget(central)
|
|
55
|
+
root = QVBoxLayout(central)
|
|
56
|
+
|
|
57
|
+
# Barra de topo
|
|
58
|
+
top = QHBoxLayout()
|
|
59
|
+
self.lbl_lang = QLabel()
|
|
60
|
+
self.cmb_lang = QComboBox()
|
|
61
|
+
self.cmb_lang.addItem("", "en")
|
|
62
|
+
self.cmb_lang.addItem("", "pt")
|
|
63
|
+
self.cmb_lang.currentIndexChanged.connect(self._on_lang_changed)
|
|
64
|
+
self.btn_import = QPushButton()
|
|
65
|
+
self.btn_demo = QPushButton()
|
|
66
|
+
top.addWidget(self.lbl_lang)
|
|
67
|
+
top.addWidget(self.cmb_lang)
|
|
68
|
+
top.addStretch()
|
|
69
|
+
top.addWidget(self.btn_import)
|
|
70
|
+
top.addWidget(self.btn_demo)
|
|
71
|
+
root.addLayout(top)
|
|
72
|
+
|
|
73
|
+
# Nota de privacidade
|
|
74
|
+
self.lbl_privacy = QLabel()
|
|
75
|
+
self.lbl_privacy.setWordWrap(True)
|
|
76
|
+
self.lbl_privacy.setStyleSheet("color: #8fd19e;")
|
|
77
|
+
root.addWidget(self.lbl_privacy)
|
|
78
|
+
|
|
79
|
+
# Resumo
|
|
80
|
+
self.lbl_summary = QLabel("—")
|
|
81
|
+
self.lbl_summary.setWordWrap(True)
|
|
82
|
+
root.addWidget(self.lbl_summary)
|
|
83
|
+
|
|
84
|
+
# Tabela
|
|
85
|
+
self.table = QTableWidget(0, 4)
|
|
86
|
+
self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
|
|
87
|
+
self.table.setEditTriggers(QTableWidget.NoEditTriggers)
|
|
88
|
+
self.table.setSelectionBehavior(QTableWidget.SelectRows)
|
|
89
|
+
root.addWidget(self.table, 1)
|
|
90
|
+
|
|
91
|
+
# Verificação de fugas
|
|
92
|
+
check_row = QHBoxLayout()
|
|
93
|
+
self.btn_check = QPushButton()
|
|
94
|
+
self.btn_check.setEnabled(False)
|
|
95
|
+
self.bar = QProgressBar()
|
|
96
|
+
self.bar.setRange(0, 100)
|
|
97
|
+
self.lbl_check = QLabel("")
|
|
98
|
+
check_row.addWidget(self.btn_check)
|
|
99
|
+
check_row.addWidget(self.bar, 1)
|
|
100
|
+
check_row.addWidget(self.lbl_check)
|
|
101
|
+
root.addLayout(check_row)
|
|
102
|
+
|
|
103
|
+
# Relatório
|
|
104
|
+
bottom = QHBoxLayout()
|
|
105
|
+
self.btn_report = QPushButton()
|
|
106
|
+
self.btn_report.setEnabled(False)
|
|
107
|
+
bottom.addStretch()
|
|
108
|
+
bottom.addWidget(self.btn_report)
|
|
109
|
+
root.addLayout(bottom)
|
|
110
|
+
|
|
111
|
+
self.btn_import.clicked.connect(self._on_import)
|
|
112
|
+
self.btn_demo.clicked.connect(self._on_demo)
|
|
113
|
+
self.btn_check.clicked.connect(self._on_check)
|
|
114
|
+
self.btn_report.clicked.connect(self._on_report)
|
|
115
|
+
|
|
116
|
+
# ============================================================ i18n
|
|
117
|
+
def _retranslate(self) -> None:
|
|
118
|
+
self.lbl_lang.setText(t("lang_label"))
|
|
119
|
+
self.cmb_lang.setItemText(0, t("lang_en"))
|
|
120
|
+
self.cmb_lang.setItemText(1, t("lang_pt"))
|
|
121
|
+
self.btn_import.setText(t("import_btn"))
|
|
122
|
+
self.btn_demo.setText(t("demo_btn"))
|
|
123
|
+
self.btn_check.setText(t("check_btn"))
|
|
124
|
+
self.btn_report.setText(t("report_btn"))
|
|
125
|
+
self.lbl_privacy.setText(t("privacy_note"))
|
|
126
|
+
self.table.setHorizontalHeaderLabels(
|
|
127
|
+
[t("col_site"), t("col_user"), t("col_status"), t("col_breaches")])
|
|
128
|
+
if self._report.total:
|
|
129
|
+
self._refresh()
|
|
130
|
+
else:
|
|
131
|
+
self.lbl_summary.setText(t("placeholder"))
|
|
132
|
+
|
|
133
|
+
def _on_lang_changed(self) -> None:
|
|
134
|
+
texts.set_lang(self.cmb_lang.currentData())
|
|
135
|
+
self._retranslate()
|
|
136
|
+
|
|
137
|
+
# ============================================================ ações
|
|
138
|
+
def _on_import(self) -> None:
|
|
139
|
+
path, _ = QFileDialog.getOpenFileName(
|
|
140
|
+
self, t("dlg_choose_csv"), "", "CSV (*.csv);;*")
|
|
141
|
+
if not path:
|
|
142
|
+
return
|
|
143
|
+
try:
|
|
144
|
+
entries = import_csv(path)
|
|
145
|
+
except OSError as e:
|
|
146
|
+
QMessageBox.critical(self, t("dlg_import_error"), str(e))
|
|
147
|
+
return
|
|
148
|
+
if not entries:
|
|
149
|
+
QMessageBox.warning(self, t("dlg_import_error"), t("import_empty"))
|
|
150
|
+
return
|
|
151
|
+
self._source = path.rsplit("/", 1)[-1]
|
|
152
|
+
self._load(entries)
|
|
153
|
+
|
|
154
|
+
def _on_demo(self) -> None:
|
|
155
|
+
self._source = "demo"
|
|
156
|
+
self._load(demo.demo_entries())
|
|
157
|
+
|
|
158
|
+
def _load(self, entries) -> None:
|
|
159
|
+
self._report = audit(entries)
|
|
160
|
+
self.bar.setValue(0)
|
|
161
|
+
self.lbl_check.setText("")
|
|
162
|
+
self.btn_check.setEnabled(True)
|
|
163
|
+
self.btn_report.setEnabled(True)
|
|
164
|
+
self._refresh()
|
|
165
|
+
|
|
166
|
+
def _refresh(self) -> None:
|
|
167
|
+
audits = self._report.by_severity()
|
|
168
|
+
self.table.setRowCount(0)
|
|
169
|
+
for a in audits:
|
|
170
|
+
self._add_row(a)
|
|
171
|
+
r = self._report
|
|
172
|
+
self.lbl_summary.setText(" ".join([
|
|
173
|
+
t("sum_total", n=r.total),
|
|
174
|
+
t("sum_compromised", n=r.compromised),
|
|
175
|
+
t("sum_reused", n=r.reused),
|
|
176
|
+
t("sum_weak", n=r.weak),
|
|
177
|
+
t("sum_ok", n=r.ok),
|
|
178
|
+
]))
|
|
179
|
+
|
|
180
|
+
def _add_row(self, a: EntryAudit) -> None:
|
|
181
|
+
row = self.table.rowCount()
|
|
182
|
+
self.table.insertRow(row)
|
|
183
|
+
color = QColor(_SEV_COLOR[a.severity])
|
|
184
|
+
site = QTableWidgetItem(a.entry.title)
|
|
185
|
+
user = QTableWidgetItem(a.entry.username or t("no_user"))
|
|
186
|
+
status = QTableWidgetItem(t(_SEV_KEY[a.severity]))
|
|
187
|
+
status.setForeground(color)
|
|
188
|
+
breaches = QTableWidgetItem(
|
|
189
|
+
"—" if a.breach_count is None else str(a.breach_count))
|
|
190
|
+
# dica com os motivos, quando fraca
|
|
191
|
+
if a.weak_reasons:
|
|
192
|
+
status.setToolTip("; ".join(t(k) for k in a.weak_reasons))
|
|
193
|
+
for col, item in enumerate((site, user, status, breaches)):
|
|
194
|
+
self.table.setItem(row, col, item)
|
|
195
|
+
|
|
196
|
+
# ---------------------------------------------------- verificação
|
|
197
|
+
def _on_check(self) -> None:
|
|
198
|
+
passwords = [a.entry.password for a in self._report.audits]
|
|
199
|
+
self.btn_check.setEnabled(False)
|
|
200
|
+
self.btn_import.setEnabled(False)
|
|
201
|
+
self.bar.setValue(0)
|
|
202
|
+
self._checker = BreachChecker()
|
|
203
|
+
self._checker.progress.connect(self._on_progress)
|
|
204
|
+
self._checker.result.connect(self._on_breach_result)
|
|
205
|
+
self._checker.error.connect(self._on_check_error)
|
|
206
|
+
self._checker.finished.connect(self._on_check_finished)
|
|
207
|
+
self._checker.check(passwords)
|
|
208
|
+
|
|
209
|
+
def _on_progress(self, done: int, total: int) -> None:
|
|
210
|
+
self.bar.setValue(int(done / total * 100) if total else 100)
|
|
211
|
+
self.lbl_check.setText(t("checking", done=done, total=total))
|
|
212
|
+
|
|
213
|
+
def _on_breach_result(self, password: str, count: int) -> None:
|
|
214
|
+
# aplica a contagem a todas as entradas com esta password
|
|
215
|
+
for a in self._report.audits:
|
|
216
|
+
if a.entry.password == password:
|
|
217
|
+
a.breach_count = count
|
|
218
|
+
self._refresh()
|
|
219
|
+
|
|
220
|
+
def _on_check_error(self, _kind: str) -> None:
|
|
221
|
+
self.lbl_check.setText(t("check_offline"))
|
|
222
|
+
|
|
223
|
+
def _on_check_finished(self) -> None:
|
|
224
|
+
self.bar.setValue(100)
|
|
225
|
+
self.btn_check.setEnabled(True)
|
|
226
|
+
self.btn_import.setEnabled(True)
|
|
227
|
+
if not self.lbl_check.text().startswith(t("check_offline")[:10]):
|
|
228
|
+
self.lbl_check.setText(t("check_done"))
|
|
229
|
+
self._refresh()
|
|
230
|
+
|
|
231
|
+
# -------------------------------------------------------- relatório
|
|
232
|
+
def _on_report(self) -> None:
|
|
233
|
+
md = report.build_markdown(self._report, source=self._source,
|
|
234
|
+
when=datetime.now())
|
|
235
|
+
path, selected = QFileDialog.getSaveFileName(
|
|
236
|
+
self, t("report_btn"), "keywarden-report.md",
|
|
237
|
+
"Markdown (*.md);;Text (*.txt);;PDF (*.pdf)")
|
|
238
|
+
if not path:
|
|
239
|
+
return
|
|
240
|
+
try:
|
|
241
|
+
if path.lower().endswith(".pdf") or "pdf" in selected.lower():
|
|
242
|
+
if not path.lower().endswith(".pdf"):
|
|
243
|
+
path += ".pdf"
|
|
244
|
+
self._write_pdf(md, path)
|
|
245
|
+
else:
|
|
246
|
+
with open(path, "w", encoding="utf-8") as f:
|
|
247
|
+
f.write(md)
|
|
248
|
+
except OSError as e:
|
|
249
|
+
QMessageBox.critical(self, t("dlg_import_error"), str(e))
|
|
250
|
+
|
|
251
|
+
@staticmethod
|
|
252
|
+
def _write_pdf(markdown_text: str, path: str) -> None:
|
|
253
|
+
from PySide6.QtGui import QTextDocument
|
|
254
|
+
from PySide6.QtPrintSupport import QPrinter
|
|
255
|
+
doc = QTextDocument()
|
|
256
|
+
doc.setMarkdown(markdown_text)
|
|
257
|
+
printer = QPrinter(QPrinter.PrinterResolution)
|
|
258
|
+
printer.setOutputFormat(QPrinter.PdfFormat)
|
|
259
|
+
printer.setOutputFileName(path)
|
|
260
|
+
doc.print_(printer)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: keywarden-audit
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Local password-vault auditor: weak, reused and breached passwords
|
|
5
|
+
Author: BlackLotus Software
|
|
6
|
+
License-Expression: GPL-3.0-or-later
|
|
7
|
+
Project-URL: Homepage, https://gitlab.com/MMonteiro01/keywarden
|
|
8
|
+
Project-URL: Repository, https://gitlab.com/MMonteiro01/keywarden
|
|
9
|
+
Keywords: password,security,audit,breach,haveibeenpwned,privacy
|
|
10
|
+
Classifier: Environment :: X11 Applications :: Qt
|
|
11
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
12
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Topic :: Security
|
|
15
|
+
Requires-Python: >=3.11
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
Requires-Dist: PySide6
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
pyproject.toml
|
|
2
|
+
keywarden/__init__.py
|
|
3
|
+
keywarden/app.py
|
|
4
|
+
keywarden/assets/icon.svg
|
|
5
|
+
keywarden/core/__init__.py
|
|
6
|
+
keywarden/core/audit.py
|
|
7
|
+
keywarden/core/demo.py
|
|
8
|
+
keywarden/core/hibp.py
|
|
9
|
+
keywarden/core/importers.py
|
|
10
|
+
keywarden/core/models.py
|
|
11
|
+
keywarden/core/report.py
|
|
12
|
+
keywarden/core/strength.py
|
|
13
|
+
keywarden/core/texts.py
|
|
14
|
+
keywarden/net/__init__.py
|
|
15
|
+
keywarden/net/hibp_client.py
|
|
16
|
+
keywarden/ui/__init__.py
|
|
17
|
+
keywarden/ui/main_window.py
|
|
18
|
+
keywarden_audit.egg-info/PKG-INFO
|
|
19
|
+
keywarden_audit.egg-info/SOURCES.txt
|
|
20
|
+
keywarden_audit.egg-info/dependency_links.txt
|
|
21
|
+
keywarden_audit.egg-info/entry_points.txt
|
|
22
|
+
keywarden_audit.egg-info/requires.txt
|
|
23
|
+
keywarden_audit.egg-info/top_level.txt
|
|
24
|
+
tests/test_audit.py
|
|
25
|
+
tests/test_hibp.py
|
|
26
|
+
tests/test_importers.py
|
|
27
|
+
tests/test_report.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
PySide6
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
keywarden
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "keywarden-audit"
|
|
3
|
+
version = "0.1.1"
|
|
4
|
+
description = "Local password-vault auditor: weak, reused and breached passwords"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.11"
|
|
7
|
+
license = "GPL-3.0-or-later"
|
|
8
|
+
authors = [{ name = "BlackLotus Software" }]
|
|
9
|
+
keywords = ["password", "security", "audit", "breach", "haveibeenpwned", "privacy"]
|
|
10
|
+
classifiers = [
|
|
11
|
+
"Environment :: X11 Applications :: Qt",
|
|
12
|
+
"Intended Audience :: End Users/Desktop",
|
|
13
|
+
"Operating System :: POSIX :: Linux",
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"Topic :: Security",
|
|
16
|
+
]
|
|
17
|
+
dependencies = ["PySide6"]
|
|
18
|
+
|
|
19
|
+
[project.urls]
|
|
20
|
+
Homepage = "https://gitlab.com/MMonteiro01/keywarden"
|
|
21
|
+
Repository = "https://gitlab.com/MMonteiro01/keywarden"
|
|
22
|
+
|
|
23
|
+
[project.scripts]
|
|
24
|
+
keywarden = "keywarden.app:main"
|
|
25
|
+
|
|
26
|
+
[build-system]
|
|
27
|
+
requires = ["setuptools>=77"]
|
|
28
|
+
build-backend = "setuptools.build_meta"
|
|
29
|
+
|
|
30
|
+
[tool.setuptools.packages.find]
|
|
31
|
+
include = ["keywarden*"]
|
|
32
|
+
|
|
33
|
+
[tool.setuptools.package-data]
|
|
34
|
+
keywarden = ["assets/*.svg", "assets/*.png"]
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
from keywarden.core.audit import audit
|
|
3
|
+
from keywarden.core.models import Entry, Severity
|
|
4
|
+
from keywarden.core import strength
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def _e(title, pw, user="me"):
|
|
8
|
+
return Entry(title=title, username=user, password=pw)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def test_fraca_comum():
|
|
12
|
+
r = strength.weak_reasons("123456")
|
|
13
|
+
assert "reason_common" in r
|
|
14
|
+
assert "reason_short" in r
|
|
15
|
+
assert "reason_digits" in r
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def test_forte_sem_razoes():
|
|
19
|
+
assert strength.weak_reasons("Tr0ub4dour&3x!") == []
|
|
20
|
+
assert strength.char_classes("Tr0ub4dour&3x!") == 4
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def test_reutilizacao_detetada():
|
|
24
|
+
rep = audit([_e("Gmail", "benfica"), _e("Twitter", "benfica"), _e("Banco", "Zx9#mK2$pL")])
|
|
25
|
+
by_title = {a.entry.title: a for a in rep.audits}
|
|
26
|
+
assert set(by_title["Gmail"].reused_with) == {"Twitter"}
|
|
27
|
+
assert by_title["Banco"].reused_with == []
|
|
28
|
+
assert by_title["Gmail"].is_reused
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def test_severidade_prioriza_pior():
|
|
32
|
+
rep = audit([_e("A", "123456")]) # fraca
|
|
33
|
+
a = rep.audits[0]
|
|
34
|
+
assert a.severity is Severity.WEAK
|
|
35
|
+
a.breach_count = 42 # agora comprometida
|
|
36
|
+
assert a.severity is Severity.COMPROMISED # a pior condição manda
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def test_relatorio_agregado():
|
|
40
|
+
rep = audit([_e("A", "123456"), _e("B", "123456"), _e("C", "Zx9#mK2$pL")])
|
|
41
|
+
assert rep.total == 3
|
|
42
|
+
assert rep.weak == 2 # os dois 123456
|
|
43
|
+
assert rep.reused == 2 # 123456 partilhado por A e B
|
|
44
|
+
# ordenação por severidade: as arriscadas primeiro
|
|
45
|
+
ordem = [a.entry.title for a in rep.by_severity()]
|
|
46
|
+
assert ordem[-1] == "C" # a forte e única fica por último
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def test_vazio():
|
|
50
|
+
rep = audit([])
|
|
51
|
+
assert rep.total == 0
|
|
52
|
+
assert rep.by_severity() == []
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
from keywarden.core import hibp
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def test_sha1_e_prefixo():
|
|
6
|
+
# "password" tem um SHA-1 conhecido e fixo.
|
|
7
|
+
assert hibp.sha1_hex("password") == "5BAA61E4C9B93F3F0682250B6CF8331B7EE68FD8"
|
|
8
|
+
prefix, suffix = hibp.prefix_suffix("password")
|
|
9
|
+
assert prefix == "5BAA6"
|
|
10
|
+
assert suffix == "1E4C9B93F3F0682250B6CF8331B7EE68FD8"
|
|
11
|
+
assert len(prefix) == 5 and len(suffix) == 35
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def test_url_so_tem_o_prefixo():
|
|
15
|
+
url = hibp.range_url("password")
|
|
16
|
+
assert url.endswith("/5BAA6")
|
|
17
|
+
# garantia de privacidade: o sufixo NUNCA aparece no URL
|
|
18
|
+
assert "1E4C9B93F3F0682250B6CF8331B7EE68FD8" not in url
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def test_contagem_encontrada():
|
|
22
|
+
# resposta simulada da API (formato SUFIXO:CONTAGEM, com \r\n)
|
|
23
|
+
suffix = "1E4C9B93F3F0682250B6CF8331B7EE68FD8"
|
|
24
|
+
resp = f"003D68EB55068C33ACE09247EE4C639306B:3\r\n{suffix}:200000\r\nZZZ:1\r\n"
|
|
25
|
+
assert hibp.count_in_response(resp, suffix) == 200000
|
|
26
|
+
assert hibp.breach_count("password", resp) == 200000
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def test_contagem_nao_encontrada():
|
|
30
|
+
resp = "003D68EB55068C33ACE09247EE4C639306B:3\r\nABCDEF:1\r\n"
|
|
31
|
+
assert hibp.breach_count("Zx9#mK2$pL", resp) == 0
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_resposta_vazia():
|
|
35
|
+
assert hibp.count_in_response("", "ABC") == 0
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def test_case_insensitive():
|
|
39
|
+
# a API devolve maiúsculas; a comparação não deve depender disso
|
|
40
|
+
resp = "aabbccddeeff00112233445566778899aabb:5\n"
|
|
41
|
+
assert hibp.count_in_response(resp, "AABBCCDDEEFF00112233445566778899AABB") == 5
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
from keywarden.core.importers import import_csv_text
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def test_chrome_edge():
|
|
6
|
+
csv_text = (
|
|
7
|
+
"name,url,username,password,note\n"
|
|
8
|
+
"Gmail,https://accounts.google.com,me@gmail.com,s3cr3t,\n"
|
|
9
|
+
"Twitter,https://twitter.com,me,hunter2,\n"
|
|
10
|
+
)
|
|
11
|
+
e = import_csv_text(csv_text)
|
|
12
|
+
assert len(e) == 2
|
|
13
|
+
assert e[0].title == "Gmail"
|
|
14
|
+
assert e[0].username == "me@gmail.com"
|
|
15
|
+
assert e[0].password == "s3cr3t"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def test_firefox_sem_titulo_usa_dominio():
|
|
19
|
+
csv_text = (
|
|
20
|
+
"url,username,password,httpRealm,formActionOrigin,guid\n"
|
|
21
|
+
"https://www.reddit.com,user1,p4ss,,,{abc}\n"
|
|
22
|
+
)
|
|
23
|
+
e = import_csv_text(csv_text)
|
|
24
|
+
assert len(e) == 1
|
|
25
|
+
assert e[0].title == "reddit.com" # derivado do URL (sem www.)
|
|
26
|
+
assert e[0].password == "p4ss"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def test_bitwarden_ignora_notas_sem_password():
|
|
30
|
+
csv_text = (
|
|
31
|
+
"folder,favorite,type,name,login_uri,login_username,login_password\n"
|
|
32
|
+
"Pessoal,,login,Banco,https://banco.pt,joao,Zx9#mK2\n"
|
|
33
|
+
"Pessoal,,note,Wifi de casa,,,\n" # nota: sem login_password → ignorada
|
|
34
|
+
)
|
|
35
|
+
e = import_csv_text(csv_text)
|
|
36
|
+
assert len(e) == 1
|
|
37
|
+
assert e[0].title == "Banco"
|
|
38
|
+
assert e[0].password == "Zx9#mK2"
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_keepass_com_aspas_e_delimitador_virgula():
|
|
42
|
+
csv_text = (
|
|
43
|
+
'"Group","Title","Username","Password","URL","Notes"\n'
|
|
44
|
+
'"Root","Email","ana","p@ss,com,virgula","https://mail.pt",""\n'
|
|
45
|
+
)
|
|
46
|
+
e = import_csv_text(csv_text)
|
|
47
|
+
assert len(e) == 1
|
|
48
|
+
assert e[0].title == "Email"
|
|
49
|
+
assert e[0].password == "p@ss,com,virgula" # vírgula dentro de aspas preservada
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def test_delimitador_ponto_e_virgula():
|
|
53
|
+
csv_text = "name;username;password\nSite;u;pw123\n"
|
|
54
|
+
e = import_csv_text(csv_text)
|
|
55
|
+
assert len(e) == 1
|
|
56
|
+
assert e[0].password == "pw123"
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def test_csv_vazio_ou_sem_passwords():
|
|
60
|
+
assert import_csv_text("") == []
|
|
61
|
+
assert import_csv_text("foo,bar\n1,2\n") == [] # sem coluna de password
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def test_proton_pass():
|
|
65
|
+
csv_text = (
|
|
66
|
+
"name,url,username,password,note,totp,vault\n"
|
|
67
|
+
"GitHub,https://github.com,blacklotus,Zx9#mK2$pL,,,Pessoal\n"
|
|
68
|
+
"Gmail,https://gmail.com,me@proton.me,benfica,,,Pessoal\n"
|
|
69
|
+
)
|
|
70
|
+
e = import_csv_text(csv_text)
|
|
71
|
+
assert len(e) == 2
|
|
72
|
+
assert e[0].title == "GitHub"
|
|
73
|
+
assert e[1].username == "me@proton.me"
|
|
74
|
+
assert e[0].password == "Zx9#mK2$pL"
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
from datetime import datetime
|
|
3
|
+
|
|
4
|
+
from keywarden.core import texts
|
|
5
|
+
from keywarden.core.audit import audit
|
|
6
|
+
from keywarden.core.models import Entry
|
|
7
|
+
from keywarden.core.report import build_markdown
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _e(title, pw, user="me"):
|
|
11
|
+
return Entry(title=title, username=user, password=pw)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def test_relatorio_tem_seccoes_e_nao_mostra_passwords():
|
|
15
|
+
rep = audit([_e("Gmail", "123456"), _e("Twitter", "123456"), _e("Banco", "x")])
|
|
16
|
+
rep.audits[0].breach_count = 5000 # Gmail comprometida
|
|
17
|
+
md = build_markdown(rep, source="firefox.csv", when=datetime(2026, 11, 25, 10, 0))
|
|
18
|
+
|
|
19
|
+
assert texts.t("rep_title") in md
|
|
20
|
+
assert "2026-11-25 10:00" in md
|
|
21
|
+
assert "firefox.csv" in md
|
|
22
|
+
# as passwords em claro NUNCA aparecem no relatório
|
|
23
|
+
assert "123456" not in md
|
|
24
|
+
# mas os sites e vereditos sim
|
|
25
|
+
assert "Gmail" in md and "Twitter" in md
|
|
26
|
+
assert texts.t("rep_compromised_h") in md
|
|
27
|
+
assert texts.t("rep_reused_h") in md
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def test_grupo_de_reutilizacao_aparece_uma_vez():
|
|
31
|
+
rep = audit([_e("A", "benfica"), _e("B", "benfica"), _e("C", "benfica")])
|
|
32
|
+
md = build_markdown(rep)
|
|
33
|
+
# o grupo {A,B,C} deve aparecer uma só vez, não uma por entrada
|
|
34
|
+
assert md.count("A, B, C") == 1
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def test_relatorio_sem_problemas():
|
|
38
|
+
rep = audit([_e("Forte", "Tr0ub4dour&3x!")])
|
|
39
|
+
md = build_markdown(rep)
|
|
40
|
+
# sem comprometidas, sem reutilizadas, sem fracas -> "Nenhuma" em cada secção
|
|
41
|
+
assert md.count(texts.t("rep_none")) == 3
|