Example #1
0
 def _create_one_hop_path(self, egress_if):
     ts = int(SCIONTime.get_time())
     info = InfoOpaqueField.from_values(ts, self.addr.isd_as[0], hops=2)
     hf1 = HopOpaqueField.from_values(self.HOF_EXP_TIME, 0, egress_if)
     hf1.set_mac(self.of_gen_key, ts, None)
     # Return a path where second HF is empty.
     return SCIONPath.from_values(info, [hf1, HopOpaqueField()])
Example #2
0
 def test(self, raw):
     inst = HopOpaqueField()
     inst._parse_flags = create_mock()
     data = create_mock(["pop"])
     data.pop.side_effect = map(bytes.fromhex,
                                ('0e 2a', '0a0b0c', '012345'))
     raw.return_value = data
     # Call
     inst._parse("data")
     # Tests
     raw.assert_called_once_with("data", inst.NAME, inst.LEN)
     ntools.eq_(inst.exp_time, 0x2a)
     inst._parse_flags.assert_called_once_with(0x0e)
     ntools.eq_(inst.ingress_if, 0x0a0)
     ntools.eq_(inst.egress_if, 0xb0c)
     ntools.eq_(inst.mac, bytes.fromhex('012345'))
Example #3
0
 def test_no_prev(self, mac):
     inst = HopOpaqueField()
     inst.pack = create_mock()
     pack_mac = bytes.fromhex('02 2a0a 0b0c')
     inst.pack.return_value = pack_mac
     ts = 0x01020304
     expected = b"".join([
         ts.to_bytes(4, "big"),
         pack_mac,
         bytes(7),
     ])
     mac.return_value = "mac_data"
     # Call
     ntools.eq_(inst.calc_mac("key", ts), "mac")
     # Tests
     inst.pack.assert_called_once_with(mac=True)
     mac.assert_called_once_with("key", expected)
Example #4
0
 def test_prev(self, mac):
     inst = HopOpaqueField()
     inst.pack = create_mock()
     pack_mac = bytes.fromhex('02 2a0a 0b0c')
     inst.pack.return_value = pack_mac
     prev_pack_mac = bytes.fromhex('10 1112 1314')
     prev = create_mock_full({"pack()": prev_pack_mac})
     ts = 0x01020304
     expected = b"".join([
         ts.to_bytes(4, "big"),
         pack_mac,
         prev_pack_mac[1:],
     ])
     # Call
     inst.calc_mac("key", ts, prev)
     # Tests
     prev.pack.assert_called_once_with()
     mac.assert_called_once_with("key", expected)
Example #5
0
 def test_mac(self):
     inst = HopOpaqueField()
     inst._pack_flags = create_mock()
     inst._pack_flags.return_value = 0x0e
     inst.exp_time = 0x2a
     inst.ingress_if = 0x0a0
     inst.egress_if = 0xb0c
     inst.mac = bytes.fromhex('012345')
     expected = bytes.fromhex('04 2a 0a0b0c')
     # Call
     ntools.eq_(inst.pack(mac=True), expected)
Example #6
0
    def _parse_hofs(self, data, label, count):
        """
        Parse raw :any:`HopOpaqueFields`\s.

        :param Raw data: Raw instance.
        :param str label: OF label.
        :param int count: Number of HOFs to parse.
        """
        hofs = []
        for _ in range(count):
            hofs.append(HopOpaqueField(data.pop(HopOpaqueField.LEN)))
        self._ofs.set(label, hofs)
Example #7
0
 def _create_pcbm(self, in_if, out_if, ts, prev_hof, xover=False):
     hof = HopOpaqueField.from_values(self.HOF_EXP_TIME,
                                      in_if,
                                      out_if,
                                      xover=xover)
     hof.set_mac(self.of_gen_key, ts, prev_hof)
     in_info = self._mk_if_info(in_if)
     out_info = self._mk_if_info(out_if)
     return PCBMarking.from_values(in_info["remote_ia"],
                                   in_info["remote_if"], in_info["mtu"],
                                   out_info["remote_ia"],
                                   out_info["remote_if"], hof,
                                   self._get_if_rev_token(in_if))
