Add setup_fingerprint_check/src/setup_fingerprint_check/core.py
This commit is contained in:
commit
8b0abb99cc
1 changed files with 57 additions and 0 deletions
57
setup_fingerprint_check/src/setup_fingerprint_check/core.py
Normal file
57
setup_fingerprint_check/src/setup_fingerprint_check/core.py
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
import hashlib
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import platform
|
||||||
|
from typing import Dict
|
||||||
|
|
||||||
|
|
||||||
|
def _collect_system_info() -> Dict[str, str]:
|
||||||
|
"""Sammelt relevante Systeminformationen zur Fingerprint-Bildung."""
|
||||||
|
info = {
|
||||||
|
"platform": platform.system(),
|
||||||
|
"platform_release": platform.release(),
|
||||||
|
"platform_version": platform.version(),
|
||||||
|
"python_version": platform.python_version(),
|
||||||
|
"executable": sys.executable,
|
||||||
|
"uname": str(os.uname()) if hasattr(os, 'uname') else 'N/A',
|
||||||
|
}
|
||||||
|
return info
|
||||||
|
|
||||||
|
|
||||||
|
def _generate_fingerprint(info: Dict[str, str]) -> str:
|
||||||
|
"""Generiert einen SHA256-Fingerprint basierend auf Systeminformationen."""
|
||||||
|
fingerprint_source = "|".join(f"{k}={v}" for k, v in sorted(info.items()))
|
||||||
|
return hashlib.sha256(fingerprint_source.encode('utf-8')).hexdigest()
|
||||||
|
|
||||||
|
|
||||||
|
def check_setup_fingerprint(expected_fingerprint: str) -> bool:
|
||||||
|
"""Vergleicht den aktuellen Setup-Fingerprint mit dem erwarteten Fingerprint.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
expected_fingerprint (str): Referenzwert des erwarteten Setup-Fingerprints.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: True, wenn der aktuelle Fingerprint mit dem erwarteten übereinstimmt, sonst False.
|
||||||
|
"""
|
||||||
|
if not isinstance(expected_fingerprint, str):
|
||||||
|
raise TypeError("expected_fingerprint muss ein String sein.")
|
||||||
|
if not expected_fingerprint.strip():
|
||||||
|
raise ValueError("expected_fingerprint darf nicht leer sein.")
|
||||||
|
|
||||||
|
current_info = _collect_system_info()
|
||||||
|
current_fingerprint = _generate_fingerprint(current_info)
|
||||||
|
|
||||||
|
match = current_fingerprint == expected_fingerprint.strip()
|
||||||
|
return match
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description="Überprüfung des Setup-Fingerprints.")
|
||||||
|
parser.add_argument("--expected", required=True, help="Erwarteter Fingerprint des Test-Setups.")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
result = check_setup_fingerprint(args.expected)
|
||||||
|
sys.stdout.write("valid\n" if result else "mismatch\n")
|
||||||
|
sys.exit(0 if result else 1)
|
||||||
Loading…
Reference in a new issue