Exemplo n.º 1
0
    def add_edge(self, paren_node, child_node):
        """
        Given a the name of a parent and child node, a new edge will be created
        between them.
        Args:
            paren_node (string): name identifying parent node
            child_node (string): name identifying child node
        Returns:
            N/A
        """
        if (paren_node == child_node):
            return False

        paren = self.node_list[paren_node]
        child = self.node_list[child_node]

        if child_node in paren.edges:
            return False

        paren_obj = Roles.objects.get(role=paren_node)
        child_obj = Roles.objects.get(role=child_node)
        r_ij = hash_fun(paren.get_t_i(), child.l_i)
        y_ij = encrypt(r_ij, child.get_t_i(), child.get_k_i())
        new_edge = Edge(r_ij, y_ij)
        self.node_list[paren_node].edges[child_node] = new_edge

        if not self.is_cyclic():
            RoleEdges(parent_role=paren_obj,
                      child_role=child_obj,
                      edge_secret=r_ij,
                      edge_key=y_ij).save()
        else:
            self.node_list[paren_node].edges.pop(child_node)
            return False
Exemplo n.º 2
0
 def derive_desc_key_helper(self, src_node, t_i):
     key_list = []
     for children in self.node_list[src_node].edges.keys():
         t_j, k_j = decrypt(hash_fun(t_i, self.node_list[children].l_i),
                            self.node_list[src_node].edges[children].y_ij)
         key_list.append(k_j)
         key_list += self.derive_desc_key(children, t_j)
     return key_list
Exemplo n.º 3
0
 def get_k_i(self):
     """
     Return the value of the decrypt key (k_i).
     Args:
         N/A
     Returns:
         hex digest (string): hash of s_i + "1" + l_i
     """
     return hash_fun(self.__s_i, self.l_i, val_opt="1")
Exemplo n.º 4
0
 def get_t_i(self):
     """
     Return the value of the derive key (t_i).
     Args:
         N/A
     Returns:
         hex digest (string): hash of s_i + "0" + l_i
     """
     return hash_fun(self.__s_i, self.l_i, val_opt="0")
Exemplo n.º 5
0
 def update_r_ij(self, t_i, l_j):
     """
     Update the value of the private information (r_ij).
     Args:
         t_i (string): hex string of parent derive key
         l_j (string): hex string of child label
     Returns:
         N/A
     """
     self.__r_ij = hash_fun(t_i, l_j)
Exemplo n.º 6
0
 def derive_key(self, path):
     """
     Derive the key of the destination node given the path to it
     Args:
         path (list of string): list of names of node in the path
     Returns:
         key of the node in hex string
     """
     src_node = path[0]
     t_j = self.node_list[src_node].get_t_i()
     k_j = self.node_list[src_node].get_k_i()
     for i in range(1, len(path)):
         child = path[i]
         t_j, k_j = decrypt(hash_fun(t_j, self.node_list[child].l_i),
                            self.node_list[src_node].edges[child].y_ij)
         src_node = child
     return k_j