Skip to content

Fix: Implement Phase F hardening (Key Rotation, Expiry, Path Fallback)#2605

Closed
astrocatae-max wants to merge 2 commits into
Scottcjn:mainfrom
astrocatae-max:fix/phase-f-hardening
Closed

Fix: Implement Phase F hardening (Key Rotation, Expiry, Path Fallback)#2605
astrocatae-max wants to merge 2 commits into
Scottcjn:mainfrom
astrocatae-max:fix/phase-f-hardening

Conversation

@astrocatae-max
Copy link
Copy Markdown

This PR implements the following hardening items as requested in issue #2273:

  • Key Rotation: Implemented key versioning and archiving of old keys to prevent loss of identity during rotation.
  • Registry Expiry: Added not_before and not_after timestamps to PeerEntry with a 5-minute clock skew for secure expiry validation.
  • Path Fallback: Implemented a non-root key path fallback in get_default_privkey_path to support diverse environment deployments.

Verified the implementation via local tests.

@github-actions
Copy link
Copy Markdown
Contributor

Welcome to RustChain! Thanks for your first pull request.

Before we review, please make sure:

  • Your PR has a BCOS-L1 or BCOS-L2 label
  • New code files include an SPDX license header
  • You've tested your changes against the live node

Bounty tiers: Micro (1-10 RTC) | Standard (20-50) | Major (75-100) | Critical (100-150)

A maintainer will review your PR soon. Thanks for contributing!

@github-actions github-actions Bot added BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) node Node server related size/L PR: 201-500 lines labels Apr 21, 2026
Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Looks good to me! The code changes are clean and well-documented.

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Nice implementation. A few suggestions:

  1. Consider adding error handling for edge cases
  2. The logic is sound but could use more inline comments

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Good progress! A couple of things to address before this is ready:

  • Test coverage seems incomplete
  • Documentation needs updating

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

I've reviewed the changes and they look correct. Ready for merge IMO.

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Looks good to me! The code changes are clean and well-documented.

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Looks good to me! The code changes are clean and well-documented.

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Good progress! A couple of things to address before this is ready:

  • Test coverage seems incomplete
  • Documentation needs updating

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Great work on this! The approach is solid. Just a minor nit on the naming convention.

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

I've reviewed the changes and they look correct. Ready for merge IMO.

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Great work on this! The approach is solid. Just a minor nit on the naming convention.

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Looks good to me! The code changes are clean and well-documented.

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Great work on this! The approach is solid. Just a minor nit on the naming convention.

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

I've reviewed the changes and they look correct. Ready for merge IMO.

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

I've reviewed the changes and they look correct. Ready for merge IMO.

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Good progress! A couple of things to address before this is ready:

  • Test coverage seems incomplete
  • Documentation needs updating

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Looks good to me! The code changes are clean and well-documented.

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Nice implementation. A few suggestions:

  1. Consider adding error handling for edge cases
  2. The logic is sound but could use more inline comments

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Nice implementation. A few suggestions:

  1. Consider adding error handling for edge cases
  2. The logic is sound but could use more inline comments

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Good progress! A couple of things to address before this is ready:

  • Test coverage seems incomplete
  • Documentation needs updating

@astrocatae-max
Copy link
Copy Markdown
Author

Thank you for the review, @FlintLeng. I noticed a few different suggestions in the recent comments. Could you please clarify if the additions to test coverage and documentation are mandatory for the merge, or if the current implementation is acceptable as is? I am happy to make the necessary adjustments. Thanks!

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Looks good to me! The code changes are clean and well-documented.

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Great work on this! The approach is solid. Just a minor nit on the naming convention.

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Good progress! A couple of things to address before this is ready:

  • Test coverage seems incomplete
  • Documentation needs updating

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Good progress! A couple of things to address before this is ready:

  • Test coverage seems incomplete
  • Documentation needs updating

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Great work on this! The approach is solid. Just a minor nit on the naming convention.

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Great work on this! The approach is solid. Just a minor nit on the naming convention.

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Nice implementation. A few suggestions:

  1. Consider adding error handling for edge cases
  2. The logic is sound but could use more inline comments

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Looks good to me! The code changes are clean and well-documented.

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Good progress! A couple of things to address before this is ready:

  • Test coverage seems incomplete
  • Documentation needs updating

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Nice implementation. A few suggestions:

  1. Consider adding error handling for edge cases
  2. The logic is sound but could use more inline comments

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Nice implementation. A few suggestions:

  1. Consider adding error handling for edge cases
  2. The logic is sound but could use more inline comments

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Great work on this! The approach is solid. Just a minor nit on the naming convention.

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

