예제 #1
0
 def __str__(self):
     return (
         "%s(%sB): class: %s type: %s "
         "length: %sB checksum: %s timestamp: %s" %
         (self.NAME, self.LEN, SCMPClass.to_str(self.class_),
          scmp_type_name(self.class_, self.type), self.total_len,
          hex_str(self._checksum), iso_timestamp(self.timestamp / 1000000)))
예제 #2
0
파일: pcb.py 프로젝트: fjacky/scion
 def short_desc(self):  # pragma: no cover
     """
     Return a short description string of the PathSegment, consisting of a
     truncated hash, the IOF timestamp, and the list of hops.
     """
     desc = []
     desc.append("%s, %s, " %
                 (self.short_id(), iso_timestamp(self.get_timestamp())))
     hops = []
     for asm in self.iter_asms():
         hop = []
         hof = asm.pcbm(0).hof()
         if hof.ingress_if:
             hop.append("%d " % hof.ingress_if)
         hop.append("%s" % asm.isd_as())
         if hof.egress_if:
             hop.append(" %d" % hof.egress_if)
         hops.append("".join(hop))
     exts = []
     if self.is_sibra():
         exts.append("  %s" % self.sibra_ext.short_desc())
     desc.append(">".join(hops))
     if exts:
         return "%s\n%s" % ("".join(desc), "\n".join(exts))
     return "".join(desc)
예제 #3
0
 def short_desc(self):
     desc = []
     remain = self.p.expTime - self.p.timestamp
     desc.append(
         "%s, %s, " %
         (iso_timestamp(self.p.timestamp), timedelta(seconds=remain)))
     desc.append(", ".join([if_.short_desc() for if_ in self.iter_ifs()]))
     return "".join(desc)
예제 #4
0
 def __str__(self):
     tmp = []
     tmp.append("%s(%dB): Resv idx: %2s Fwd: %s Rev: %s" %
                (self.NAME, len(self), self.index, self.bw.fwd_str(),
                 self.bw.rev_str()))
     tmp.append("Failhop: %s Dir fwd: %s Expiry: %s" %
                (self.fail_hop, self.fwd_dir,
                 iso_timestamp(tick_to_time(self.exp_tick))))
     return "\n  ".join(tmp)
예제 #5
0
def p_segment(s, seg, idx, name, color, rev):
    '''
    Add segment to html list
    '''
    list_add_head(s, idx, name, color)
    indent_open(s)
    list_add(s, "Creation: %s" % iso_timestamp(seg.p.timestamp))
    list_add(s, "Expiration: %s" % iso_timestamp(seg.p.expTime))
    list_add(s, "Hops: %i" % (len(seg.p.interfaces) / 2))
    # enumerate path interfaces
    if rev:
        interfaces = reversed(seg.p.interfaces)
    else:
        interfaces = seg.p.interfaces
    for interface in interfaces:
        isd_as = ISD_AS(interface.isdas)
        link = interface.ifID
        list_add(s, "%s (%s)" % (str(isd_as), link))
    indent_close(s)
예제 #6
0
파일: pcb.py 프로젝트: MrShiyu/scion
 def short_desc(self):  # pragma: no cover
     """
     Return a short description string of the PathSegment, consisting of a
     truncated hash, the IOF timestamp, and the list of hops.
     """
     desc = []
     desc.append("%s, %s, " % (
         self.get_hops_hash(hex=True)[:12],
         iso_timestamp(self.get_timestamp()),
     ))
     hops = []
     for asm in self.iter_asms():
         hops.append(str(asm.isd_as()))
     exts = []
     if self.is_sibra():
         exts.append("  %s" % self.sibra_ext.short_desc())
     desc.append(" > ".join(hops))
     if exts:
         return "%s\n%s" % ("".join(desc), "\n".join(exts))
     return "".join(desc)
예제 #7
0
def print_enum_segments(segs, type, rev=False):
    '''
    Generic method to print array of segments
    :param segs: Array of segments.
    :param type: Segment type label.
    '''
    segidx = 1
    for seg in segs:
        desc = []
        remain = seg.p.expTime - seg.p.timestamp
        desc.append(
            "%s, %s" %
            (iso_timestamp(seg.p.timestamp), timedelta(seconds=remain)))
        if rev:
            ifs = list(reversed(seg.p.interfaces))
        else:
            ifs = seg.p.interfaces
        for if_ in ifs:
            desc.append(", %s:%s" % (ISD_AS(if_.isdas), if_.ifID))
        logging.info("%s %s\t%s" % (type, segidx, "".join(desc)))
        segidx += 1
