Generate a client hello object, use hostname in SNI extension.
(self, hostname)
| 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, |
| 75 | self.ciphers, |
| 76 | extensions=self.extensions) |
| 77 | ch.compression_methods = self.compression_methods |
| 78 | for cb in self.callbacks: |
| 79 | ch = cb(ch) |
| 80 | return ch |
| 81 | |
| 82 | |
| 83 | class Firefox_42(HelloConfig): |