def test_write_with_multiple_hostnames(self): server_name = SNIExtension() server_name = server_name.create(host_names=[ bytearray(b'example.com'), bytearray(b'example.org')]) self.assertEqual(bytearray( b'\x00\x1c' + # lenght of array - 28 bytes b'\x00' + # type of element - host_name (0) b'\x00\x0b' + # length of element - 11 bytes # utf-8 encoding of example.com b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x63\x6f\x6d' + b'\x00' + # type of elemnt - host_name (0) b'\x00\x0b' + # length of elemnet - 11 bytes # utf-8 encoding of example.org b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x6f\x72\x67' ), server_name.ext_data) self.assertEqual(bytearray( b'\x00\x00' + # type of extension - SNI (0) b'\x00\x1e' + # length of extension - 26 bytes b'\x00\x1c' + # lenght of array - 24 bytes b'\x00' + # type of element - host_name (0) b'\x00\x0b' + # length of element - 11 bytes # utf-8 encoding of example.com b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x63\x6f\x6d' + b'\x00' + # type of elemnt - host_name (0) b'\x00\x0b' + # length of elemnet - 11 bytes # utf-8 encoding of example.org b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x6f\x72\x67' ), server_name.write())
def test_write_of_empty_extension(self): server_name = SNIExtension() self.assertEqual(bytearray( b'\x00\x00' + # type of extension - SNI (0) b'\x00\x00' # length of extension - 0 bytes ), server_name.write())
def test_write_with_multiple_hostnames(self): server_name = SNIExtension() server_name = server_name.create( hostNames=[bytearray(b'example.com'), bytearray(b'example.org')]) self.assertEqual( bytearray(b'\x00\x1c' + # lenght of array - 28 bytes b'\x00' + # type of element - host_name (0) b'\x00\x0b' + # length of element - 11 bytes # utf-8 encoding of example.com b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x63\x6f\x6d' + b'\x00' + # type of elemnt - host_name (0) b'\x00\x0b' + # length of elemnet - 11 bytes # utf-8 encoding of example.org b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x6f\x72\x67'), server_name.extData) self.assertEqual( bytearray(b'\x00\x00' + # type of extension - SNI (0) b'\x00\x1e' + # length of extension - 26 bytes b'\x00\x1c' + # lenght of array - 24 bytes b'\x00' + # type of element - host_name (0) b'\x00\x0b' + # length of element - 11 bytes # utf-8 encoding of example.com b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x63\x6f\x6d' + b'\x00' + # type of elemnt - host_name (0) b'\x00\x0b' + # length of elemnet - 11 bytes # utf-8 encoding of example.org b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x6f\x72\x67'), server_name.write())
def test_write_of_empty_extension(self): server_name = SNIExtension() self.assertEqual( bytearray(b'\x00\x00' + # type of extension - SNI (0) b'\x00\x00' # length of extension - 0 bytes ), server_name.write())
def test_write_of_empty_list_of_names(self): server_name = SNIExtension() server_name = server_name.create(server_names=[]) self.assertEqual(bytearray( b'\x00\x00' # length of array - 0 bytes ), server_name.ext_data) self.assertEqual(bytearray( b'\x00\x00' + # type of extension - SNI 0 b'\x00\x02' + # length of extension - 2 bytes b'\x00\x00' # length of array of names - 0 bytes ), server_name.write())
def test_write_of_empty_list_of_names(self): server_name = SNIExtension() server_name = server_name.create(serverNames=[]) self.assertEqual( bytearray(b'\x00\x00' # length of array - 0 bytes ), server_name.extData) self.assertEqual( bytearray(b'\x00\x00' + # type of extension - SNI 0 b'\x00\x02' + # length of extension - 2 bytes b'\x00\x00' # length of array of names - 0 bytes ), server_name.write())
def test_write(self): server_name = SNIExtension() server_name = server_name.create(bytearray(b'example.com')) self.assertEqual(bytearray( b'\x00\x0e' + # length of array - 14 bytes b'\x00' + # type of element - host_name (0) b'\x00\x0b' + # length of element - 11 bytes # UTF-8 encoding of example.com b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x63\x6f\x6d' ), server_name.ext_data) self.assertEqual(bytearray( b'\x00\x00' + # type of extension - SNI (0) b'\x00\x10' + # length of extension - 16 bytes b'\x00\x0e' + # length of array - 14 bytes b'\x00' + # type of element - host_name (0) b'\x00\x0b' + # length of element - 11 bytes # UTF-8 encoding of example.com b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x63\x6f\x6d' ), server_name.write())
def test_write(self): server_name = SNIExtension() server_name = server_name.create(bytearray(b'example.com')) self.assertEqual( bytearray(b'\x00\x0e' + # length of array - 14 bytes b'\x00' + # type of element - host_name (0) b'\x00\x0b' + # length of element - 11 bytes # UTF-8 encoding of example.com b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x63\x6f\x6d'), server_name.extData) self.assertEqual( bytearray(b'\x00\x00' + # type of extension - SNI (0) b'\x00\x10' + # length of extension - 16 bytes b'\x00\x0e' + # length of array - 14 bytes b'\x00' + # type of element - host_name (0) b'\x00\x0b' + # length of element - 11 bytes # UTF-8 encoding of example.com b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x63\x6f\x6d'), server_name.write())