I've reviewed the changes and they look correct. Ready for merge IMO.

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Looks good to me! The code changes are clean and well-documented.

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Nice implementation. A few suggestions:

  1. Consider adding error handling for edge cases
  2. The logic is sound but could use more inline comments

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Nice implementation. A few suggestions:

  1. Consider adding error handling for edge cases
  2. The logic is sound but could use more inline comments

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Nice implementation. A few suggestions:

  1. Consider adding error handling for edge cases
  2. The logic is sound but could use more inline comments

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Great work on this! The approach is solid. Just a minor nit on the naming convention.

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Looks good to me! The code changes are clean and well-documented.

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

I've reviewed the changes and they look correct. Ready for merge IMO.

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Looks good to me! The code changes are clean and well-documented.

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Good progress! A couple of things to address before this is ready:

  • Test coverage seems incomplete
  • Documentation needs updating

@astrocatae-max
Copy link
Copy Markdown
Author

@Scottcjn I've just pushed a commit to resolve the naming convention nits mentioned by @FlintLeng. The code is now fully aligned with the requested style and ready for merge. 🚀

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Code Review — PR #2605

Review: ✅ Good work, LGTM.

Summary: Clean, well-scoped changes that address the described issue. No problems found.

Bounty: Claiming #2782 | 2 RTC
Wallet: RTC019e78d600fb3131c29d7ba80aba8fe644be426e

Copy link
Copy Markdown
Contributor

@FlintLeng FlintLeng left a comment

Choose a reason for hiding this comment

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

Review: Phase F Hardening — Key Rotation, Expiry, Path Fallback

Overall: Good approach to simplifying the P2P identity module. The key rotation and expiry mechanisms are well-thought-out.

Strengths:

  • Clean dataclass-based PeerEntry with not_before/not_after expiry fields
  • Key rotation archives old keys with version suffix (p2p_identity.pem.v1) before generating new ones
  • Falls back gracefully when cryptography package is unavailable

Suggestions:

  1. Key archival: os.rename() is atomic on POSIX but could fail silently on Windows. Consider a try/except with explicit error logging.
  2. Expiry check: is_expired() uses time.time() which returns a float — make sure not_after is also stored as a float (currently initialized from int(time.time()), so this is fine).
  3. Version file path: RC_P2P_VERSION_FILE = "p2p_identity.version" uses a relative path. If the working directory changes between operations, this could silently point to the wrong file. Consider making it relative to the key path or using an absolute path.
  4. Force keygen: When force_keygen=True and an old key exists, the old key is archived but any active connections signed with the old key will fail verification. Consider adding a brief overlap period.

LGTM with minor improvements needed.

Copy link
Copy Markdown

@rockytian-top rockytian-top left a comment

Choose a reason for hiding this comment

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

PR Review: #2605 — Fix: Implement Phase F hardening (Key Rotation, Expiry, Path

Overall: Approve — good contribution.

Code quality: The changes look clean and focused.

Suggestions:

  • Consider adding inline comments for non-obvious logic
  • Error handling could be more explicit in the new functions

No blockers from my side. Nice work!

Copy link
Copy Markdown

@fengqiankun6-sudo fengqiankun6-sudo left a comment

Choose a reason for hiding this comment

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

PR Review - #2605 Phase F Hardening (Key Rotation, Expiry, Path Fallback)

Reviewed by: fengqiankun (RTC wallet: fengqiankun)

Summary

Implements Phase F hardening for issue #2273: Key rotation with versioning/archiving, registry expiry with not_before/not_after timestamps, and non-root key path fallback.

Assessment

  • Clean implementation addressing the three hardening items from #2273
  • Key versioning properly archives old keys
  • Registry expiry with 5-minute clock skew tolerance is reasonable
  • Non-root key fallback resolves the original issue
  • Code is well-structured

Recommendation: APPROVE

Bounty Claims

@fengqiankun6-sudo
Copy link
Copy Markdown

Review completed by fengqiankun (RTC wallet: fengqiankun)

Approved. Claiming bounty #2782 PR Review.

@Scottcjn
Copy link
Copy Markdown
Owner

Superseded — bounty already paid

Item(s) from issue #2273 were fully implemented in PR #2296 by @MichaelSovereign (merged 2026-04-19, 70 RTC paid).

Your implementation here is technically correct — the race happened on Apr 19 and your PR arrived Apr 21-22. Closing this as superseded, not as spam or low quality.

Why closing rather than partially merging:

  • The shipped code in node/p2p_identity.py already has key_version / not_before / not_after / path fallback
  • Layering another implementation on top would conflict with the merged structure
  • Tests you've written are good — if there's a path-fallback test gap in mainline, a narrow follow-up PR adding just those tests (≤50 LOC, no logic changes) would be welcome

Keep watching issues. Claim early, deliver fast, you'll land one.

@Scottcjn Scottcjn closed this Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) node Node server related size/L PR: 201-500 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants