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
`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.
36 lines
630 B
Go
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))
|
|
}
|