Base object for all Client Hello configurations.
| 15 | |
| 16 | |
| 17 | class HelloConfig(object): |
| 18 | """Base object for all Client Hello configurations.""" |
| 19 | |
| 20 | def __init__(self): |
| 21 | """Initialize object with default settings.""" |
| 22 | self._name = None |
| 23 | self.modifications = [] |
| 24 | self.callbacks = [] |
| 25 | self.version = (3, 3) |
| 26 | self.record_version = (3, 0) |
| 27 | self.ciphers = [] |
| 28 | self.extensions = None |
| 29 | self.random = None |
| 30 | self.session_id = bytearray(0) |
| 31 | self.compression_methods = [0] |
| 32 | self.ssl2 = False |
| 33 | |
| 34 | @property |
| 35 | def name(self): |
| 36 | """Return the name of config with all the modifications applied.""" |
| 37 | if self.modifications: |
| 38 | return "{0} ({1})".format(self._name, |
| 39 | ", ".join(self.modifications)) |
| 40 | else: |
| 41 | return self._name |
| 42 | |
| 43 | @name.setter |
| 44 | def name(self, value): |
| 45 | """Set the base name of the configuration.""" |
| 46 | self._name = value |
| 47 | |
| 48 | def __call__(self, hostname): |
| 49 | """Generate a client hello object, use hostname in SNI extension.""" |
| 50 | # SNI is special in that we don't want to send it if it is empty |
| 51 | if self.extensions: |
| 52 | sni = next((x for x in self.extensions |
| 53 | if isinstance(x, SNIExtension)), |
| 54 | None) |
| 55 | if sni: |
| 56 | if hostname is not None: |
| 57 | if sni.serverNames is None: |
| 58 | sni.serverNames = [] |
| 59 | sni.hostNames = [hostname] |
| 60 | else: |
| 61 | # but if we were not provided with a host name, we want |
| 62 | # to remove empty extension |
| 63 | if sni.serverNames is None: |
| 64 | self.extensions = [x for x in self.extensions |
| 65 | if not isinstance(x, SNIExtension)] |
| 66 | |
| 67 | if self.random: |
| 68 | rand = self.random |
| 69 | else: |
| 70 | # we're not doing any crypto with it, just need "something" |
| 71 | # TODO: place unix time at the beginning |
| 72 | rand = numberToByteArray(random.getrandbits(256), 32) |
| 73 | |
| 74 | ch = ClientHello(self.ssl2).create(self.version, rand, self.session_id, |
nothing calls this directly
no outgoing calls
no test coverage detected