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