Skip to content

fix: Redact pnet pre-shared key Debug output#6490

Open
milaforge wants to merge 3 commits into
libp2p:masterfrom
milaforge:pnet-redact-psk-debug
Open

fix: Redact pnet pre-shared key Debug output#6490
milaforge wants to merge 3 commits into
libp2p:masterfrom
milaforge:pnet-redact-psk-debug

Conversation

@milaforge

Copy link
Copy Markdown

Description

Redacts PreSharedKey Debug output, covers PnetConfig derived Debug, and adds to_key_file for explicit raw keyfile export.
Tests: cargo test -p libp2p-pnet

AI Assistance Disclosure

Tools used Codex

Attestation (required):

  • I have read every line of this diff, understand what it does, and can explain it in review.

Notes & open questions

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • A changelog entry has been made in the appropriate crates

@milaforge milaforge changed the title Redact pnet pre-shared key Debug output fix: Redact pnet pre-shared key Debug output Jun 18, 2026
@milaforge milaforge force-pushed the pnet-redact-psk-debug branch from 0fa9016 to 8c52925 Compare June 18, 2026 12:00

@jxs jxs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi, and thanks! Left a comment otherwise LGTM

Comment thread transports/pnet/src/lib.rs Outdated
Comment on lines +87 to +88
pub fn to_key_file(self) -> String {
format!("/key/swarm/psk/1.0.0/\n/base16/\n{}\n", to_hex(&self.0))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why do we require this? This doesn't look like canonical

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good point. to_key_file() intentionally matches the existing Display serialization; it is not meant to introduce a second key-file format.

I updated it to:

  1. delegate through Display,
  2. changed the signature to borrow &self,
  3. and tightened the docs on both APIs to make clear that they emit the unredacted go-libp2p key-file format.
  4. I also added a regression test so if Display ever stops being the raw key-file serializer, the test points maintainers to decouple to_key_file() instead of silently changing export behavior.

@jxs jxs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

sorry only one thing left

Comment thread transports/pnet/src/lib.rs Outdated
}

#[test]
fn debug_formatting_does_not_leak_raw_psk() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think these tests are required

}

/// Export the unredacted key in go-libp2p key file format.
pub fn to_key_file(&self) -> String {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

also see the clippy lints here

Co-authored-by: João Oliveira <hello@jxs.pt>
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.

2 participants