mirror of
https://github.com/bunny-lab-io/Borealis.git
synced 2025-12-16 03:25:48 -07:00
Fix agent keystore initialization order
This commit is contained in:
@@ -125,6 +125,24 @@ def _agent_guid_path() -> str:
|
||||
return os.path.abspath(os.path.join(os.path.dirname(__file__), 'agent_GUID'))
|
||||
|
||||
|
||||
def _settings_dir():
|
||||
try:
|
||||
return os.path.join(_find_project_root(), 'Agent', 'Borealis', 'Settings')
|
||||
except Exception:
|
||||
return os.path.abspath(os.path.join(os.path.dirname(__file__), 'Settings'))
|
||||
|
||||
|
||||
_KEY_STORE_INSTANCE = None
|
||||
|
||||
|
||||
def _key_store() -> AgentKeyStore:
|
||||
global _KEY_STORE_INSTANCE
|
||||
if _KEY_STORE_INSTANCE is None:
|
||||
scope = 'SYSTEM' if SYSTEM_SERVICE_MODE else 'CURRENTUSER'
|
||||
_KEY_STORE_INSTANCE = AgentKeyStore(_settings_dir(), scope=scope)
|
||||
return _KEY_STORE_INSTANCE
|
||||
|
||||
|
||||
def _persist_agent_guid_local(guid: str):
|
||||
guid = _normalize_agent_guid(guid)
|
||||
if not guid:
|
||||
@@ -1029,23 +1047,6 @@ def _collect_heartbeat_metrics() -> Dict[str, Any]:
|
||||
|
||||
|
||||
def _settings_dir():
|
||||
try:
|
||||
return os.path.join(_find_project_root(), 'Agent', 'Borealis', 'Settings')
|
||||
except Exception:
|
||||
return os.path.abspath(os.path.join(os.path.dirname(__file__), 'Settings'))
|
||||
|
||||
|
||||
_KEY_STORE_INSTANCE = None
|
||||
|
||||
|
||||
def _key_store() -> AgentKeyStore:
|
||||
global _KEY_STORE_INSTANCE
|
||||
if _KEY_STORE_INSTANCE is None:
|
||||
scope = 'SYSTEM' if SYSTEM_SERVICE_MODE else 'CURRENTUSER'
|
||||
_KEY_STORE_INSTANCE = AgentKeyStore(_settings_dir(), scope=scope)
|
||||
return _KEY_STORE_INSTANCE
|
||||
|
||||
|
||||
SERVER_CERT_PATH = _key_store().server_certificate_path()
|
||||
|
||||
|
||||
|
||||
@@ -39,7 +39,9 @@ def _restrict_permissions(path: str) -> None:
|
||||
def _protect(data: bytes, *, scope_system: bool) -> bytes:
|
||||
if not IS_WINDOWS or not win32crypt:
|
||||
return data
|
||||
flags = win32crypt.CRYPTPROTECT_LOCAL_MACHINE if scope_system else 0
|
||||
flags = 0
|
||||
if scope_system:
|
||||
flags = getattr(win32crypt, "CRYPTPROTECT_LOCAL_MACHINE", 0x4)
|
||||
protected = win32crypt.CryptProtectData(data, None, None, None, None, flags) # type: ignore[attr-defined]
|
||||
return protected[1]
|
||||
|
||||
@@ -47,7 +49,9 @@ def _protect(data: bytes, *, scope_system: bool) -> bytes:
|
||||
def _unprotect(data: bytes, *, scope_system: bool) -> bytes:
|
||||
if not IS_WINDOWS or not win32crypt:
|
||||
return data
|
||||
flags = win32crypt.CRYPTPROTECT_LOCAL_MACHINE if scope_system else 0
|
||||
flags = 0
|
||||
if scope_system:
|
||||
flags = getattr(win32crypt, "CRYPTPROTECT_LOCAL_MACHINE", 0x4)
|
||||
unwrapped = win32crypt.CryptUnprotectData(data, None, None, None, None, flags) # type: ignore[attr-defined]
|
||||
return unwrapped[1]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user