Jean-Paul Calderone | 19555b9 | 2008-02-19 22:29:57 -0500 | [diff] [blame^] | 1 | import sys |
| 2 | |
| 3 | from OpenSSL.crypto import TYPE_DSA, Error, PKey, X509 |
| 4 | |
| 5 | class Checker_X509_get_pubkey(object): |
| 6 | """ |
| 7 | Leak checks for L{X509.get_pubkey}. |
| 8 | """ |
| 9 | def __init__(self, iterations): |
| 10 | self.iterations = iterations |
| 11 | |
| 12 | |
| 13 | def check_exception(self): |
| 14 | """ |
| 15 | Call the method repeatedly such that it will raise an exception. |
| 16 | """ |
| 17 | for i in xrange(self.iterations): |
| 18 | cert = X509() |
| 19 | try: |
| 20 | cert.get_pubkey() |
| 21 | except Error: |
| 22 | pass |
| 23 | |
| 24 | |
| 25 | def check_success(self): |
| 26 | """ |
| 27 | Call the method repeatedly such that it will return a PKey object. |
| 28 | """ |
| 29 | small = xrange(3) |
| 30 | for i in xrange(self.iterations): |
| 31 | key = PKey() |
| 32 | key.generate_key(TYPE_DSA, 256) |
| 33 | for i in small: |
| 34 | cert = X509() |
| 35 | cert.set_pubkey(key) |
| 36 | for i in small: |
| 37 | cert.get_pubkey() |
| 38 | |
| 39 | |
| 40 | def vmsize(): |
| 41 | return [x for x in file('/proc/self/status').readlines() if 'VmSize' in x] |
| 42 | |
| 43 | |
| 44 | def main(iterations='1000'): |
| 45 | iterations = int(iterations) |
| 46 | for klass in globals(): |
| 47 | if klass.startswith('Checker_'): |
| 48 | klass = globals()[klass] |
| 49 | print klass |
| 50 | checker = klass(iterations) |
| 51 | for meth in dir(checker): |
| 52 | if meth.startswith('check_'): |
| 53 | print '\t', meth, vmsize(), '...', |
| 54 | getattr(checker, meth)() |
| 55 | print vmsize() |
| 56 | |
| 57 | |
| 58 | if __name__ == '__main__': |
| 59 | main(*sys.argv[1:]) |