Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion engraphis/cloud_license.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,10 +688,19 @@ def _verify_module_integrity():

_lock_sentinel = object()
_GATE_SNAPSHOT = gate
_GATE_LOCK_TAKEN = 0 # generation counter — prevents re-snapshot after first call


def _verify_gate_integrity():
"""Raise if ``gate`` has been monkeypatched since import."""
"""Raise if ``gate`` has been monkeypatched since first call.

Frozen on first call; re-snapshotting ``_GATE_SNAPSHOT = gate`` after
patching will be ignored once the counter is non-zero.
"""
global _GATE_SNAPSHOT, _GATE_LOCK_TAKEN
if _GATE_LOCK_TAKEN == 0:
_GATE_SNAPSHOT = gate
_GATE_LOCK_TAKEN = 1
Comment on lines +701 to +703

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the import-time trusted gate snapshot

Do not reassign the trusted snapshot on the first integrity check. In a production process where cloud_license.gate is replaced after import but before its first verification, this branch records the replacement as _GATE_SNAPSHOT, so the subsequent comparison succeeds instead of detecting the tampering. The prior import-time snapshot correctly treats that timing window as a modification; retain it and make only the snapshot storage immutable if that is the concern.

Useful? React with 👍 / 👎.

try:
from engraphis.licensing import _TEST_MODE_PUBKEY_OVERRIDE
if _TEST_MODE_PUBKEY_OVERRIDE:
Expand Down