From c67ca0a3292d391834cb66d8b0d3c679958e9202 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 30 Apr 2019 18:22:10 -0700 Subject: [PATCH] htlcswitch: add new EncryptMalformedError method to ErrorEncrypter In this commit, we add a new method to the ErrorEncrypter interface: `EncryptMalformedError`. This takes a raw error (no encryption or MAC), and encrypts it as if we were the originator of this error. This will be used by the switch to convert malformed fail errors to regular fully encrypted errors. --- htlcswitch/failure.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/htlcswitch/failure.go b/htlcswitch/failure.go index d9edb1459..a17517bb7 100644 --- a/htlcswitch/failure.go +++ b/htlcswitch/failure.go @@ -87,6 +87,13 @@ type ErrorEncrypter interface { // slightly, in that it computes a proper MAC over the error. EncryptFirstHop(lnwire.FailureMessage) (lnwire.OpaqueReason, error) + // EncryptMalformedError is similar to EncryptFirstHop (it adds the + // MAC), but it accepts an opaque failure reason rather than a failure + // message. This method is used when we receive an + // UpdateFailMalformedHTLC from the remote peer and then need to + // convert that into a proper error from only the raw bytes. + EncryptMalformedError(lnwire.OpaqueReason) lnwire.OpaqueReason + // IntermediateEncrypt wraps an already encrypted opaque reason error // in an additional layer of onion encryption. This process repeats // until the error arrives at the source of the payment. @@ -153,6 +160,17 @@ func (s *SphinxErrorEncrypter) EncryptFirstHop(failure lnwire.FailureMessage) (l return s.EncryptError(true, b.Bytes()), nil } +// EncryptMalformedError is similar to EncryptFirstHop (it adds the MAC), but +// it accepts an opaque failure reason rather than a failure message. This +// method is used when we receive an UpdateFailMalformedHTLC from the remote +// peer and then need to convert that into an proper error from only the raw +// bytes. +// +// NOTE: Part of the ErrorEncrypter interface. +func (s *SphinxErrorEncrypter) EncryptMalformedError(reason lnwire.OpaqueReason) lnwire.OpaqueReason { + return s.EncryptError(true, reason) +} + // IntermediateEncrypt wraps an already encrypted opaque reason error in an // additional layer of onion encryption. This process repeats until the error // arrives at the source of the payment. We re-encrypt the message on the