예제 #1
0
 def decode_auth_ack_message(
         self, ciphertext: bytes) -> Tuple[datatypes.PublicKey, bytes]:
     if len(ciphertext) < ENCRYPTED_AUTH_ACK_LEN:
         raise BadAckMessage(f"Auth ack msg too short: {len(ciphertext)}")
     elif len(ciphertext) == ENCRYPTED_AUTH_ACK_LEN:
         eph_pubkey, nonce, _ = decode_ack_plain(ciphertext, self.privkey)
     else:
         eph_pubkey, nonce, _ = decode_ack_eip8(ciphertext, self.privkey)
     return eph_pubkey, nonce
예제 #2
0
def decode_ack_plain(
        ciphertext: bytes, privkey: datatypes.PrivateKey
) -> Tuple[datatypes.PublicKey, bytes, int]:
    """Decrypts and decodes a legacy pre-EIP-8 auth ack message.

    Returns the remote's ephemeral pubkey, nonce and protocol version.
    """
    message = ecies.decrypt(ciphertext, privkey)
    if len(message) != AUTH_ACK_LEN:
        raise BadAckMessage(f"Unexpected size for ack message: {len(message)}")
    eph_pubkey = keys.PublicKey(message[:PUBKEY_LEN])
    nonce = message[PUBKEY_LEN:PUBKEY_LEN + HASH_LEN]
    return eph_pubkey, nonce, SUPPORTED_RLPX_VERSION
예제 #3
0
파일: auth.py 프로젝트: qkcww/pyquarkchain
def decode_auth_plain(
    ciphertext: bytes, privkey: datatypes.PrivateKey
) -> Tuple[datatypes.Signature, datatypes.PublicKey, bytes, int]:
    """Decode legacy pre-EIP-8 auth message format"""
    message = ecies.decrypt(ciphertext, privkey)
    if len(message) != AUTH_MSG_LEN:
        raise BadAckMessage(f"Unexpected size for auth message: {len(message)}")
    signature = keys.Signature(signature_bytes=message[:SIGNATURE_LEN])
    pubkey_start = SIGNATURE_LEN + HASH_LEN
    pubkey = keys.PublicKey(message[pubkey_start : pubkey_start + PUBKEY_LEN])
    nonce_start = pubkey_start + PUBKEY_LEN
    nonce = message[nonce_start : nonce_start + HASH_LEN]
    return signature, pubkey, nonce, SUPPORTED_RLPX_VERSION