Example #1
0
    def test_create(self):
        npn_extension = NPNExtension()
        npn_extension = npn_extension.create()

        self.assertEqual(None, npn_extension.protocols)
        self.assertEqual(13172, npn_extension.ext_type)
        self.assertEqual(bytearray(0), npn_extension.ext_data)
Example #2
0
    def test_write(self):
        npn_extension = NPNExtension().create()

        self.assertEqual(bytearray(
            b'\x33\x74' +   # type of extension - NPN
            b'\x00\x00'     # length of extension
            ), npn_extension.write())
Example #3
0
    def test_create(self):
        npn_extension = NPNExtension()
        npn_extension = npn_extension.create()

        self.assertIsNone(npn_extension.protocols)
        self.assertEqual(13172, npn_extension.extType)
        self.assertEqual(bytearray(0), npn_extension.extData)
Example #4
0
    def test_write(self):
        npn_extension = NPNExtension().create()

        self.assertEqual(
            bytearray(b'\x33\x74' +  # type of extension - NPN
                      b'\x00\x00'  # length of extension
                      ),
            npn_extension.write())
Example #5
0
    def test_parse(self):
        npn_extension = NPNExtension()

        p = Parser(bytearray(0))

        npn_extension = npn_extension.parse(p)

        self.assertEqual(bytearray(0), npn_extension.extData)
        self.assertEqual([], npn_extension.protocols)
Example #6
0
    def test_parse_with_protocol_length_long_by_one(self):
        npn_extension = NPNExtension()

        p = Parser(
            bytearray(b'\x09' +  # length of name - 9 (short by one)
                      b'\x68\x74\x74\x70\x2f\x31\x2e\x31'))

        with self.assertRaises(SyntaxError):
            npn_extension.parse(p)
Example #7
0
    def test_parse_with_protocol_length_long_by_one(self):
        npn_extension = NPNExtension()

        p = Parser(bytearray(
            b'\x09' +   # length of name - 9 (short by one)
            b'\x68\x74\x74\x70\x2f\x31\x2e\x31'))

        with self.assertRaises(SyntaxError):
            npn_extension.parse(p)
Example #8
0
    def test_parse(self):
        npn_extension = NPNExtension()

        p = Parser(bytearray(0))

        npn_extension = npn_extension.parse(p)

        self.assertEqual(bytearray(0), npn_extension.ext_data)
        self.assertEqual([], npn_extension.protocols)
Example #9
0
    def test_parse_with_procotol(self):
        npn_extension = NPNExtension()

        p = Parser(bytearray(
            b'\x08' +   # length of name
            b'\x68\x74\x74\x70\x2f\x31\x2e\x31'))

        npn_extension = npn_extension.parse(p)

        self.assertEqual([bytearray(b'http/1.1')], npn_extension.protocols)
Example #10
0
    def test_parse_with_procotol(self):
        npn_extension = NPNExtension()

        p = Parser(
            bytearray(b'\x08' +  # length of name
                      b'\x68\x74\x74\x70\x2f\x31\x2e\x31'))

        npn_extension = npn_extension.parse(p)

        self.assertEqual([bytearray(b'http/1.1')], npn_extension.protocols)
Example #11
0
    def test_write_with_list(self):
        npn_extension = NPNExtension()
        npn_extensnio = npn_extension.create([
            bytearray(b'http/1.1'),
            bytearray(b'spdy/3')])

        self.assertEqual(bytearray(
            b'\x33\x74' +   # type of extension - NPN
            b'\x00\x10' +   # length of extension
            b'\x08' +       # length of name of protocol
            # utf-8 encoding of "http/1.1"
            b'\x68\x74\x74\x70\x2f\x31\x2e\x31' +
            b'\x06' +       # length of name of protocol
            # utf-8 encoding of "spdy/3"
            b'\x73\x70\x64\x79\x2f\x33'
            ), npn_extension.write())
Example #12
0
    def test_create_with_list_of_protocols(self):
        npn_extension = NPNExtension()
        npn_extension = npn_extension.create(
            [bytearray(b'http/1.1'),
             bytearray(b'spdy/3')])

        self.assertEqual([bytearray(b'http/1.1'),
                          bytearray(b'spdy/3')], npn_extension.protocols)
        self.assertEqual(
            bytearray(b'\x08' +  # length of name of protocol
                      # utf-8 encoding of "http/1.1"
                      b'\x68\x74\x74\x70\x2f\x31\x2e\x31' +
                      b'\x06' +  # length of name of protocol
                      # utf-8 encoding of "http/1.1"
                      b'\x73\x70\x64\x79\x2f\x33'),
            npn_extension.extData)
