Blog

How to Factor a 4096-bit Certificate

October 21, 2015 by Ixia Blog Team

The RSA cipher is the basis of today’s web security. Its strength relies on an attacker’s inability to factor a number into the underlying primes that were multiplied together to create that number.

If you were to search the web about the difficulty of factoring integers used for RSA, you run into these intricate formulas that only an intrepid mathematician could understand. You don’t even get a time estimate, but just an order of magnitude. Then you find references to the RSA challenge numbers1 and discover that many are still not factored. It’s believed that a 1024-bit number could be factorable in the near future, but when you get to a 2048-bit number, terms like “heat death of the universe” start showing up. Also, a 4096-bit number is the gold standard used by signing authorities (those who sign certificates for other entities). This can never be factored without a quantum computer (and we seem to be some time away from that event).

There have been ongoing efforts2 in collecting and analyzing web certificates. An eye-opening 1.4% of 1024-bit certificates are relatively easy to factor, since primes end up being reused between certificates. This seems to be from the random number generation used in creating the primes in the first place.

https://scans.io has a live ongoing project to collect certificates used all over the web. One entry I found had a malformed certificate. Comparing it to the officially published certificate, there is, in fact, a single bit difference in the base-64 encoding of the certificate. It turns out that this change is enough to turn a very strong product into a number that’s relatively easy to factor.

Here’s the certificate as found by scans.io in their 20131030-20150518_certs.gz file (which has the hash of a18db9687dcf975fd74b80b3fbfaf494bd92f9a0)

 rsa-certificate

And here’s the official certificate as published by https://support.comodo.com/index.php?/Default/Knowledgebase/Article/View/966/108/intermediate-1-sha-2-comodo-rsa-certification-authority

 rsa-certificate2

Notice the difference? Even the “diff” utility doesn't make it easy:

 rsa-certificate3

So I’ve highlighted it here:

 rsa-certificate4

This is a change from 0x4f to 0x6f, a one-bit difference. That change is in the middle of the public modulus, which changes the number into:

595250832037245141724642107398533641144111340640849154810839512193646804439589382557795096048235159392412856809181253983148280442751106836828767077478502910675291715965426418324395462826337195608826159904332409833532414343087397304684051488024083060971973988667565926401713702437407307790551210783180012029671811979458976709742365579736599681150756374332129237698142054260771585540729412505699671993111094681722253786369180597052805125225748672266569013967025850135765598233721214965171040686884703517711864518647963618102322884373894861238464186441528415873877499307554355231373646804211013770034465627350166153734933786011622475019872581027516832913754790596939102532587063612068091625752995700206528059096165261547017202283116886060219954285939324476288744352486373248874067358561174498106575840101185900982162077077159324006959478269508752739127700736488047233240000039822220436926238829787777910496389976535011652167232945157863398393696073700349302045727197567758245297430951576661723085986322884692482509395445908010374318515362349026410765737591124992274932144264431069815225184803312051962397687546843549391694421374473639112368823353302082648568656670016717594098938729881048363493597279528092799031426506695583681896350803

On the surface, this seems daunting, but quickly breaks down into these primes (and the Miller-Rabin test easily confirms that these are prime):

257,

13597,

1190899,

17004451,

1819255238231, 4623731541688734360157042570610599516948756673458506045203383012491808884456840033256405244797373597698967825083614426858612172505968492429519729880788904669708659889195420119187545837343961105966713029653015626564410301004065523216873832556827271668037513653274083955351661031451005547129716495519856684862339797215225619044495314803081828924065993631397995002133184553870300969743815093415782391050089126574481411538326136338358602828285227302429027010535487312302708101693546422554530297729638618279672595506733452307463764128075572070518984325606985678956318543708024909638157569790529363117690866454471646918195515608197892797533331343998996749384381287896482752822626708144630179880644910939702909238809836672024841283049899764435643301500156753535232757034055275361761581567949729909736163907014149101108187137389755514653772766995574030729420371074928603918060655933332376504544795477628463896509713211880178013570634849313511923786260820063802222901481912180717261906818645776983810280048759905846118981705184817225422907319149095850579839942393906735249567561852134230042425232475850706950515777817768328720324295190824823428665893682564136428583423557638264707642117886612016046673110507953

Don’t worry. This certificate is no longer in use by that site, nor would it have actually been usable, so there is no danger in exposing these details.

How do we get a one-bit error like this? It can happen from memory corruption when a computer doesn’t use ECC memory3, or even when old hard drives are used. A humorous example of the one-bit-error issue is the registration of “micrmsoft.com”4, which changes the ‘o’ (0x6f) to an ‘m’ (0x6d), which is a one-bit difference and received many hits.

It’s a reminder that in all things dealing with encryption, the devil is always in the details, and the slightest mistake may be enough for an attacker to break in. The difference is that an attacker won’t tell you when something is broken. Although I’ve “factored” a 4096-bit certificate and can cross that off my bucket list, we are still some time away before we can declare the RSA algorithm broken.

References:

1 https://en.wikipedia.org/wiki/RSA_Factoring_Challenge

2 “Mining Your Ps and Qs Detection of Widespread Weak Keys" (https://www.rsaconference.com/writable/presentations/file_upload/cryp-t17.pdf) by Nadia Heninger

3 https://en.wikipedia.org/wiki/ECC_memory

4 http://micrmsoft.blogspot.com/2012/11/why-this-domain.html

Additional Resources:

Ixia ATI subscription

Ixia security solutions