Skip to content

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

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

fix: Redact pnet pre-shared key Debug output#6490
milaforge wants to merge 5 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 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

This comment was marked as outdated.

@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
Fingerprint(out)
}

/// Export the unredacted key in go-libp2p key file format.

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.

Suggested change
/// Export the unredacted key in go-libp2p key file format.
/// Export the unredacted private key.

}

#[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

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.

Why?
debug_formatting_does_not_leak_raw_psk directly covers the security promise of the PR. PreSharedKey Debug redacts the raw key, and derived PnetConfig Debug does not accidentally re-expose it through the field. This is valuable regression coverage.

Comment thread transports/pnet/src/lib.rs Outdated
milaforge and others added 2 commits June 18, 2026 22:04
writeln!(f, "/key/swarm/psk/1.0.0/")?;
writeln!(f, "/base16/")?;
writeln!(f, "{}", to_hex(&self.0))
f.write_str(&self.to_key_file())

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.

Making to_key_file() the canonical raw-export implementation and having Display delegate to it.

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