mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
client: reject malformed server public keys
Loop-in and loop-out responses carry compressed server public keys that are copied into fixed-size fields and later used for HTLC construction. Validate the length and parse each compressed key before storing it, and validate the MuSig2 loop-in receiver internal key as well. This turns short or unparsable server keys into explicit errors instead of silently zero-padding short responses or accepting an invalid internal key. Update root test mocks to return size-correct MuSig2 signing data under the stricter checks.
This commit is contained in:
parent
605e72a261
commit
cc0392af3f
4 changed files with 80 additions and 16 deletions
28
swap_server_client_test.go
Normal file
28
swap_server_client_test.go
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package loop
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
looptest "github.com/lightninglabs/loop/test"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// TestParseServerPubKey ensures that parseServerPubKey accepts a valid
|
||||
// compressed public key and rejects keys with an invalid length or contents.
|
||||
func TestParseServerPubKey(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, pubKey := looptest.CreateKey(1)
|
||||
pubKeyBytes := pubKey.SerializeCompressed()
|
||||
|
||||
parsedKey, err := parseServerPubKey("test key", pubKeyBytes)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, pubKeyBytes, parsedKey[:])
|
||||
|
||||
_, err = parseServerPubKey("test key", pubKeyBytes[:32])
|
||||
require.ErrorContains(t, err, "invalid test key length")
|
||||
|
||||
invalidKey := make([]byte, 33)
|
||||
_, err = parseServerPubKey("test key", invalidKey)
|
||||
require.ErrorContains(t, err, "invalid test key")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue