Repository: dalek-cryptography/curve25519-dalek (language: rust)

Issue:
`Debug` implementation of `SigningKey` will print secret key material
Since the `Debug` implementation of `SigningKey` is derived, the `secret_key` is being printed and because `SecretKey` is just a type alias for `[u8; 32]`, it uses the std debug implementation for `[T; N]`:

https://github.com/dalek-cryptography/curve25519-dalek/blob/598695c4007d7ee3f48760668c47cf89b9aefb67/ed25519-dalek/src/signing.rs#L61-L64

I think in order to protect users from leaking their secret key, this should be omitted in the Debug output.


Discussion / hints:

Fix patch:
diff --git a/ed25519-dalek/src/signing.rs b/ed25519-dalek/src/signing.rs
index fad45f706..ec866d967 100644
--- a/ed25519-dalek/src/signing.rs
+++ b/ed25519-dalek/src/signing.rs
@@ -9,6 +9,8 @@
 
 //! ed25519 signing keys.
 
+use core::fmt::Debug;
+
 #[cfg(feature = "pkcs8")]
 use ed25519::pkcs8;
 
@@ -58,7 +60,7 @@ pub type SecretKey = [u8; SECRET_KEY_LENGTH];
 // Invariant: `verifying_key` is always the public key of
 // `secret_key`. This prevents the signing function oracle attack
 // described in https://github.com/MystenLabs/ed25519-unsafe-libs
-#[derive(Clone, Debug)]
+#[derive(Clone)]
 pub struct SigningKey {
     /// The secret half of this signing key.
     pub(crate) secret_key: SecretKey,
@@ -507,6 +509,14 @@ impl AsRef<VerifyingKey> for SigningKey {
     }
 }
 
+impl Debug for SigningKey {
+    fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
+        f.debug_struct("SigningKey")
+            .field("verifying_key", &self.verifying_key)
+            .finish_non_exhaustive() // avoids printing `secret_key`
+    }
+}
+
 impl KeypairRef for SigningKey {
     type VerifyingKey = VerifyingKey;
 }


Test patch: