Exemplo n.º 1
0
def get_messages(partner):

    # Check for new info
    check_db()
    all_messages = get_mail_db(current_user.name, partner)

    message_js = []

    groupnames = names_n_group(current_user.name)[1]
    members = []
    partner_id = ""
    if partner in groupnames:
        members = get_members(partner)

    partner_id = get_id(partner)

    for mess in all_messages:

        direction = "sent" if mess.sender == current_user.name else "replies"

        sender_id = get_id(mess.sender, string=True)
        message = {"sender": sender_id,
                   "recipient": mess.recipient,
                   "content": mess.content,
                   "time": mess.time.time().strftime("%H:%M:%S"),
                   "direction": direction,
                   "imgURL": url_for('tree_bp.static',
                                     filename='/imag/' + mess.sender + '.png')}
        message_js += [message]

    return {'messages': message_js, 'members': members, 'id': partner_id}
Exemplo n.º 2
0
def remove_member():
    # It is important to be up to date before removing a member
    # in order to be sure we get the correct keys
    check_db()

    data = request.json

    # Intels for the already existing members, so that they
    # get the tree into the server, and adapt theirs
    groupname = data['groupname']
    members = get_members(groupname)
    headers = {'x-access-tokens': get_token(current_user.name)}

    group = get_group(groupname)

    for member in members:
        dico = {'groupname': groupname, 'member': data['member']}

        intel = {
            'sender': current_user.name,
            'content': json.dumps(dico),
            'recipient': member,
            'type': 'remove_member',
            'groupname': groupname
        }

        requests.post(server_address + "/intels/" + member,
                      json=intel,
                      headers=headers)

    members = get_members(groupname)
    if data['member'] in members:
        members.remove(data['member'])
        group.members = ','.join(members)
        db.session.commit()

    return "User removed !", 200
Exemplo n.º 3
0
def settings(partner):
    members_id, not_members_id = {}, {}
    names, groupnames = names_n_group(current_user.name)
    check_db()
    if partner in groupnames:
        members = get_members(partner)
        not_members = [name for name in names if name not in members]
        for not_member in not_members:
            not_members_id[not_member] = get_id(not_member, string=True)
        for member in members:
            members_id[member] = get_id(member, string=True)
    return render_template('settings.html',
                           partner=partner,
                           notmembersid=not_members_id,
                           members=members,
                           notmembers=not_members,
                           membersid=members_id)
Exemplo n.º 4
0
def update_key():
    data = request.json
    print('data = ', data)
    groupname = data["groupname"]
    if groupname not in names_n_group(current_user.name)[1]:
        return "Rien à faire ici", 200

    # Updating of the tree
    tree = read_tree(groupname)
    update_stage_key(tree, data['groupname'])

    usernode = get_node(tree, data['user'])
    usernode.update_secret_key(data['secretK'])

    path = usernode.path
    fill_nodes(tree, path)

    write_tree(groupname, tree)

    members = get_members(groupname)
    # We don't send to the member who modified, since
    # they already did it the modifications for themself
    members.remove(current_user.name)
    dico = get_pk_path(tree, usernode)
    headers = {'x-access-tokens': get_token(current_user.name)}
    for member in members:
        intel = {
            'sender': current_user.name,
            'content': repr(dico),
            'recipient': member,
            'type': 'update_key',
            'groupname': groupname
        }
        requests.post(server_address + "/intels/" + member,
                      json=intel,
                      headers=headers)

    print('\nSuccess : key updated')
    return "Tout de bon", 200
Exemplo n.º 5
0
def add_member():
    check_db()

    data = request.json
    groupname, new_member = data['groupname'], data['newmember']

    # Get the tree, add a node and get the node
    tree = read_tree(groupname)
    add_node(tree, new_member)
    newnode = get_node(tree, new_member)

    # We take a random OTK private key, with the corresponding index
    private_otk = get_otk(current_user.name)
    ind_private_otk = private_otk.serverID

    # Creation of the shared key (leaf key) and we put it in the leaf attribute
    headers = {'x-access-tokens': get_token(current_user.name)}
    public_otk = requests.get(server_address + "/getOTK/" + new_member + "/" +
                              str(-1),
                              headers=headers).json()
    otkeys = {
        'privateOTK': str(ind_private_otk),
        'publicOTK': public_otk['publOTK']
    }
    compute_leaf_keys(newnode, current_user.name, newnode.value, otkeys,
                      'initiator')

    # Update the key pairs
    fill_nodes(tree, newnode.path)

    members = get_members(groupname)
    pks = get_pk_path(tree, newnode)
    publicKeys = get_all_pk(tree)

    dico = {'groupname': groupname, 'publicKeys': pks, 'newmember': new_member}

    # Intels for the already existing members
    headers = {'x-access-tokens': get_token(current_user.name)}
    for member in members:
        intel = {
            'sender': current_user.name,
            'content': repr(dico),
            'recipient': member,
            'type': data['type'],
            'groupname': groupname
        }
        requests.post(server_address + "/intels/" + member,
                      json=intel,
                      headers=headers)

    # We make a copy not to erase our tree
    central_tree = deepcopy(tree)
    clear_leaves(central_tree, get_all_value(central_tree))

    # Intel for the new member only,
    # so that they create its tree
    dico = {
        'info_otk': {
            'creatorOTK': SIKE_compute_pk(private_otk.privateOTK, 'initiator'),
            'partnerOTK': public_otk['indexOTK']
        },
        'groupname': groupname,
        'members': ','.join(get_value_leaves(tree)),
        'publicKeys': repr(publicKeys)
    }
    intel = {
        'sender': current_user.name,
        'content': repr(dico),
        'recipient': new_member,
        'type': 'creation',
        'groupname': groupname
    }

    headers = {'x-access-tokens': get_token(current_user.name)}
    requests.post(server_address + "/intels/" + new_member,
                  json=intel,
                  headers=headers)

    # Add the new member to the list of members
    group = get_group(groupname)
    group.members = group.members + "," + new_member
    db.session.commit()

    return "Done", 200