Ejemplo n.º 1
0
async def id_pubkey_correspondence(id_pubkey):
    client = ClientInstance().client
    # determine if id_pubkey is a pubkey
    checked_pubkey = is_pubkey_and_check(id_pubkey)
    if checked_pubkey:
        id_pubkey = checked_pubkey
        try:
            idty = await identity_of(id_pubkey)
            print(
                "{} public key corresponds to identity: {}".format(
                    display_pubkey_and_checksum(id_pubkey), idty["uid"]
                )
            )
        except:
            message_exit("No matching identity")
    # if not ; then it is a uid
    else:
        pubkeys = await wot_lookup(id_pubkey)
        print("Public keys found matching '{}':\n".format(id_pubkey))
        for pubkey in pubkeys:
            print("→", display_pubkey_and_checksum(pubkey["pubkey"]), end=" ")
            try:
                corresponding_id = await client(wot.identity_of, pubkey["pubkey"])
                print("↔ " + corresponding_id["uid"])
            except:
                print("")
    await client.close()
Ejemplo n.º 2
0
async def received_sent_certifications(uid_pubkey):
    """
    get searched id
    get id of received and sent certifications
    display in a table the result with the numbers
    """
    client = ClientInstance().client
    first_block = await client(blockchain.block, 1)
    time_first_block = first_block["time"]

    checked_pubkey = is_pubkey_and_check(uid_pubkey)
    if checked_pubkey:
        uid_pubkey = checked_pubkey

    identity, pubkey, signed = await choose_identity(uid_pubkey)
    certifications = OrderedDict()
    params = await BlockchainParams().params
    req = await client(wot.requirements, pubkey)
    req = req["identities"][0]
    certifications["received_expire"] = list()
    certifications["received"] = list()
    for cert in identity["others"]:
        certifications["received_expire"].append(
            expiration_date_from_block_id(
                cert["meta"]["block_number"], time_first_block, params
            )
        )
        certifications["received"].append(
            cert_written_in_the_blockchain(req["certifications"], cert)
        )
        (
            certifications["sent"],
            certifications["sent_expire"],
        ) = get_sent_certifications(signed, time_first_block, params)
    nbr_sent_certs = len(certifications["sent"]) if "sent" in certifications else 0
    print(
        "{0} ({1}) from block #{2}\nreceived {3} and sent {4}/{5} certifications:\n{6}\n{7}\n".format(
            identity["uid"],
            display_pubkey_and_checksum(pubkey, True),
            identity["meta"]["timestamp"][:15] + "…",
            len(certifications["received"]),
            nbr_sent_certs,
            params["sigStock"],
            tabulate(
                certifications,
                headers="keys",
                tablefmt="orgtbl",
                stralign="center",
            ),
            "✔: Certifications written into the blockchain",
        )
    )
    await membership_status(certifications, pubkey, req)
    await client.close()
Ejemplo n.º 3
0
def test_is_pubkey_and_check(uid_pubkey, expected):
    assert expected == crypto_tools.is_pubkey_and_check(uid_pubkey)
Ejemplo n.º 4
0
def test_is_pubkey_and_check_errors(uid_pubkey, expected, capsys):
    with pytest.raises(SystemExit) as pytest_exit:
        test = crypto_tools.is_pubkey_and_check(uid_pubkey)
        assert capsys.readouterr() == expected
    assert pytest_exit.type == SystemExit
Ejemplo n.º 5
0
async def send_certification(uid_pubkey_to_certify):
    client = ClientInstance().client

    checked_pubkey = is_pubkey_and_check(uid_pubkey_to_certify)
    if checked_pubkey:
        uid_pubkey_to_certify = checked_pubkey

    idty_to_certify, pubkey_to_certify, send_certs = await wot.choose_identity(
        uid_pubkey_to_certify)

    # Authentication
    key = auth_method()

    # Check whether current user is member
    issuer_pubkey = key.pubkey
    issuer = await wot.is_member(issuer_pubkey)
    if not issuer:
        message_exit("Current identity is not member.")

    if issuer_pubkey == pubkey_to_certify:
        message_exit("You can’t certify yourself!")

    # Check if the certification can be renewed
    req = await client(bma.wot.requirements, pubkey_to_certify)
    req = req["identities"][0]
    for cert in req["certifications"]:
        if cert["from"] == issuer_pubkey:
            params = await BlockchainParams().params
            # Ğ1: 0<–>2y - 2y + 2m
            # ĞT: 0<–>4.8m - 4.8m + 12.5d
            renewable = cert["expiresIn"] - params["sigValidity"] + params[
                "sigReplay"]
            if renewable > 0:
                renewable_date = convert_time(time() + renewable, "date")
                message_exit("Certification renewable the " + renewable_date)

    # Check if the certification is already in the pending certifications
    for pending_cert in req["pendingCerts"]:
        if pending_cert["from"] == issuer_pubkey:
            message_exit("Certification is currently been processed")

    # Display license and ask for confirmation
    head = await HeadBlock().head_block
    currency = head["currency"]
    license_approval(currency)

    # Certification confirmation
    await certification_confirmation(issuer, issuer_pubkey, pubkey_to_certify,
                                     idty_to_certify)

    identity = Identity(
        version=10,
        currency=currency,
        pubkey=pubkey_to_certify,
        uid=idty_to_certify["uid"],
        ts=block_uid(idty_to_certify["meta"]["timestamp"]),
        signature=idty_to_certify["self"],
    )

    certification = Certification(
        version=10,
        currency=currency,
        pubkey_from=issuer_pubkey,
        identity=identity,
        timestamp=BlockUID(head["number"], head["hash"]),
        signature="",
    )

    # Sign document
    certification.sign([key])

    # Send certification document
    response = await client(bma.wot.certify, certification.signed_raw())

    if response.status == 200:
        print("Certification successfully sent.")
    else:
        print("Error while publishing certification: {0}".format(
            await response.text()))

    await client.close()