Example #8
0
File: base.py Project: fjacky/scion
 def _create_pcbm(self, in_if, out_if, ts, prev_hof, xover=False):
     in_info = self._mk_if_info(in_if)
     if in_info["remote_ia"].int() and not in_info["remote_if"]:
         return None
     out_info = self._mk_if_info(out_if)
     if out_info["remote_ia"].int() and not out_info["remote_if"]:
         return None
     hof = HopOpaqueField.from_values(
         self.HOF_EXP_TIME, in_if, out_if, xover=xover)
     hof.set_mac(self.of_gen_key, ts, prev_hof)
     return PCBMarking.from_values(
         in_info["remote_ia"], in_info["remote_if"], in_info["mtu"],
         out_info["remote_ia"], out_info["remote_if"], hof)
 def _create_ad_marking(self):
     """
     Create an AD Marking with the given ingress and egress interfaces.
     """
     hof = HopOpaqueField.from_values(1, 111, 222)
     rev_token = HashChain(Random.new().read(32)).next_element()
     pcbm = PCBMarking.from_values(1, 10, hof)
     peer_markings = []
     signing_key = read_file(get_sig_key_file_path(1, 10))
     signing_key = base64.b64decode(signing_key)
     data_to_sign = (b'11' + pcbm.hof.pack())
     signature = sign(data_to_sign, signing_key)
     return ADMarking.from_values(pcbm, peer_markings, rev_token, signature)
Example #10
0
 def handle_one_hop_path(self, hdr, spkt, from_local_as):
     if len(spkt.path) != InfoOpaqueField.LEN + 2 * HopOpaqueField.LEN:
         logging.error("OneHopPathExt: incorrect path length.")
         return [(RouterFlag.ERROR,)]
     if not from_local_as:  # Remote packet, create the 2nd Hop Field
         info = spkt.path.get_iof()
         hf1 = spkt.path.get_hof_ver(ingress=True)
         exp_time = OneHopPathExt.HOF_EXP_TIME
         hf2 = HopOpaqueField.from_values(exp_time, self.interface.if_id, 0)
         hf2.set_mac(self.of_gen_key, info.timestamp, hf1)
         # FIXME(PSz): quite brutal for now:
         spkt.path = SCIONPath.from_values(info, [hf1, hf2])
         spkt.path.inc_hof_idx()
     return []
Example #11
0
 def test_prev(self, cbcmac):
     inst = HopOpaqueField()
     inst.pack = create_mock()
     pack_mac = bytes.fromhex('02 2a 0a0b0c')
     inst.pack.return_value = pack_mac
     prev = create_mock(["mac", "pack"])
     prev.mac = bytes.fromhex('050607')
     prev.pack = create_mock()
     prev_pack_mac = bytes.fromhex('10 11 121314')
     prev.pack.return_value = prev_pack_mac
     ts = 0x01020304
     expected = b"".join([
         pack_mac,
         prev_pack_mac,
         prev.mac,
         ts.to_bytes(4, "big"),
         bytes(inst.MAC_BLOCK_PADDING),
     ])
     # Call
     inst.calc_mac("key", ts, prev)
     # Tests
     prev.pack.assert_called_once_with(mac=True)
     cbcmac.assert_called_once_with("key", expected)
Example #12
0
 def _create_pcbm(self, in_if, out_if, ts, prev_hof, xover=False):
     in_info = self._mk_if_info(in_if)
     if in_info["remote_ia"].int() and not in_info["remote_if"]:
         return None
     out_info = self._mk_if_info(out_if)
     if out_info["remote_ia"].int() and not out_info["remote_if"]:
         return None
     exp_time = self.hof_exp_time(ts)
     if exp_time <= 0:
         logging.error("Invalid hop field expiration time value: %s",
                       exp_time)
         return None
     hof = HopOpaqueField.from_values(exp_time, in_if, out_if, xover=xover)
     hof.set_mac(self.of_gen_key, ts, prev_hof)
     return PCBMarking.from_values(in_info["remote_ia"],
                                   in_info["remote_if"], in_info["mtu"],
                                   out_info["remote_ia"],
                                   out_info["remote_if"], hof)
Example #13
0
 def hof(self):  # pragma: no cover
     return HopOpaqueField(self.p.hof)