The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Email Subscription

    Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 719 other subscribers

Stupid Certificate Tricks | rya.nc

Posted by jpluimers on 2026/11/26

A few weeks ago, this 10+ year post suddenly became very relevant: [Wayback/Archive] Stupid Certificate Tricks | rya.nc

The post explains how to create a certificate where the public key contains some ASCII text.

In short, the trick is that there is quite a bit of data in the first half of the public key can be influenced by carefully modifying the prime factors that the private key are built from.

These and similar became hot again because of the eMudhra certificate disaster, which in the end was attributed to a Python script (that should have never been approved as it did not meet standards) exporting the private keys from the HSM, then truncating them during re-import¹.

I found it via:

  1. [Wayback/Archive] nothacking: “Check out my new TLS certifica…” – Infosec Exchange

    Check out my new TLS certificate: yes, Let’s Encrypt signed this and yes, it works [funnies.maurycyz.com].

    [Wayback/Archive] funnies.maurycyz.com

    openssl s_client -connect funnies.maurycyz.com:443 2>/dev/null | sed -n /BEGIN/,/END/p

    A base64 (pem) certificate where the RSA public modulus (the

    A base64 (pem) certificate where the RSA public modulus (the “public key”) includes the string: “///You+dont+actually+have+to+pick+random+private+keys//No+one+checks//A+certificate+aurthority+almost+got+away+with+the+number+4//”

  2. [Wayback/Archive] Horrible public key tricks:
  3. [Wayback/Archive] Horible public key tricks | Hacker News
  4. [Wayback/Archive] httpv.pdf [Wayback PDF View/PDF View] – No one can force me to have a secure website!!!
  5. [Wayback/Archive] Stupid certificate tricks | Hacker News

--jeroen

¹ this became a soap of which you can read the full thread is still ongoing. You can read it here (archived until 20261116 and 20261110): [Wayback/Archive] 2083449 – eMudhra: Private key compromise of Intermediate Certificates (comment #82 is the eMudhra postmortem)

Some other links and comments (most are short versions of what already is in the above thread):

  • [Wayback/Archive] Scott Helme: “eMudhra’s incident report is o…” – Infosec Exchange

    eMudhra’s incident report is out! A Python script truncated their CA private keys to one byte?!

    bugzilla.mozilla.org/show_bug.

    1. the fact that the keys left the HSM is highly sus
    2. yeah, the whole purpose of using an HSM is that the keys never leave, not some checkbox compliance of what the keys were generated on. this whole shaggy dog story simply raises more questions than it answers
    3. like if you legitimately need to move keys securely between your HSMs for whatever byzantine reasons, there’s a thing for that: en.wikipedia.org/wiki/Key_wrap
    4. After the wrapped key was returned, the script read the unwrapped private key’s value out of the module (in host side memory) and re‑created a key object from that host‑side value

      Yeah sorry what the hell, what do@you mean “out of the module”? All I can wonder is did they mean basically “through HSM interfaces manipulating the key material opaquely”? So that they basically truncated it to 1 byte within the HSM itself by nulling out the rest via the opaque structure?

    5. This person makes an interesting hypothesis regarding abuse of the “backup” function that might be available in those HSMs when FIPS mode is disabled:
      bugzilla.mozilla.org/show_bug.
    6. yeah, that comment got my attention as well. A borked attempt at reversing the backup format sounds a lot more plausible than “somehow truncated the value in python after retrieving it via an interface designed for this purpose”Although, Occam’s razor…
    7. this 100% feels like what happened honestly. It would also explain why the RSA keys didn’t have that issue only the ECC keys.(Either that or they only tested on RSA keys for some insane reason).Because I’m going to be honest, even if you can export a key wrapped with your own chosen key (something that seems like how this is done), I’m not actually certain vendors document the wrapped key format?
    8. So not only was there a bug; there was a bug in the “handle the private key outside the HSM as an emergency bodge” script that didn’t merely export and unwrap the keys but re-created defective ones from a truncated copy of of the material from the HSM.Somehow I feel even worse about this than previously.
    9. The thing that sounds the most fishy to me remains the fact that they immediately announced leaving the public CA business before even the incident report.That screams “we fucked up so bad, please don’t come look too closely into the rest of our stuff”
    10. once again, webtrust audits, which attest that the wrong thing is done correctly, showing their value. In any sane and sensible world, you’d have people who know that half-arsing a python script is likely to end badly auditing CA operations like a KGC, but no, it’s accountants who don’t like numbers who sign off that everything is hunky-dory.Also loved the attempt to blame the incident, in part, on those pesky trust stores and their attempts to improve things. “root store program policy changes taking effect on 15 June 2025 […] meant that the keys had to be generated before the end of May 2025.” I mean, a CA can’t *possibly* be expected to follow the spirit of the rules and just comply with requirements, they’ve just *got* to rush things to get their bad practices in before the deadline.
    11. “…correspond to private scalars below the expected range and are recoverable from public information.”The number 4 is indeed public information known to any person with basic education in math.
    12. I love the bit where, even if their shitty python script hadn’t fucked up and truncated the keys… it would’ve still been non-compliant because the whole fuckin’ process was very obviously non-compliant (see: their RSA keys).But it’s totes cool because they just had to get it in before they were *checks notes* obligated to do things better.Not really sure why they bothered rushing. They evidently don’t give two shits for their responsibilities.
  • [Wayback/Archive] eMudhra Revokes 8 More CAs It Previously Declared Unaffected by Key Compromise
  • [Wayback/Archive] Latest Baseline Requirements | CA/Browser Forum thanks @mickert@hsnl.social who also commented this (in Dutch, but I translated it):

    it states this:

    5.2.2 Number of Individuals Required per Task The CA Private Key SHALL be backed up, stored, and recovered only by personnel in Trusted Roles using, at least, dual control in a physically secured environment.

    So it looks like exporting private keys from the HSM is allowed … I would think cross-signing when HSM breaks -> new CA.

    It also states (but could be about certificates signed by a private key) and referenced in the eMudhra report:

    6.2.6 Private key transfer into or from a cryptographic module If the Issuing CA generated the Private Key on behalf of the Subordinate CA, then the Issuing CA SHALL encrypt the Private Key for transport to the Subordinate CA. If the Issuing CA becomes aware that a Subordinate CA’s Private Key has been communicated to an unauthorized person or an organization not affiliated with the Subordinate CA, then the Issuing CA SHALL revoke all certificates that include the Public Key corresponding to the communicated Private Key.

    And this (but I don’t think a Python script in RAM meets this):

    6.2.7 Private key storage on cryptographic module The CA SHALL protect its Private Key in a system or device that has been validated as meeting at least FIPS 140-2 level 3, FIPS 140-3 level 3, or an appropriate Common Criteria Protection Profile or Security Target, EAL 4 (or higher), which includes requirements to protect the Private Key and other assets against known threats.

    All in all, it looks like eMudhra had a creative implementation of the rules.

  • a

Leave a Comment