Example #13
0
    def test_write_with_list(self):
        npn_extension = NPNExtension()
        npn_extensnio = npn_extension.create(
            [bytearray(b'http/1.1'),
             bytearray(b'spdy/3')])

        self.assertEqual(
            bytearray(b'\x33\x74' +  # type of extension - NPN
                      b'\x00\x10' +  # length of extension
                      b'\x08' +  # length of name of protocol
                      # utf-8 encoding of "http/1.1"
                      b'\x68\x74\x74\x70\x2f\x31\x2e\x31' +
                      b'\x06' +  # length of name of protocol
                      # utf-8 encoding of "spdy/3"
                      b'\x73\x70\x64\x79\x2f\x33'),
            npn_extension.write())
Example #14
0
    def test_create_with_list_of_protocols(self):
        npn_extension = NPNExtension()
        npn_extension = npn_extension.create([
            bytearray(b'http/1.1'),
            bytearray(b'spdy/3')])

        self.assertEqual([
            bytearray(b'http/1.1'),
            bytearray(b'spdy/3')], npn_extension.protocols)
        self.assertEqual(bytearray(
            b'\x08' +   # length of name of protocol
            # utf-8 encoding of "http/1.1"
            b'\x68\x74\x74\x70\x2f\x31\x2e\x31' +
            b'\x06' +   # length of name of protocol
            # utf-8 encoding of "http/1.1"
            b'\x73\x70\x64\x79\x2f\x33'
            ), npn_extension.ext_data)
Example #15
0
 def __init__(self):
     """Set the configuration to Firefox 42."""
     super(Firefox_42, self).__init__()
     self._name = "Firefox 42"
     self.version = (3, 3)
     self.record_version = (3, 1)
     self.ciphers = [
         CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
         CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
         CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
         CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
         CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
         CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
         CipherSuite.TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
         CipherSuite.TLS_DHE_RSA_WITH_AES_256_CBC_SHA,
         CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA,
         CipherSuite.TLS_RSA_WITH_AES_256_CBC_SHA,
         CipherSuite.TLS_RSA_WITH_3DES_EDE_CBC_SHA
     ]
     ext = self.extensions = []
     ext.append(SNIExtension())
     ext.append(
         TLSExtension(extType=ExtensionType.renegotiation_info).create(
             bytearray(1)))
     ext.append(SupportedGroupsExtension().create(
         [GroupName.secp256r1, GroupName.secp384r1, GroupName.secp521r1]))
     ext.append(ECPointFormatsExtension().create(
         [ECPointFormat.uncompressed]))
     ext.append(TLSExtension(extType=ExtensionType.session_ticket))
     ext.append(NPNExtension())
     ext.append(
         TLSExtension(extType=ExtensionType.alpn).create(
             bytearray(b'\x00\x15' + b'\x02' + b'h2' + b'\x08' +
                       b'spdy/3.1' + b'\x08' + b'http/1.1')))
     ext.append(
         TLSExtension(extType=ExtensionType.status_request).create(
             bytearray(b'\x01' + b'\x00\x00' + b'\x00\x00')))
     sig_algs = []
     for alg in ['sha256', 'sha384', 'sha512', 'sha1']:
         sig_algs.append((getattr(HashAlgorithm,
                                  alg), SignatureAlgorithm.rsa))
     for alg in ['sha256', 'sha384', 'sha512', 'sha1']:
         sig_algs.append((getattr(HashAlgorithm,
                                  alg), SignatureAlgorithm.ecdsa))
     for alg in ['sha256', 'sha1']:
         sig_algs.append((getattr(HashAlgorithm,
                                  alg), SignatureAlgorithm.dsa))
     ext.append(SignatureAlgorithmsExtension().create(sig_algs))
    def test___init___(self):
        npn_extension = NPNExtension()

        self.assertEqual(None, npn_extension.protocols)
        self.assertEqual(13172, npn_extension.extType)
        self.assertEqual(bytearray(0), npn_extension.extData)
Example #17
0
    def test___repr__(self):
        npn_extension = NPNExtension().create([bytearray(b'http/1.1')])

        self.assertEqual("NPNExtension(protocols=[bytearray(b'http/1.1')])",
                         repr(npn_extension))