Ejemplo n.º 1
0
def generate_dispatcher_input(
    my_bls_public_key: str,
    my_bls_public_key_shares: List[str],
    my_bls_private_key_shares: List[int],
    my_rsa_key: RsaKey,
    all_rsa_public_keys: List[str],
) -> Tuple[List[Dict[str, Any]], int]:
    """
    Generate dispatcher input data.
    """
    input_data = []
    my_rsa_public_key_ssh = my_rsa_key.publickey().export_key(
        "OpenSSH").decode("ascii")
    my_index = -1
    for i in range(len(all_rsa_public_keys)):
        recipient_rsa_public_key = RSA.import_key(all_rsa_public_keys[i])
        recipient_bls_private_key_share = my_bls_private_key_shares[i]

        if recipient_rsa_public_key == my_rsa_key.publickey():
            my_index = i
            continue

        encrypted_data = {
            "public_key": my_bls_public_key,
            "public_key_shares": my_bls_public_key_shares,
            "private_key_share": str(recipient_bls_private_key_share),
        }
        enc_session_key, nonce, tag, ciphertext = rsa_encrypt(
            recipient_public_key=recipient_rsa_public_key,
            data=json.dumps(encrypted_data),
        )
        signature = rsa_sign(my_rsa_key, ciphertext)

        input_data.append({
            "sender_rsa_public_key":
            my_rsa_public_key_ssh,
            "recipient_rsa_public_key":
            recipient_rsa_public_key.export_key("OpenSSH").decode("ascii"),
            "enc_session_key":
            enc_session_key.hex(),
            "ciphertext":
            ciphertext.hex(),
            "nonce":
            nonce.hex(),
            "tag":
            tag.hex(),
            "signature":
            signature.hex(),
        })

    return input_data, my_index
Ejemplo n.º 2
0
 def _save_keypair(self, key: RSA.RsaKey) -> None:
     self._priv = key.exportKey("PEM")
     self._pub = key.publickey().exportKey("DER")
Ejemplo n.º 3
0
 def get_public_key(keys: RsaKey) -> str:
     public_key = keys.publickey().exportKey()
     return public_key.decode()