Exemple #1
0
 def test_bad_checksum(self, raw):
     inst = SCMPHeader()
     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))
Exemple #2
0
 def test(self, raw):
     inst = SCMPHeader()
     data = create_mock(["pop"])
     data.pop.return_value = bytes.fromhex(
         "11112222000f99992323232323232323")
     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.class_, 0x1111)
     ntools.eq_(inst.type, 0x2222)
     ntools.eq_(inst.total_len, 0x000F)
     ntools.eq_(inst._checksum, bytes.fromhex("9999"))
     ntools.eq_(inst.timestamp, 0x2323232323232323)
Exemple #3
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)
Exemple #4
0
 def test(self, in_cksum):
     inst = SCMPHeader()
     src_ia = create_mock_full({"pack()": b"srIA"})
     src_host = create_mock_full({"pack()": b"sHst"})
     inst._src = create_mock_full({
         "isd_as": src_ia,
         "host": src_host
     },
                                  class_=SCIONAddr)
     dst_ia = create_mock_full({"pack()": b"dsIA"})
     dst_host = create_mock_full({"pack()": b"dHst"})
     inst._dst = create_mock_full({
         "isd_as": dst_ia,
         "host": dst_host
     },
                                  class_=SCIONAddr)
     inst.pack = create_mock()
     inst.pack.return_value = b"packed with null checksum"
     payload = b"payload"
     expected_call = b"".join([
         b"dsIA",
         b"srIA",
         b"dHst",
         b"sHst",
         b"\x00",
         bytes([L4Proto.SCMP]),
         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)
Exemple #5
0
 def convert_to_scmp_error(self, addr, class_, type_, pkt, *args,
                           hopbyhop=False, **kwargs):
     self.addrs.src = addr
     if self.ext_hdrs:
         if self.ext_hdrs[0].EXT_TYPE == ExtHopByHopType.SCMP:
             # Remove any existing SCMP ext header
             del self.ext_hdrs[0]
     # Insert SCMP ext at start of headers
     self.ext_hdrs.insert(0, SCMPExt.from_values(hopbyhop=hopbyhop))
     # Trim any extra headers, in the case of SCMPTooManyHopByHop, max+1 as
     # the SCMP ext header isn't counted.
     self.ext_hdrs = self.ext_hdrs[:MAX_HOPBYHOP_EXT + 1]
     # Create SCMP payload.
     pld = SCMPPayload.from_pkt(class_, type_, pkt, *args, **kwargs)
     self.l4_hdr = SCMPHeader.from_values(self.addrs.src, self.addrs.dst,
                                          class_, type_)
     self.set_payload(pld)
Exemple #6
0
 def test(self, scapy_checksum):
     inst = SCMPHeader()
     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.SCMP]),
         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)
Exemple #7
0
 def test_bad_length(self, raw):
     inst = SCMPHeader()
     inst.total_len = 10
     # Call
     ntools.assert_raises(SCMPBadPktLen, inst.validate, range(9))
Exemple #8
0
 def _create_l4_hdr(self):
     return SCMPHeader.from_values(
         self.addr, self.dst, SCMPClass.GENERAL,
         SCMPGeneralClass.ECHO_REQUEST)