A key-agreement object let its caller supply the randomness used to make a long-term X25519 private key. Predict that source and you recover the key, and every secret it derived.
What goes wrong
This is the weak-nonce mistake again, with worse stakes. The object generates a long-lived X25519 private key, and the entropy behind that key comes from a randomness source the caller supplied. No validation, no internal source, just direct use.
A private key is only private because the number behind it was unpredictable. If the caller hands over a deterministic or reused generator, the private key is derivable by anyone who can reproduce that generator's output. From the private key, every session key and shared secret the object ever negotiated falls out with it. Traffic that anyone recorded becomes readable after the fact.
Long-term keys deserve stricter handling than ephemeral values, because their blast radius is measured in the lifetime of the identity rather than one message. Sourcing their entropy from outside the boundary is the wrong place to be flexible.
The pattern
class KeyAgreement:
def __init__(self, rng):
self.private = x25519_generate(rng) # entropy from caller
self.public = x25519_public(self.private)
def shared_secret(self, peer_pub):
return x25519(self.private, peer_pub)class KeyAgreement:
def __init__(self):
rng = system_secure_random() # entropy owned here
self.private = x25519_generate(rng)
self.public = x25519_public(self.private)
def shared_secret(self, peer_pub):
return x25519(self.private, peer_pub)Grounding and reachability were confirmed. The exploit-path gate would not conclude without the calling code, so the finding was held and an evidence request was raised instead of being reported as fact.
Why it matters to you
Any identity built on this key is forgeable, and any conversation it protected is decryptable, retroactively, the moment an attacker learns or influences the entropy source. That includes the dull failure mode where someone wires in a fixed seed to make tests reproducible and it escapes into a release.
Check your own code
- Find every place a long-term key pair is generated and trace where its randomness comes from.
- Reject constructors that accept a random source for key generation, and create it internally.
- In tests, avoid injecting deterministic RNGs into the same class path used in production.