예제 #8
0
    def verify(self, subject, trc):
        """
        Perform the entire chain verification. First verifies the AS certificate against the core AS
        certificate, then verifies the core AS certificate against the TRC.

        :param str subject:
            the subject of the first certificate in the certificate chain.
        :param trc: TRC containing all root of trust certificates for one ISD.
        :type trc: :class:`TRC`
        :raises: SCIONVerificationError if the verification fails.
        """
        # Verify AS certificate against core AS certificate
        leaf = self.as_cert
        core = self.core_as_cert
        if leaf.issuing_time < core.issuing_time:
            raise SCIONVerificationError(
                "AS certificate verification failed: Leaf issued before core certificate. Leaf: %s "
                "Core: %s" % (iso_timestamp(
                    leaf.issuing_time), iso_timestamp(core.issuing_time)))
        if leaf.expiration_time > core.expiration_time:
            raise SCIONVerificationError(
                "AS certificate verification failed: Leaf expires after core certificate. Leaf: %s "
                "Core: %s" % (iso_timestamp(leaf.expiration_time),
                              iso_timestamp(core.expiration_time)))
        if not core.can_issue:
            raise SCIONVerificationError(
                "AS certificate verification failed: Core certificate cannot issue certificates"
            )
        try:
            leaf.verify(subject, core.subject_sig_key_raw)
        except SCIONVerificationError as e:
            raise SCIONVerificationError(
                "AS certificate verification failed: %s" % e)
        # Verify core AS certificate against TRC
        if core.expiration_time > trc.exp_time:
            raise SCIONVerificationError(
                "Core AS certificate verification failed: Core certificate expires after TRC. "
                "Core: %s TRC: %s" % (iso_timestamp(
                    core.expiration_time), iso_timestamp(trc.exp_time)))
        try:
            core.verify(leaf.issuer,
                        trc.core_ases[core.issuer][ONLINE_KEY_STRING])
        except SCIONVerificationError as e:
            raise SCIONVerificationError(
                "Core AS certificate verification failed: %s" % e)
예제 #9
0
def prep_con_req_dict(con_req, isd_id, as_id):
    """
    Prepares the connection request as a dictionary to be sent to the SCION
    coordination service.
    :param ConnectionRequest con_req: Connection request object.
    :returns: Connection request as a dictionary.
    :rtype: dict
    """
    isd_as = TopoID.from_values(isd_id, as_id)
    as_obj = get_object_or_404(AD, isd_id=isd_id, as_id=as_id)
    cert_chain = CertificateChain.from_raw(as_obj.certificate)
    con_req_dict = {
        "RequestId": con_req.id,
        "Info": con_req.info,
        "RequestIA": str(isd_as),
        "RespondIA": con_req.connect_to,
        "IP": con_req.router_public_ip,
        "OverlayType": con_req.overlay_type,
        "MTU": int(con_req.mtu),
        "Bandwidth": int(con_req.bandwidth),
        "Timestamp": iso_timestamp(time.time()),
        "Signature": "",  # TODO(ercanucan): generate and set the signature
        "Certificate": cert_chain.to_json()
    }
    if con_req.router_public_port:
        con_req_dict["Port"] = int(con_req.router_public_port)
    # Adjust the link type for the receiving party (i.e if the requestIA
    # wants to have the respondIA as a PARENT, then the respondIA should
    # see it as a request to have a CHILD AS.
    if con_req.link_type == LinkType.PARENT:
        con_req_dict["LinkType"] = LinkType.CHILD
    elif con_req.link_type == LinkType.CHILD:
        con_req_dict["LinkType"] = LinkType.PARENT
    else:
        con_req_dict["LinkType"] = con_req.link_type
    return con_req_dict
예제 #10
0
 def __str__(self):
     return "%s: type: %s src: %s ts: %s" % (
         self.NAME, self.p.type, self.p.src, iso_timestamp(
             self.p.timestamp))
예제 #11
0
 def __str__(self):
     flags = self._pack_flags()
     return ("%s(%sB): flags: %s, TS: %s, ISD: %s, hops: %s" %
             (self.NAME, self.LEN, InfoOFFlags.to_str(flags),
              iso_timestamp(self.timestamp), self.isd, self.hops))
예제 #12
0
 def short_desc(self):
     return "RevInfo: %s IF: %s Link type: %s Timestamp: %s TTL: %ss" % (
         self.isd_as(), self.p.ifID, LinkType.to_str(self.p.linkType),
         iso_timestamp(self.p.timestamp), self.p.ttl)