def generate(self, state): if self.version is None: self.version = state.client_version if self.random: state.client_random = self.random if self.session_id is None: self.session_id = state.session_id if not state.client_random: state.client_random = bytearray(32) extensions = None if self.extensions is not None: extensions = self._generate_extensions(state) clnt_hello = ClientHello(self.ssl2).create(self.version, state.client_random, self.session_id, self.ciphers, extensions=extensions) clnt_hello.compression_methods = self.compression state.client_version = self.version self.msg = clnt_hello return clnt_hello
def generate(self, state): if self.version is None: self.version = state.client_version if self.random: state.client_random = self.random if self.session_id is None: self.session_id = state.session_id if not state.client_random: state.client_random = bytearray(32) extensions = None if self.extensions is not None: extensions = self._generate_extensions(state) clnt_hello = ClientHello().create(self.version, state.client_random, self.session_id, self.ciphers, extensions=extensions) clnt_hello.compression_methods = self.compression state.client_version = self.version self.msg = clnt_hello return clnt_hello
def __call__(self, hostname): """Generate a client hello object, use hostname in SNI extension.""" # SNI is special in that we don't want to send it if it is empty if self.extensions: sni = next((x for x in self.extensions if isinstance(x, SNIExtension)), None) if sni: if hostname is not None: if sni.serverNames is None: sni.serverNames = [] sni.hostNames = [hostname] else: # but if we were not provided with a host name, we want # to remove empty extension if sni.serverNames is None: self.extensions = [x for x in self.extensions if not isinstance(x, SNIExtension)] if self.random: rand = self.random else: # we're not doing any crypto with it, just need "something" # TODO: place unix time at the beginning rand = numberToByteArray(random.getrandbits(256), 32) ch = ClientHello(self.ssl2).create(self.version, rand, self.session_id, self.ciphers, extensions=self.extensions) ch.compression_methods = self.compression_methods for cb in self.callbacks: ch = cb(ch) return ch
def __call__(self, hostname): """Generate a client hello object, use hostname in SNI extension.""" # SNI is special in that we don't want to send it if it is empty if self.extensions: sni = next( (x for x in self.extensions if isinstance(x, SNIExtension)), None) if sni: if hostname is not None: if sni.serverNames is None: sni.serverNames = [] sni.hostNames = [hostname] else: # but if we were not provided with a host name, we want # to remove empty extension if sni.serverNames is None: self.extensions = [ x for x in self.extensions if not isinstance(x, SNIExtension) ] if self.random: rand = self.random else: # we're not doing any crypto with it, just need "something" # TODO: place unix time at the beginning rand = numberToByteArray(random.getrandbits(256), 32) ch = ClientHello(self.ssl2).create(self.version, rand, self.session_id, self.ciphers, extensions=self.extensions) ch.compression_methods = self.compression_methods for cb in self.callbacks: ch = cb(ch) return ch