Skip to content

fix(policy): preserve original DataToVerify bytes on commit#40

Merged
sashyo merged 1 commit into
mainfrom
fix/policy-datatoverify
May 20, 2026
Merged

fix(policy): preserve original DataToVerify bytes on commit#40
sashyo merged 1 commit into
mainfrom
fix/policy-datatoverify

Conversation

@sashyo
Copy link
Copy Markdown
Owner

@sashyo sashyo commented May 20, 2026

Summary

  • Stop re-serializing the policy via policy.toBytes() when committing to storage; this rebuilds section 0 from fields and can byte-differ from what the ORK actually signed (PolicyParameters Map order, enum casing, length-prefix encoding).
  • Compose stored policyData = TideMemory([ DataToVerify, signature ]) using the exact bytes from request.draft so section 0 is byte-identical to what was signed in Sign tidecloak sdk integration #1.

Why

PolicyAuthorizationFlow.AuthorizeAsync on the ORK verifies Policy.Signature against the raw bytes of Policy.DataToVerify (the input section 0, preserved). When section 0 drifts on round-trip, Sign #2 fails with "Policy signature could not be verified" while Sign #1 (Doken:1 flow) still succeeds. This change makes the bytes stored at commit time match the bytes the ORK signed.

Test plan

  • Commit a fresh SSH policy via Admin Approvals
  • Verify server log shows Composed signed policy: dtv=<N>B sig=64B total=<M>B
  • Connect via SSH as a user covered by that policy — confirm both signs (createTideRequest → executeSignRequest) succeed
  • Confirm previous "Policy signature could not be verified" errors no longer appear in ORK logs

Sign #2 verifies the policy signature against the raw bytes of section 0
of the policy. Re-serializing via policy.toBytes() rebuilds section 0
from fields (PolicyParameters Map order, enum casing, length-prefix
encoding) and can byte-differ from what the ORK signed in Sign #1,
which causes "Policy signature could not be verified" on later signs.

Compose the stored policyData as TideMemory([ DataToVerify, signature ])
using the exact bytes from request.draft so section 0 is byte-identical
to what the ORK signed.
@sashyo sashyo merged commit ace0887 into main May 20, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant