Files
brianmcgee c7840edca5
buildbot/nix-eval Build done.
PR Size Review Check / pr-size-review-gate (pull_request) Successful in 56s
sizelint / sizelint (pull_request) Successful in 1m13s
buildbot/nix-build Build done.
gitea-mq/buildbot/nix-eval Build done.
gitea-mq/buildbot/nix-build Build done.
gitea-mq Merge queue passed
crypto,config: guard against nil PublicKey in decoded signatures
`PublicKey.String()`, `URLEncoded()`, `Bytes()`, and `Equal()` all panic when called on a `nil` receiver. A peer can exploit this by sending a Manifest with a missing `network_id` or `signed_by`, causing a nil-pointer panic in the stream-handler goroutine that crashes the daemon.

Add nil-receiver guards to `PublicKey` methods and an early nil-check
in `SignatureAuth.Authorize()` so malformed signatures are rejected
with an error rather than crashing the process.
2026-04-08 12:10:37 +01:00

36 lines
630 B
Go

package crypto_test
import (
"testing"
"git.clan.lol/clan/data-mesher/pkg/crypto"
"git.clan.lol/clan/data-mesher/test"
"github.com/stretchr/testify/require"
)
func TestPublicKey_NilReceiver(t *testing.T) {
t.Parallel()
as := require.New(t)
var nilKey *crypto.PublicKey
as.Empty(nilKey.String())
as.Empty(nilKey.URLEncoded())
as.Nil(nilKey.Bytes())
}
func TestPublicKey_Equal_NilReceiver(t *testing.T) {
t.Parallel()
as := require.New(t)
keys := test.GenerateKeys(t, 1)
var nilKey *crypto.PublicKey
as.True(nilKey.Equal(nil))
as.False(nilKey.Equal(keys[0].Public))
as.False(keys[0].Public.Equal(nil))
}