Пример #1
0
def prep_approved_join_reply(request, join_rep_dict, own_isdas, own_as_obj):
    """
    Prepares the join reply for the APPROVED case.
    """
    logger.info("New AS ID = %s", request.POST['newASId'])
    joining_as = request.POST['newASId']
    is_core = request.POST['join_as_a_core']
    sig_pub_key = from_b64(request.POST['sig_pub_key'])
    enc_pub_key = from_b64(request.POST['enc_pub_key'])
    signing_as_sig_priv_key = from_b64(own_as_obj.sig_priv_key)
    joining_ia = TopoID.from_values(own_isdas[0], joining_as)
    if is_core.lower() == "true":
        validity = Certificate.CORE_AS_VALIDITY_PERIOD
        comment = "Core AS Certificate"
    else:
        validity = Certificate.AS_VALIDITY_PERIOD
        comment = "AS Certificate"
    cert = Certificate.from_values(
        str(joining_ia), str(own_isdas), INITIAL_TRC_VERSION, INITIAL_CERT_VERSION, comment,
        is_core, validity, enc_pub_key, sig_pub_key, SigningKey(signing_as_sig_priv_key)
    )
    respond_ia_chain = CertificateChain.from_raw(own_as_obj.certificate)
    request_ia_chain = CertificateChain([cert, respond_ia_chain.core_as_cert])
    join_rep_dict['JoiningIA'] = str(joining_ia)
    join_rep_dict['IsCore'] = is_core.lower() == "true"
    join_rep_dict['RespondIA'] = str(own_isdas)
    join_rep_dict['JoiningIACertificate'] = request_ia_chain.to_json()
    join_rep_dict['RespondIACertificate'] = respond_ia_chain.to_json()
    join_rep_dict['TRC'] = TRC.from_raw(own_as_obj.trc).to_json()
    logger.debug("Accepting Join Request = %s", join_rep_dict)
Пример #2
0
def save_all_topologies(request):
    """
    Generate topology files for all ASes or specific ASes in a ISD.
    :param HttpRequest request: Django HTTP request passed on through urls.py
    :returns: Django HTTP Response object.
    :rtype: HttpResponse.
    """
    current_page = request.META.get('HTTP_REFERER')
    topology_params = request.POST.copy()
    isd_list = topology_params.getlist('ISD')
    for isd in isd_list:
        for ad_obj in AD.objects.filter(isd_id=isd):
            isd_as = TopoID.from_values(ad_obj.isd_id, ad_obj.as_id)
            topo_dict = ad_obj.original_topology
            # TODO: in the DB there is at least one entry (ffaa:0:1306) with {}
            if len(topo_dict) == 0:
                continue
            # write the topology file
            create_local_gen(isd_as, topo_dict)
            addr_list = []
            cloud_engine_list = []
            host_name_list = []
            for cloud in CloudMachine.objects.filter(ad_id=ad_obj):
                addr_list.append(cloud.addr)
                cloud_engine_list.append(cloud.cloud_provider)
                host_name_list.append(cloud.host_name)
            topology_params.setlist('inputCloudAddress', addr_list)
            topology_params.setlist('inputCloudEngine', cloud_engine_list)
            topology_params.setlist('inputHostname', host_name_list)
            commit_hash = ad_obj.commit_hash
            # sanitize commit hash from comments, take first part up to |, strip spaces
            commit_hash = (commit_hash.split('|'))[0].strip()
            generate_ansible_hostfile(topology_params,
                                      topo_dict,
                                      isd_as,
                                      commit_hash)
    return redirect(current_page)
Пример #3
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
Пример #4
0
 def _self_sign_keys(self):
     topo_id = TopoID.from_values(0, 0)
     self.sig_pub_keys[topo_id], self.sig_priv_keys[topo_id] = generate_sign_keypair()
     self.enc_pub_keys[topo_id], self.enc_priv_keys[topo_id] = generate_enc_keypair()