-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: fix exposed private key in logs (#5306)
### Description Initially I was thinking of just reimplementing Debug for `SealevelInterchainSecurityModule`, but I saw that keypair is used in many different places. So I think this solution is a bit more permanent. Having a wrapper around Solana's Keypair with a custom Debug function. ### Drive-by changes ### Related issues ### Backward compatibility yes ### Testing Added unittest to test debug functionality
- Loading branch information
Showing
7 changed files
with
102 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use std::ops::Deref; | ||
|
||
use solana_sdk::{signature::Keypair, signer::Signer}; | ||
|
||
/// Wrapper around solana_sdk's Keypair. | ||
/// This implements a custom Debug so the private keys are | ||
/// not exposed. | ||
pub struct SealevelKeypair(pub Keypair); | ||
|
||
impl SealevelKeypair { | ||
/// create new SealevelKeypair | ||
pub fn new(keypair: Keypair) -> Self { | ||
Self(keypair) | ||
} | ||
/// Return the underlying keypair | ||
pub fn keypair(&self) -> &Keypair { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl Deref for SealevelKeypair { | ||
type Target = Keypair; | ||
|
||
/// Return the underlying keypair | ||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl std::fmt::Debug for SealevelKeypair { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "{}", self.0.pubkey()) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use solana_sdk::signature::Keypair; | ||
|
||
use super::SealevelKeypair; | ||
|
||
#[test] | ||
fn test_no_exposed_secret_key() { | ||
let priv_key = "2ckDxzDFpZGeWd7VbHzd6dMgxYpqVDPA8XzeXFuuUJ1K8CjtyTBenD1TSPPovahXEFw3kBihoyAKktyro22MP4bN"; | ||
let pub_key = "6oKnHXD2LRzQ4iNsgvkGSNNx68vj5GCYYpR2icy5JZhE"; | ||
|
||
let keypair = SealevelKeypair(Keypair::from_base58_string(priv_key)); | ||
|
||
let actual = format!("{:?}", keypair); | ||
assert_eq!(pub_key, actual); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters