Пример #1
0
 def test_bad_checksum(self, raw):
     inst = SCIONUDPHeader()
     inst.total_len = 10 + inst.LEN
     inst._calc_checksum = create_mock()
     inst._calc_checksum.return_value = bytes.fromhex("8888")
     inst._checksum = bytes.fromhex("9999")
     # Call
     ntools.assert_raises(SCIONChecksumFailed, inst.validate, range(10))
Пример #2
0
 def test(self, raw):
     inst = SCIONUDPHeader()
     data = create_mock(["pop"])
     data.pop.return_value = bytes.fromhex("11112222000f9999")
     raw.return_value = data
     # Call
     inst._parse("src", "dst", "raw")
     # Tests
     raw.assert_called_once_with("raw", inst.NAME, inst.LEN)
     ntools.eq_(inst._src, "src")
     ntools.eq_(inst._dst, "dst")
     ntools.eq_(inst.src_port, 0x1111)
     ntools.eq_(inst.dst_port, 0x2222)
     ntools.eq_(inst.total_len, 0x000F)
     ntools.eq_(inst._checksum, bytes.fromhex("9999"))
Пример #3
0
 def _create_hdrs(self):
     """
     Create headers for a SCION packet
     """
     dest = SCIONAddr.from_values(self.remote, SVCType.SB_A)
     cmn_hdr, addr_hdr = build_base_hdrs(self.addr, dest)
     payload = SIBRAPayload.from_values()
     udp_hdr = SCIONUDPHeader.from_values(self.addr, self._port, dest, 0)
     return cmn_hdr, addr_hdr, udp_hdr, payload
Пример #4
0
 def test(self):
     inst = SCIONUDPHeader()
     inst._src = "src addr"
     inst._dst = "dst addr"
     inst.src_port = "src port"
     inst.dst_port = "dst port"
     # Call
     inst.reverse()
     # Tests
     ntools.eq_(inst._src, "dst addr")
     ntools.eq_(inst._dst, "src addr")
     ntools.eq_(inst.src_port, "dst port")
     ntools.eq_(inst.dst_port, "src port")
Пример #5
0
def parse_l4_hdr(proto, data, dst=None, src=None):
    if proto == L4Proto.UDP:
        raw_hdr = data.pop(SCIONUDPHeader.LEN)
        assert src
        assert dst
        return SCIONUDPHeader((src, dst, raw_hdr))
    if proto == L4Proto.SCMP:
        raw_hdr = data.pop(SCMPHeader.LEN)
        return SCMPHeader((src, dst, raw_hdr))
    if proto in L4Proto.L4:
        return None
    raise SCIONParseError("Unsupported L4 protocol type: %s" % proto)
Пример #6
0
 def test(self, in_cksum):
     inst = SCIONUDPHeader()
     inst._dst = create_mock_full(
         {
             "isd_as": create_mock_full({"pack()": b"dsIA"}),
             "host": create_mock_full({"pack()": b"dstH"}),
         },
         class_=SCIONAddr)
     inst._src = create_mock_full(
         {
             "isd_as": create_mock_full({"pack()": b"srIA"}),
             "host": create_mock_full({"pack()": b"srcH"}),
         },
         class_=SCIONAddr)
     inst.pack = create_mock_full(return_value=b"packed with null checksum")
     payload = b"payload"
     expected_call = b"".join([
         b"dsIA",
         b"srIA",
         b"dstH",
         b"srcH",
         b"\x00",
         bytes([L4Proto.UDP]),
         b"packed with null checksum",
         payload,
     ])
     in_cksum.return_value = 0x3412
     # Call
     ntools.eq_(inst._calc_checksum(payload), bytes.fromhex("3412"))
     # Tests
     in_cksum.assert_called_once_with(expected_call)
Пример #7
0
 def _create_reg_pkt(self, type_, remote=False):
     if remote:
         dst_ia = self.remote
         path = self.seg.get_path(True)
     else:
         dst_ia = self.addr.isd_as
         path = SCIONPath()
     pcb = self._create_reg_pcb(remote)
     pld = PathRecordsReg.from_values({type_: [pcb]})
     dest = SCIONAddr.from_values(dst_ia, SVCType.PS_A)
     cmn_hdr, addr_hdr = build_base_hdrs(self.addr, dest)
     udp_hdr = SCIONUDPHeader.from_values(self.addr, self._port, dest, 0)
     return SCIONL4Packet.from_values(cmn_hdr, addr_hdr, path, [], udp_hdr,
                                      pld)
Пример #8
0
 def _build_packet(self, dst_host=None, path=None, ext_hdrs=(),
                   dst_ia=None, payload=None, dst_port=0):
     if dst_host is None:
         dst_host = HostAddrNone()
     if dst_ia is None:
         dst_ia = self.addr.isd_as
     if path is None:
         path = SCIONPath()
     if payload is None:
         payload = PayloadRaw()
     dst_addr = SCIONAddr.from_values(dst_ia, dst_host)
     cmn_hdr, addr_hdr = build_base_hdrs(dst_addr, self.addr)
     udp_hdr = SCIONUDPHeader.from_values(
         self.addr, self._port, dst_addr, dst_port)
     return SCIONL4Packet.from_values(
         cmn_hdr, addr_hdr, path, ext_hdrs, udp_hdr, payload)
Пример #9
0
 def test(self, scapy_checksum):
     inst = SCIONUDPHeader()
     inst._src = create_mock(["pack"], class_=SCIONAddr)
     inst._src.pack.return_value = b"source address"
     inst._dst = create_mock(["pack"], class_=SCIONAddr)
     inst._dst.pack.return_value = b"destination address"
     inst.pack = create_mock()
     inst.pack.return_value = b"packed with null checksum"
     payload = b"payload"
     expected_call = b"".join([
         b"source address", b"destination address", bytes([L4Proto.UDP]),
         b"packed with null checksum", payload,
     ])
     scapy_checksum.return_value = 0x3412
     # Call
     ntools.eq_(inst._calc_checksum(payload), bytes.fromhex("1234"))
     # Tests
     scapy_checksum.assert_called_once_with(expected_call)
Пример #10
0
 def test_bad_length(self, raw):
     inst = SCIONUDPHeader()
     inst.total_len = 10
     # Call
     ntools.assert_raises(SCMPBadPktLen, inst.validate, range(9))
Пример #11
0
 def _create_l4_hdr(self):
     return SCIONUDPHeader.from_values(self.addr, self.sock.port, self.dst,
                                       self.dport)