1
0

lnpeer: obfuscate error pakets of forwarded htlcs, that we

propageate back to the sender.

lnworker: in htlc_fulfilled and htlc_failed, return early if the
htlc was forwarded, so that we do not trigger invoice callbacks
This commit is contained in:
ThomasV
2023-10-19 15:55:28 +02:00
parent 250884489e
commit 4c42840c1c
3 changed files with 20 additions and 13 deletions

View File

@@ -396,7 +396,7 @@ class OnionRoutingFailure(Exception):
def construct_onion_error(
reason: OnionRoutingFailure,
onion_packet: OnionPacket,
their_public_key: bytes,
our_onion_private_key: bytes,
) -> bytes:
# create payload
@@ -409,11 +409,14 @@ def construct_onion_error(
error_packet += pad_len.to_bytes(2, byteorder="big")
error_packet += bytes(pad_len)
# add hmac
shared_secret = get_ecdh(our_onion_private_key, onion_packet.public_key)
shared_secret = get_ecdh(our_onion_private_key, their_public_key)
um_key = get_bolt04_onion_key(b'um', shared_secret)
hmac_ = hmac_oneshot(um_key, msg=error_packet, digest=hashlib.sha256)
error_packet = hmac_ + error_packet
# obfuscate
return error_packet
def obfuscate_onion_error(error_packet, their_public_key, our_onion_private_key):
shared_secret = get_ecdh(our_onion_private_key, their_public_key)
ammag_key = get_bolt04_onion_key(b'ammag', shared_secret)
stream_bytes = generate_cipher_stream(ammag_key, len(error_packet))
error_packet = xor_bytes(error_packet, stream_bytes)