Skip to content

Commit 540d603

Browse files
joostjagerGeorgeTsagk
authored andcommitted
sphinx: initialize NewOnionErrorEncrypter with shared secret directly
Allow for more flexible usage of the error encrypter. This is useful when upgrading an existing legacy error encrypter to attributable errors in lnd.
1 parent aa5f1c3 commit 540d603

File tree

2 files changed

+8
-28
lines changed

2 files changed

+8
-28
lines changed

obfuscation.go

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,10 @@ type OnionErrorEncrypter struct {
1212
sharedSecret Hash256
1313
}
1414

15-
// NewOnionErrorEncrypter creates new instance of the onion encrypter backed by
16-
// the passed router, with encryption to be done using the passed ephemeralKey.
17-
func NewOnionErrorEncrypter(router *Router, ephemeralKey *btcec.PublicKey,
18-
opts ...ProcessOnionOpt) (*OnionErrorEncrypter, error) {
19-
20-
cfg := &processOnionCfg{}
21-
for _, o := range opts {
22-
o(cfg)
23-
}
24-
25-
sharedSecret, err := router.generateSharedSecret(
26-
ephemeralKey, cfg.blindingPoint,
27-
)
28-
if err != nil {
29-
return nil, err
30-
}
31-
15+
func NewOnionErrorEncrypter(sharedSecret Hash256) *OnionErrorEncrypter {
3216
return &OnionErrorEncrypter{
3317
sharedSecret: sharedSecret,
34-
}, nil
18+
}
3519
}
3620

3721
// Encode writes the encrypter's shared secret to the provided io.Writer.

obfuscation_test.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ func TestOnionFailure(t *testing.T) {
3535
}
3636

3737
// Emulate creation of the obfuscator on node where error have occurred.
38-
obfuscator := &OnionErrorEncrypter{
39-
sharedSecret: sharedSecrets[len(errorPath)-1],
40-
}
38+
obfuscator := NewOnionErrorEncrypter(sharedSecrets[len(errorPath)-1])
4139

4240
// Emulate the situation when last hop creates the onion failure
4341
// message and send it back.
@@ -47,9 +45,7 @@ func TestOnionFailure(t *testing.T) {
4745
for i := len(errorPath) - 2; i >= 0; i-- {
4846
// Emulate creation of the obfuscator on forwarding node which
4947
// propagates the onion failure.
50-
obfuscator = &OnionErrorEncrypter{
51-
sharedSecret: sharedSecrets[i],
52-
}
48+
obfuscator = NewOnionErrorEncrypter(sharedSecrets[i])
5349
obfuscatedData = obfuscator.EncryptError(false, obfuscatedData)
5450
}
5551

@@ -208,16 +204,16 @@ func TestOnionFailureSpecVector(t *testing.T) {
208204
t.Fatalf("unable to decode spec shared secret: %v",
209205
err)
210206
}
211-
obfuscator := &OnionErrorEncrypter{
212-
sharedSecret: sharedSecrets[len(sharedSecrets)-1-i],
213-
}
207+
obfuscator := NewOnionErrorEncrypter(
208+
sharedSecrets[len(sharedSecrets)-1-i],
209+
)
214210

215211
var b bytes.Buffer
216212
if err := obfuscator.Encode(&b); err != nil {
217213
t.Fatalf("unable to encode obfuscator: %v", err)
218214
}
219215

220-
obfuscator2 := &OnionErrorEncrypter{}
216+
obfuscator2 := NewOnionErrorEncrypter(Hash256{})
221217
obfuscatorReader := bytes.NewReader(b.Bytes())
222218
if err := obfuscator2.Decode(obfuscatorReader); err != nil {
223219
t.Fatalf("unable to decode obfuscator: %v", err)

0 commit comments

Comments
 (0)