def _close_negotiation(negotiation, contributions): now = get_now() negotiation.text = get_text(contributions) signings_dict = mk_signings(negotiation, contributions) hashable = { "timestamp": now.isoformat(), "negotiation_id": negotiation.id, "text": negotiation.text, "signings": signings_dict, } consensus = utils.hash_string(canonical.to_canonical(hashable)) negotiation.timestamp = now negotiation.consensus = consensus negotiation.status = spec.NegotiationStatus.DONE negotiation.save()
def check_negotiation_wizard(negotiation_id, invitations): invitations = list(invitations) me = cfg.get("PEER_ID") contributions = filter_data_only(client.contribution_list(negotiation_id)) contributions = [c for c in contributions if c["latest"]] signers = [me] orig_body = None orig_next_negotiation_id = read_next_negotiation_id() for contribution in contributions: signer = contribution["signer_key_id"] text = get_contribution_text(contribution) body = text["body"] if orig_body is None: orig_body = body if orig_body != body: raise ValueError("contribution texts differ") meta = text["meta"] invitation_id = meta.get("invitation_id") if invitation_id is not None: check_invitation(invitations, invitation_id) client.peer_import(signer) signers.append(signer) # print "Imported peer %s" % signer elif signer != me: raise ValueError("uninvited contribution!") next_negotiation_id = meta.get("next_negotiation_id") if next_negotiation_id != orig_next_negotiation_id: raise ValueError("wrong next_negotiation_id") if invitations: raise Block("Invitations pending: %s" % invitations) ui.inform("All invited peers have joined. Sending accept contribution.") name = orig_body["data"]["name"] next_negotiation_id = orig_body["info"].get("next_negotiation_id") hashed_next_negotiation_id = utils.hash_string(orig_next_negotiation_id) is_contrib, d = client.peer_create( name, set_key=True, owners=signers, negotiation_id=negotiation_id, accept=True, next_negotiation_id=hashed_next_negotiation_id) assert is_contrib contrib_id = d["data"]["id"] ui.inform("Your new contribution id is: %s" % contrib_id) return contrib_id
def verify(request, signature, public, working_gpg, gpg_path): req_filepath = write_to_file(request, "r") sig_filepath = write_to_file(signature, "s") if public: gpg_homename = "gpg_" + utils.hash_string(signature)[0:10] gpg_homepath = os.path.join("/tmp", gpg_homename) tmp_gpg = gnupg.GPG(homedir=gpg_homepath, binary=gpg_path) tmp_gpg.import_keys(public) verif_gpg = tmp_gpg else: verif_gpg = working_gpg with open(req_filepath) as req_file: v = verif_gpg.verify_file(req_file, sig_filepath) os.remove(req_filepath) os.remove(sig_filepath) shutil.rmtree(gpg_homepath) return v.valid, v.key_id
def write_to_file(s, prefix): filename = prefix + utils.hash_string(s) filepath = os.path.join("/tmp", filename) with open(filepath, "w") as f: f.write(s) return filepath
def get_key_id_from_key_data(key_data): return unicode(utils.hash_string(key_data))
def check_hashed_next_negotiation_id(meta): next_negotiation_id = read_next_negotiation_id() hashed_next_negotiation_id = meta.get("next_negotiation_id") if hashed_next_negotiation_id != utils.hash_string(next_negotiation_id): raise ValueError("wrong next_negotiation_id hash")
def hash_meta_next_negotiation(meta): next_negotiation_id = meta["next_negotiation_id"] meta["next_negotiation_id"] = utils.hash_string(next_negotiation_id) return meta