Happens sometimes that you have some certificate encrypted by some simple password. And then when you really need it, you cannot remember what was that simple password. Here is a very simple script, which can help you in such situation

#!/usr/bin/python
import itertools
import subprocess

a = [1,2,3,4,5,6,7,8,9]

for i in xrange(0,len(a)+1):
     l = list(itertools.permutations(a,i))
     for i in l:
       pw = ''
       for ch in i:
         pw = pw + str(ch)
       print pw
       try:
         subprocess.check_call(["openssl","pkcs12","-info",
                 "-in", "cert.pfx", "-passin", "pass:%s"%pw])
       except subprocess.CalledProcessError as e:
         if e.returncode > 1:
           raise e
       else:
         print "Solution found! %s"%pw
         sys.exit(0)

Tags